100 lines
3.0 KiB
PHP
100 lines
3.0 KiB
PHP
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | ShopXO 国内领先企业级B2C免费开源电商系统
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Devil
|
|
// +----------------------------------------------------------------------
|
|
namespace app\plugins\wallet\service;
|
|
|
|
use think\Db;
|
|
use app\service\PluginsService;
|
|
use app\service\ResourcesService;
|
|
use app\service\PaymentService;
|
|
|
|
/**
|
|
* 钱包服务层
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 0.0.1
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
*/
|
|
class WalletService
|
|
{
|
|
// 钱包状态
|
|
public static $wallet_status_list = [
|
|
0 => ['value' => 0, 'name' => '正常', 'checked' => true],
|
|
1 => ['value' => 1, 'name' => '异常'],
|
|
2 => ['value' => 2, 'name' => '已注销'],
|
|
];
|
|
|
|
// 业务类型
|
|
public static $business_type_list = [
|
|
0 => ['value' => 0, 'name' => '充值', 'checked' => true],
|
|
1 => ['value' => 1, 'name' => '提现'],
|
|
2 => ['value' => 2, 'name' => '消费'],
|
|
];
|
|
|
|
// 操作类型
|
|
public static $operation_type_list = [
|
|
0 => ['value' => 0, 'name' => '减少', 'checked' => true],
|
|
1 => ['value' => 1, 'name' => '增加'],
|
|
];
|
|
|
|
// 金额类型
|
|
public static $money_type_list = [
|
|
0 => ['value' => 0, 'name' => '正常', 'checked' => true],
|
|
1 => ['value' => 1, 'name' => '冻结'],
|
|
];
|
|
|
|
|
|
/**
|
|
* 用户钱包
|
|
* @author Devil
|
|
* @blog http://gong.gg/
|
|
* @version 1.0.0
|
|
* @date 2019-04-30
|
|
* @desc description
|
|
* @param [array] $params [输入参数]
|
|
*/
|
|
public static function UserWallet($params = [])
|
|
{
|
|
// 请求参数
|
|
$p = [
|
|
[
|
|
'checked_type' => 'empty',
|
|
'key_name' => 'user',
|
|
'error_msg' => '用户信息有误',
|
|
],
|
|
];
|
|
$ret = ParamsChecked($params, $p);
|
|
if($ret !== true)
|
|
{
|
|
return DataReturn($ret, -1);
|
|
}
|
|
|
|
// 获取钱包, 不存在则创建
|
|
$wallet = Db::name('PluginsWallet')->where(['user_id' => $params['user']['id']])->find();
|
|
if(empty($wallet))
|
|
{
|
|
$data = [
|
|
'user_id' => $params['user']['id'],
|
|
'status' => 0,
|
|
'add_time' => time(),
|
|
];
|
|
$wallet_id = Db::name('PluginsWallet')->insertGetId($data);
|
|
if($wallet_id > 0)
|
|
{
|
|
$wallet = Db::name('PluginsWallet')->find($wallet_id);
|
|
} else {
|
|
return DataReturn('钱包添加失败', -100);
|
|
}
|
|
}
|
|
|
|
return DataReturn('操作成功', 0, $wallet);
|
|
}
|
|
}
|
|
?>
|