model('wallet')->getWallet($this->auth->id,'score'), 'score_bufen' => model('wallet')->getWallet($this->auth->id,'shouyi'), 'bufen_bei' => config('site.withdraw_bufen_bei'), //部分提现整数倍 'bufen_bei_remark' => '部分提现只能提'.config('site.withdraw_bufen_bei').'的整数倍', // 'min_withdrawal_money' => 1, // 'max_withdrawal_money' => 50000, 'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(), 'type_2' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',2)->where('status',1)->field('realname,banknumber,bankname')->find(), 'type_3' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',3)->where('status',1)->field('realname,banknumber,bankname')->find(), ]; $this->success(1,$data); } //提现 public function scorewithdraw() { $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行 $from = input('from','all'); if(!in_array($type,[1,2,3])){ $this->error('参数错误'); } if(!in_array($from,['all','bufen'])){ $this->error('参数错误'); } //检查其他申请 $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find(); if($check){ $this->error('目前还有兑换在审核中,请稍后在兑换'); } //检查是否未确认收货 $map2 = [ 'user_id' => $this->auth->id, 'status' => 1, 'have_paid' => ['gt',0], 'have_received' => 0, ]; $check2 = Db::name('unishop_order')->where($map2)->find(); if($check2){ if($check2['have_delivered'] == 0){ $this->error('您有订单尚未发货,请等待订单完成'); } $this->error('您有订单尚未确认收货,请先完成收货'); } //开启事务 Db::startTrans(); //余额查询 if($from == 'all'){ $user_money = model('wallet')->getWallet($this->auth->id,'score'); }else{ //部分提现 $user_money = model('wallet')->getWallet($this->auth->id,'shouyi'); //最大 $bufen_score = input('bufen_score',0,'intval'); //传入值 if($bufen_score > $user_money){ $this->error('部分提现最高:'.$user_money); } $bufen_bei = config('site.withdraw_bufen_bei') ?: 1; //部分提现整数倍 if($bufen_score < $bufen_bei){ $this->error('部分提现只能是'.$bufen_bei.'的整数倍,最小:'.$bufen_bei); } if($bufen_score % $bufen_bei > 0){ $this->error('部分提现只能是'.$bufen_bei.'的整数倍'); } $user_money = $bufen_score;//传入值赋值 } if ($user_money <= 0) { Db::rollback(); $this->error('积分不足'); } $data = []; $data['order_no'] = createUniqueNo('T',$this->auth->id); $data['user_id'] = $this->auth->id; $data['score'] = $user_money; $data['type'] = $type; $data['realname'] = input('realname',''); $data['banknumber'] = input('banknumber',''); $data['bankname'] = input('bankname',''); $data['createtime'] = time(); $data['status'] = 0; $data['from'] = ($from == 'all') ? 1 : 2; //all=1,bufen=2 //添加提现记录 $log_id = Db::name('user_withdraw')->insertGetId($data); if (!$log_id) { Db::rollback(); $this->error('申请兑换失败'); } //扣收益 if($from == 'bufen'){ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'shouyi',-$data['score'],2,'积分兑换','user_withdraw',$log_id); if ($rs_wallet['status'] == false) { $this->error($rs_wallet['msg']); Db::rollback(); } } //扣积分 $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id); if ($rs_wallet['status'] == false) { $this->error($rs_wallet['msg']); Db::rollback(); } Db::commit(); $this->success('申请兑换成功,请等待审核'); } //废弃的提现 public function old_scorewithdraw() { $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行 /*$money = input('score', '', 'intval'); if ($money <= 0) { $this->error('请输入正确兑换积分'); }*/ $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find(); if($check){ $this->error('目前还有兑换在审核中,请稍后在兑换'); } //余额查询 $user_money = model('wallet')->getWallet($this->auth->id,'score'); /*if ($user_money < $money) { $this->error('余额不足'); }*/ if ($user_money <= 0) { $this->error('积分不足'); } //查询最低最高提现金额 /*$min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1; $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000; if ($money < $min_withdrawal_money) { $this->error('最低提现金额' . $min_withdrawal_money . '元'); } if ($money > $max_withdrawal_money) { $this->error('最高提现金额' . $max_withdrawal_money . '元'); }*/ $data['order_no'] = createUniqueNo('T',$this->auth->id); $data['user_id'] = $this->auth->id; // $data['score'] = $money; $data['score'] = $user_money; $data['type'] = $type; $data['realname'] = input('realname',''); $data['banknumber'] = input('banknumber',''); $data['bankname'] = input('bankname',''); $data['createtime'] = time(); $data['status'] = 0; //开启事务 Db::startTrans(); //添加提现记录 $log_id = Db::name('user_withdraw')->insertGetId($data); if (!$log_id) { Db::rollback(); $this->error('申请兑换失败'); } $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id); if ($rs_wallet['status'] == false) { $this->error($rs_wallet['msg']); Db::rollback(); } Db::commit(); $this->success('申请兑换成功,请等待审核'); } //用户钱包流水 public function scorelog(){ $list = Db::name('user_score_log')->field('id,change_value,log_type,createtime')->where('user_id',$this->auth->id)->autopage()->order('id desc')->select(); foreach($list as $key => &$val){ $val['log_type_text'] = model('wallet')->getlogtype($val['log_type']); } $this->success('success',$list); } }