123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- <?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 app\common\model\User;
- /**
- * @title 会员钱包管理(佣金提现,积分,经验...)
- * @controller WalletManage
- * @group base
- */
- class WalletManage extends Base
- {
- public function initialize()
- {
- parent::initialize();
- 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 获取个人钱包信息
- * @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必传)
- */
- public function withdraw()
- {
- $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();
- }
- /**
- * @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:名称
- */
- public function getWithdrawLog()
- {
- $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():[]]);
- }
- /**
- * @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:描述
- */
- public function getUserMoneyInfo()
- {
- $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():[]]);
- }
- /**
- * @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:描述
- */
- public function getUserIntegralLog()
- {
- $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():[]]);
- }
- /**
- * @title 获取用户分销佣金记录
- * @desc 获取用户分销佣金记录
- * @author qc
- * @url /api/Wallet_manage/getDistributionMoney
- * @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:描述
- * @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是)
- */
- public function getDistributionMoney()
- {
- $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():'']);
- }
- }
|