|
@@ -1,18 +1,10 @@
|
|
|
<?php
|
|
|
-
|
|
|
-
|
|
|
namespace app\api\controller;
|
|
|
-use app\common\model\GoodsOrderItem;
|
|
|
use app\common\model\UserBank;
|
|
|
-use app\common\model\UserIntegralLog;
|
|
|
-use app\common\model\UserLevel;
|
|
|
-use app\common\model\UserMoneyInfo;
|
|
|
-use app\common\model\UserWallet;
|
|
|
-use app\common\model\UserWithdrawLog;
|
|
|
-use think\Db;
|
|
|
+use library\tools\Data;
|
|
|
use app\common\model\User;
|
|
|
/**
|
|
|
- * @title 会员钱包管理(佣金提现,积分,经验...)
|
|
|
+ * @title 会员钱包||银行卡管理【二期的忽略】
|
|
|
* @controller WalletManage
|
|
|
* @group base
|
|
|
*/
|
|
@@ -24,252 +16,125 @@ class WalletManage extends Base
|
|
|
parent::checkLogin();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @title 获取钱包详情
|
|
|
- * @desc 获取钱包详情
|
|
|
- * @author qc
|
|
|
- * @url /api/Wallet_manage/walletInfo
|
|
|
- * @method GET
|
|
|
- * @tag 个人信息
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @return name:detail type:array default:-- desc:钱包
|
|
|
- * @return name:detail.integral type:int default:-- desc:积分
|
|
|
- * @return name:detail.growth type:int default:-- desc:经验值(分销等级成长值)
|
|
|
- * @return name:detail.money type:float default:-- desc:佣金
|
|
|
- * @return name:detail.level_exp type:int default:-- desc:等级经验(会员等级经验值)
|
|
|
- * @return name:detail.withdraw type:float default:-- desc:累积提现
|
|
|
- * @return name:openid type:string default:-- desc:绑定的微信openid
|
|
|
- * @return name:ali_account type:array default:-- desc:支付宝账号
|
|
|
- * @return name:ali_account.real_name type:string default:-- desc:支付宝姓名
|
|
|
- * @return name:ali_account.card_no type:string default:-- desc:支付宝账号
|
|
|
- * @return name:bank_list type:array default:-- desc:绑定银行卡列表
|
|
|
- * @return name:bank_list.real_name type:string require:1 default:-- desc:真实姓名
|
|
|
- * @return name:bank_list.card_no type:string require:1 default:-- desc:账号
|
|
|
- * @return name:bank_list.bank_name type:string require:1 default:-- desc:所属银行
|
|
|
- *
|
|
|
- */
|
|
|
- public function walletInfo()
|
|
|
- {
|
|
|
- $wallet = UserWallet::where('user_id',$this->user_id)->find();
|
|
|
- if(!$wallet) $wallet = UserWallet::create(['user_id'=>$this->user_id]);
|
|
|
- $user_info = User::field('id,name,openid,headimg')->where('id',$this->user_id)->find();
|
|
|
- $ali_account = UserBank::field('id,real_name,card_no')->where(['user_id'=>$this->user_id,'type'=>1,'is_deleted'=>0])->find();
|
|
|
- $bank_list = UserBank::field('id,real_name,card_no,bank_name')->where(['user_id'=>$this->user_id,'type'=>2,'is_deleted'=>0])->order('id desc')->select()->toArray();
|
|
|
- $this->success('获取成功',['detail'=> $wallet->toArray(),'user_info'=>$user_info,'ali_account'=>$ali_account,'bank_list'=>$bank_list]);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * @title 获取个人钱包信息
|
|
|
- * @desc 获取个人钱包信息
|
|
|
+ * @title 更改或绑定银行卡
|
|
|
+ * @desc 更改或绑定银行卡
|
|
|
* @author qc
|
|
|
- * @url /api/Wallet_manage/getUserWallet
|
|
|
- * @method GET
|
|
|
- * @tag 获取个人钱包信息
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @return name:phone type:int default:-- desc:手机号
|
|
|
- * @return name:name type:string default:-- desc:昵称
|
|
|
- * @return name:headimg type:string default:-- desc:头像地址
|
|
|
- * @return name:card_front type:string default:-- desc:身份证正面
|
|
|
- * @return name:card_back type:string default:-- desc:身份证背面
|
|
|
- * @return name:level_name type:string default:-- desc:等级名称
|
|
|
- * @return name:partner_lev type:int default:-- desc:分销商等级id(0不是分销商)
|
|
|
- * @return name:is_agency type:int default:-- desc:是否是区域代理(0不是)
|
|
|
- * @return name:wallet type:array default:-- desc:钱包
|
|
|
- * @return name:wallet.integral type:int default:-- desc:积分
|
|
|
- * @return name:wallet.growth type:int default:-- desc:经验值(分销等级成长值)
|
|
|
- * @return name:wallet.money type:float default:-- desc:佣金
|
|
|
- * @return name:wallet.level_exp type:int default:-- desc:经验值(会员等级)
|
|
|
- *
|
|
|
- */
|
|
|
- public function getUserWallet()
|
|
|
- {
|
|
|
- $field = 'id,name,level_id,headimg,true_name,birthday,is_agency,partner_lev';
|
|
|
- $user_info = User::with('wallet')->field($field)->where('id',$this->user_id)->find()->toArray();
|
|
|
- $user_info['level_name'] = UserLevel::where('id',$user_info['level_id'])->value('name');
|
|
|
- if(empty($user_info)) $this->error('用户信息不正确');
|
|
|
- $this->success('获取成功',['user_info'=>$user_info]);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @title 佣金提现
|
|
|
- * @desc 佣金提现
|
|
|
- * @author qc
|
|
|
- * @url /api/Wallet_manage/withdraw
|
|
|
* @method POST
|
|
|
- * @tag 佣金提现
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:money type:float default:-- desc:提现金额
|
|
|
- * @param name:type type:int default:-- desc:到账类型(1支付宝,2银行卡,3微信)
|
|
|
- * @param name:pay_password type:string default:-- desc:支付密码
|
|
|
- * @param name:bank_id type:int default:-- desc:账号id(type=1或2必传)
|
|
|
+ * @url /api/Wallet_manage/bindBankAccount
|
|
|
+ * @param name:account_id type:string require:1 default:-- desc:记录id(修改时必传)
|
|
|
+ * @param name:phone type:string require:1 default:-- desc:手机号
|
|
|
+ * @param name:code type:string require:1 default:-- desc:验证码
|
|
|
+ * @param name:real_name type:string require:1 default:-- desc:真实姓名
|
|
|
+ * @param name:card_no type:string require:1 default:-- desc:账号
|
|
|
+ * @param name:bank_name type:string require:1 default:-- desc:所属银行
|
|
|
*/
|
|
|
- public function withdraw()
|
|
|
+ public function bindBankAccount()
|
|
|
{
|
|
|
- $rate = 0.03;// 提现手续费
|
|
|
- $min_money = 100 ;// 最低提现金额
|
|
|
- $max_money = 1000;// 最大提现金额
|
|
|
- $money = input('post.money',0);
|
|
|
- $type = input('post.type',0);
|
|
|
- $bank_id = input('post.bank_id',0);
|
|
|
- $pay_password = input('post.pay_password',0);
|
|
|
- if($money < $min_money) $this->error('最低提现金额:'.$min_money);
|
|
|
- if($money > $max_money) $this->error('最大提现金额:'.$max_money);
|
|
|
- $user_info = User::where('id',$this->user_id)->find()->toArray();
|
|
|
- if(!$user_info['pay_password']) $this->error('请设置提现密码');
|
|
|
- if(!check_password($pay_password,$user_info['pay_password'])) $this->error('密码错误');
|
|
|
- if($type == 3 && !$user_info['openid']) $this->error('请先绑定微信!');
|
|
|
- if(in_array($type,[1,2])) {
|
|
|
- $acc_info = UserBank::where(['id'=>$bank_id,'user_id'=>$this->user_id])->find();
|
|
|
- if(!$acc_info) $this->error('账号信息有误');
|
|
|
- }
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- $wallet = UserWallet::where(['user_id'=>$this->user_id])->find();
|
|
|
- if($wallet->money < $money) $this->exception('佣金余额不足');
|
|
|
- $service_fee = bcmul($money,$rate,2);
|
|
|
- $account = bcsub($money,$service_fee,2);
|
|
|
- $ins_data = [
|
|
|
- 'user_id' => $this->user_id,
|
|
|
- 'money' => $money,// 提现金额
|
|
|
- 'rate' => $rate,// 手续费率
|
|
|
- 'service_fee' => $service_fee,// 手续费
|
|
|
- 'account' => $account,// 实际到账金额
|
|
|
- 'type' => $type,
|
|
|
- 'user_name' => $type == 3 ? $user_info['name'] : $acc_info->real_name,
|
|
|
- 'card_no' => $type == 3 ? $user_info['openid'] : $acc_info->card_no,
|
|
|
- 'bank_name' => $type == 3 ? '微信账户' : $acc_info->bank_name,
|
|
|
- ];
|
|
|
- $ins_res = UserWithdrawLog::create($ins_data);// 提现日志
|
|
|
- UserWallet::userMoneyChange($this->user_id,$money,'提现申请',3,-1,$ins_res->id);
|
|
|
- $this->ret_msg = '申请成功';
|
|
|
- }catch (\Exception $e){
|
|
|
- $this->is_commit = false;
|
|
|
- $this->ret_msg = $e->getMessage();
|
|
|
- }
|
|
|
- $this->transReturn();
|
|
|
+ $phone = input('post.phone');
|
|
|
+ $code = input('post.code');
|
|
|
+ $real_name = input('post.real_name');
|
|
|
+ $card_no = input('post.card_no');
|
|
|
+ $bank_name = input('post.bank_name');
|
|
|
+ $account_id = input('post.account_id');
|
|
|
+ $check_code = $this->checkPhoneCode($phone,$code);
|
|
|
+ if(!$check_code) $this->error('验证码错误');
|
|
|
+ $account_data =[
|
|
|
+ 'user_id' => $this->user_id,
|
|
|
+ 'real_name' => $real_name,
|
|
|
+ 'bank_name' => $bank_name,
|
|
|
+ 'card_no' => $card_no,
|
|
|
+ 'create_time' => date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+ if($account_id) $account_data['id'] = $account_id;
|
|
|
+ (new UserBank())->save($account_data);
|
|
|
+ $this->success('绑定成功');
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * @title 获取用户提现日志
|
|
|
- * @desc 获取用户提现日志
|
|
|
+ * @title 获取绑定银行卡列表
|
|
|
+ * @desc 获取绑定银行卡列表
|
|
|
* @author qc
|
|
|
- * @url /api/Wallet_manage/getWithdrawLog
|
|
|
* @method GET
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:status type:int default:-1 desc:状态(0待处理,1已审核 2已到账 3已拒绝 4异常)
|
|
|
- * @param name:type type:int default:-- desc:类型
|
|
|
- * @param name:page type:int : default:1 desc:页数
|
|
|
- * @param name:page_num type:int : default:20 desc:每页数
|
|
|
- * @return name:money type:float default:-- desc:提现金额
|
|
|
- * @return name:type type:int default:-- desc:到账类型(1支付宝,2银行卡,3微信)
|
|
|
- * @return name:money type:float default:-- desc:申请提现金额
|
|
|
- * @return name:rate type:float default:-- desc:手续费率
|
|
|
- * @return name:service_fee type:float default:-- desc:手续费
|
|
|
- * @return name:desc type:float default:-- desc:描述
|
|
|
- * @return name:status type:int default:-- desc:状态(0待处理,1已审核 2已到账 3已拒绝 4异常)
|
|
|
- * @return name:user_name type:string default:-- desc:收款人
|
|
|
- * @return name:card_no type:string default:-- desc:收款账号
|
|
|
- * @return name:bank_name type:string default:-- desc:名称
|
|
|
+ * @url /api/Wallet_manage/getBankAccountList
|
|
|
+ * @return name:real_name type:string require:1 default:-- desc:真实姓名
|
|
|
+ * @return name:card_no type:string require:1 default:-- desc:账号
|
|
|
+ * @return name:bank_name type:string require:1 default:-- desc:所属银行
|
|
|
*/
|
|
|
- public function getWithdrawLog()
|
|
|
+ public function getBankAccountList()
|
|
|
{
|
|
|
- $status = input('get.status',-1);
|
|
|
- $where = [];
|
|
|
- $where['is_deleted'] = 0;
|
|
|
- $where['user_id'] = $this->user_id;
|
|
|
- if($status) $where['status'] = $status;
|
|
|
- $list = UserWithdrawLog::where($where)->limit($this->off_set,$this->page_num)
|
|
|
- ->order('id desc')->select();
|
|
|
- $this->success('ok',['list'=>$list ? $list->toArray():[]]);
|
|
|
+ $list = UserBank::field('id,real_name,card_no,bank_name')
|
|
|
+ ->where(['user_id'=>$this->user_id,'type'=>1,'is_deleted'=>0])
|
|
|
+ ->order('id desc')->select()->toArray();
|
|
|
+ $this->success('ok',['list'=>$list]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * @title 获取用户佣金变更记录
|
|
|
- * @desc 获取用户佣金变更记录
|
|
|
+ * @title 获取绑定银行卡详情
|
|
|
+ * @desc 获取绑定银行卡详情
|
|
|
* @author qc
|
|
|
- * @url /api/Wallet_manage/getUserMoneyInfo
|
|
|
* @method GET
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:page type:int : default:1 desc:页数
|
|
|
- * @param name:page_num type:int : default:20 desc:每页数
|
|
|
- * @return name:money type:float default:-- desc:金额
|
|
|
- * @return name:create_at type:string default:-- desc:时间
|
|
|
- * @return name:desc type:float default:-- desc:描述
|
|
|
+ * @url /api/Wallet_manage/getBankAccountDetail
|
|
|
+ * @param name:account_id type:string require:1 default:-- desc:id
|
|
|
+ * @return name:real_name type:string require:1 default:-- desc:真实姓名
|
|
|
+ * @return name:card_no type:string require:1 default:-- desc:账号
|
|
|
+ * @return name:bank_name type:string require:1 default:-- desc:所属银行
|
|
|
*/
|
|
|
- public function getUserMoneyInfo()
|
|
|
+ public function getBankAccountDetail()
|
|
|
{
|
|
|
- $where = [];
|
|
|
- $where['user_id'] = $this->user_id;
|
|
|
- $list = UserMoneyInfo::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
|
|
|
- $this->success('ok',['list'=>$list ? $list->toArray():[]]);
|
|
|
+ $account_id = input('get.account_id');
|
|
|
+ $account_info = UserBank::field('id,real_name,card_no,bank_name')->where(['user_id'=>$this->user_id,'id'=>$account_id,'is_deleted'=>0])->find();
|
|
|
+ $account_info ? $this->success('ok',['account'=>$account_info->toArray()]) : $this->error('没找到记录');
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
- * @title 获取用户积分变更记录
|
|
|
- * @desc 获取用户积分变更记录
|
|
|
+ * @title 解除银行卡绑定
|
|
|
+ * @desc 解除银行卡绑定
|
|
|
* @author qc
|
|
|
- * @url /api/Wallet_manage/getUserIntegralLog
|
|
|
- * @method GET
|
|
|
- * @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:page type:int : default:1 desc:页数
|
|
|
- * @param name:page_num type:int : default:20 desc:每页数
|
|
|
- * @param name:type type:int : default:0 desc:类型(0全部,1增加,2减少)
|
|
|
- * @return name:integral type:int default:-- desc:变更数量
|
|
|
- * @return name:create_at type:string default:-- desc:时间
|
|
|
- * @return name:desc type:float default:-- desc:描述
|
|
|
+ * @method POST
|
|
|
+ * @url /api/Wallet_manage/delUserBank
|
|
|
+ * @param name:account_id type:string require:1 default:-- desc:id
|
|
|
*/
|
|
|
- public function getUserIntegralLog()
|
|
|
+ public function delUserBank()
|
|
|
{
|
|
|
- $where = [];
|
|
|
- $where[] = ['user_id','=',$this->user_id];
|
|
|
- $where[] = ['is_deleted','=',0];
|
|
|
- if(input('type') == 1) $where[] = ['integral','>','0'];
|
|
|
- if(input('type') == 2) $where[] = ['integral','<','0'];
|
|
|
- $list = UserIntegralLog::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
|
|
|
- $this->success('ok',['list'=>$list ? $list->toArray():[]]);
|
|
|
+ $account_id = input('post.account_id');
|
|
|
+ UserBank::where(['user_id'=>$this->user_id,'id'=>$account_id])->update(['is_deleted'=>1]);
|
|
|
+ $this->success('银行卡解绑成功');
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * @title 获取用户分销佣金记录
|
|
|
- * @desc 获取用户分销佣金记录
|
|
|
- * @author qc
|
|
|
- * @url /api/Wallet_manage/getDistributionMoney
|
|
|
- * @method GET
|
|
|
+ * @title 更换或设置提现密码
|
|
|
+ * @desc 更换或设置提现密码
|
|
|
+ * @author qc
|
|
|
+ * @url /api/Wallet_manage/setPayPassword
|
|
|
+ * @method POST
|
|
|
* @header name:Authorization require:1 desc:Token
|
|
|
- * @param name:page type:int : default:1 desc:页数
|
|
|
- * @param name:page_num type:int : default:20 desc:每页数
|
|
|
- * @return name:money type:float default:-- desc:金额
|
|
|
- * @return name:create_at type:string default:-- desc:时间
|
|
|
- * @return name:desc type:float default:-- desc:描述
|
|
|
- * @return name:type type:float default:-- desc:类型(7一级分销,8二级分销)
|
|
|
- * @return name:user_info type:array default:-- desc:会员信息
|
|
|
- * @return name:user_info.name type:string default:-- desc:会员名
|
|
|
- * @return name:user_info.headimg type:string default:-- desc:会员头像
|
|
|
- * @return name:goods_list type:array default:-- desc:商品列表
|
|
|
- * @return name:goods_list.cover type:array default:-- desc:商品图
|
|
|
- * @return name:goods_list.goods_name type:string default:-- desc:商品名
|
|
|
- * @return name:goods_list.goods_spec type:string default:-- desc:商品规格
|
|
|
- * @return name:goods_list.sell_money type:float default:-- desc:商品价格
|
|
|
- * @return name:goods_list.is_dist type:int default:-- desc:是否是分销商品(0否,1是)
|
|
|
+ * @param name:phone type:int require:1 default:-- desc:手机号
|
|
|
+ * @param name:code type:int require:1 default:-- desc:手机号验证码
|
|
|
+ * @param name:pay_password type:string default:-- desc:密码
|
|
|
*/
|
|
|
- public function getDistributionMoney()
|
|
|
+ public function setPayPassword()
|
|
|
{
|
|
|
- $where = [];
|
|
|
- $where[] = ['user_id','=',$this->user_id];
|
|
|
- $where[] = ['type','in','7,8'];
|
|
|
- $list = UserMoneyInfo::where($where)->limit($this->off_set,$this->page_num)->order('id desc')->select();
|
|
|
- array_walk($list,function ($val){
|
|
|
- $val['user_info'] = User::where('id',$val['user_id'])->field('id,name,headimg')->find()->toArray();
|
|
|
- $goods_list = GoodsOrderItem::where('i.order_id',$val['id'])
|
|
|
- ->alias('i')
|
|
|
- ->leftJoin('StoreGoods g','g.id = i.goods_id')
|
|
|
- ->field('i.cover,i.sell_money,i.num,g.is_dist,i.goods_name,i.goods_spec')
|
|
|
- ->select()->toArray();
|
|
|
- $val['goods_list'] = $goods_list;
|
|
|
- });
|
|
|
- $this->success('ok',['list'=>$list ? $list->toArray():'']);
|
|
|
+ $uid = $this->user_id;
|
|
|
+ $phone = input('post.phone');
|
|
|
+ $code = input('post.code');
|
|
|
+ $pay_password = input('post.pay_password');
|
|
|
+ if(empty($phone) || empty($code) || empty($pay_password)) $this->error('参数错误');
|
|
|
+ $field = 'id,phone';
|
|
|
+ $user_info = User::field($field)->where('id',$this->user_id)->find()->toArray();
|
|
|
+ if(!$user_info['phone']) $this->error('请先绑定手机号');
|
|
|
+ if($user_info['phone'] != $phone) $this->error('与绑定手机号不一致');
|
|
|
+ $check_code = $this->checkPhoneCode($phone,$code);
|
|
|
+ if(!$check_code) $this->error('验证码错误');;
|
|
|
+ User::where('id',$uid)->update(['pay_password'=>encrypt_password($pay_password)]);
|
|
|
+ $this->updatePhoneCode($check_code);
|
|
|
+ $this->success('密码设置成功');
|
|
|
}
|
|
|
|
|
|
|