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():'']); } }