|  | @@ -1149,11 +1149,11 @@ class UserCenter extends Common
 | 
	
		
			
				|  |  |       * 提现配置列表
 | 
	
		
			
				|  |  |       * @return void
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    public function withdrawalList()
 | 
	
		
			
				|  |  | +    public function withdrawalConfigList()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              $field = 'id,money,real_money';
 | 
	
		
			
				|  |  | -            $result = model('Withdrawal')->field($field)->autopage()->order('weigh asc')->select();
 | 
	
		
			
				|  |  | +            $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |              $this->success('获取成功',$result);
 | 
	
		
			
				|  |  |          } catch (Exception $e) {
 | 
	
	
		
			
				|  | @@ -1167,11 +1167,14 @@ class UserCenter extends Common
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public function withdrawal()
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  | +        Db::startTrans();
 | 
	
		
			
				|  |  |          try {
 | 
	
		
			
				|  |  |              $withdrawConfigId = $this->request->param('id',0);
 | 
	
		
			
				|  |  |              $money = $this->request->param('money',0.00);
 | 
	
		
			
				|  |  | +            $type = $this->request->param('type',0);
 | 
	
		
			
				|  |  |              $userId = $this->auth->id;
 | 
	
		
			
				|  |  |              $isAnchor = $this->auth->is_anchor;
 | 
	
		
			
				|  |  | +            $userMoney = $this->auth->money;
 | 
	
		
			
				|  |  |              if (empty($withdrawConfigId) && empty($money)) {
 | 
	
		
			
				|  |  |                  throw new Exception('参数错误');
 | 
	
		
			
				|  |  |              }
 | 
	
	
		
			
				|  | @@ -1179,23 +1182,106 @@ class UserCenter extends Common
 | 
	
		
			
				|  |  |              if ($isAnchor != 2) {
 | 
	
		
			
				|  |  |                  throw new Exception('您不是主播不允许提现');
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            //验证提现类型
 | 
	
		
			
				|  |  | +            $withdrawTypeConfig = config('wallet.withdraw_type');
 | 
	
		
			
				|  |  | +            $typeIds = array_keys($withdrawTypeConfig);
 | 
	
		
			
				|  |  | +            if (!in_array($type,$typeIds)) {
 | 
	
		
			
				|  |  | +                throw new Exception('未知的提现类型');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $typeStr = isset($withdrawTypeConfig[$type]) ? $withdrawTypeConfig[$type] : '';
 | 
	
		
			
				|  |  | +            $withdrawRateConfig = config('site.withdrawRate');//用户获取的金额比例(需要/100)
 | 
	
		
			
				|  |  | +            $withdrawRate = bcdiv($withdrawRateConfig,100,2);
 | 
	
		
			
				|  |  | +            if (!empty($money)) {//自定义金额
 | 
	
		
			
				|  |  | +                if ($money <= 0) {
 | 
	
		
			
				|  |  | +                    throw new Exception('金额有误');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $moneys = bcmul($money,$withdrawRate,2);
 | 
	
		
			
				|  |  | +                $platformMoney = bcsub($money,$moneys,2);
 | 
	
		
			
				|  |  | +            } else {//提现配置
 | 
	
		
			
				|  |  | +                $where['id'] = $withdrawConfigId;
 | 
	
		
			
				|  |  | +                $withdrawalConfig = model('WithdrawalConfig')->where($where)->find();
 | 
	
		
			
				|  |  | +                if (empty($withdrawalConfig)) {
 | 
	
		
			
				|  |  | +                    throw new Exception('未知的配置信息');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $moneys = $withdrawalConfig['money'];
 | 
	
		
			
				|  |  | +                $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if ($moneys <= 0) {
 | 
	
		
			
				|  |  | +                throw new Exception('申请金额异常');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //扣减余额 记录余额日志
 | 
	
		
			
				|  |  | +            $walletRes = model('wallet')->lockChangeAccountRemain($userId, $moneys, '-', $userMoney, '申请提现', 104,'money');
 | 
	
		
			
				|  |  | +            if (!$walletRes['status']) {
 | 
	
		
			
				|  |  | +                throw new Exception($walletRes['msg']);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $account = $name = '';
 | 
	
		
			
				|  |  | +            if ($type == 1) {//微信
 | 
	
		
			
				|  |  | +                $account = '';
 | 
	
		
			
				|  |  | +                $name = '';
 | 
	
		
			
				|  |  | +            } elseif ($type == 2) {//支付宝
 | 
	
		
			
				|  |  | +                $userAlipayWhere['user_id'] = $userId;
 | 
	
		
			
				|  |  | +                $userAlipay = model('UserAlipay')->where($userAlipayWhere)->find();
 | 
	
		
			
				|  |  | +                if (empty($userAlipay)) {
 | 
	
		
			
				|  |  | +                    throw new Exception('请绑定支付宝');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $account = $userAlipay['pay_no'];
 | 
	
		
			
				|  |  | +                $name = $userAlipay['realname'];
 | 
	
		
			
				|  |  | +            } elseif ($type == 3) {//银行
 | 
	
		
			
				|  |  | +                $userBankWhere['user_id'] = $userId;
 | 
	
		
			
				|  |  | +                $userBank = model('UserBank')->where($userBankWhere)->find();
 | 
	
		
			
				|  |  | +                if (empty($userBank)) {
 | 
	
		
			
				|  |  | +                    throw new Exception('请绑定银行卡');
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                $account = $userBank['bank_no'];
 | 
	
		
			
				|  |  | +                $name = $userBank['realname'];
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |              $data = [
 | 
	
		
			
				|  |  |                  'user_id'       => $userId,//用户ID
 | 
	
		
			
				|  |  | -                'money'         => '',//金额
 | 
	
		
			
				|  |  | -                'handingfee'    => '',//手续费
 | 
	
		
			
				|  |  | -                'taxes'         => '',//税费
 | 
	
		
			
				|  |  | -                'type'          => '',//类型
 | 
	
		
			
				|  |  | -                'account'       => '',//提现账户
 | 
	
		
			
				|  |  | -                'name'          => '',//真实姓名
 | 
	
		
			
				|  |  | -                'memo'          => '',//备注
 | 
	
		
			
				|  |  | -                'orderid'       => '',//订单号
 | 
	
		
			
				|  |  | -                'transactionid' => '',//流水号
 | 
	
		
			
				|  |  | -                'status'        => '',//状态:created=申请中,successed=成功,rejected=已拒绝
 | 
	
		
			
				|  |  | -                'transfertime'  => '',//转账时间
 | 
	
		
			
				|  |  | -                'createtime'    => '',//添加时间
 | 
	
		
			
				|  |  | +                'money'         => $moneys,//金额
 | 
	
		
			
				|  |  | +                'handingfee'    => $platformMoney,//手续费
 | 
	
		
			
				|  |  | +                'taxes'         => 0.00,//税费
 | 
	
		
			
				|  |  | +                'type'          => $typeStr,//类型
 | 
	
		
			
				|  |  | +                'account'       => $account,//提现账户
 | 
	
		
			
				|  |  | +                'name'          => $name,//真实姓名
 | 
	
		
			
				|  |  | +                //'memo'          => '',//备注
 | 
	
		
			
				|  |  | +                //'orderid'       => '',//订单号
 | 
	
		
			
				|  |  | +                //'transactionid' => '',//流水号
 | 
	
		
			
				|  |  | +                'status'        => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
 | 
	
		
			
				|  |  | +                //'transfertime'  => '',//转账时间
 | 
	
		
			
				|  |  | +                'createtime'    => time(),//添加时间
 | 
	
		
			
				|  |  |              ];
 | 
	
		
			
				|  |  | +            $withdrawRes = model('Withdraw')->insertGetId($data);
 | 
	
		
			
				|  |  | +            if (!$withdrawRes) {
 | 
	
		
			
				|  |  | +                throw new Exception('提现失败');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Db::commit();
 | 
	
		
			
				|  |  |              $this->success('操作成功待审核');
 | 
	
		
			
				|  |  |          } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            Db::rollback();
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 提现列表
 | 
	
		
			
				|  |  | +     * @return void
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public function withdrawalList()
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $field = 'id,money,type,status,createtime,transfertime';
 | 
	
		
			
				|  |  | +            $where=[];
 | 
	
		
			
				|  |  | +            //$where['status'] = 'successed';//状态:created=申请中,successed=成功,rejected=已拒绝
 | 
	
		
			
				|  |  | +            $result = model('Withdraw')->field($field)->where($where)->autopage()->order('createtime desc')->select();
 | 
	
		
			
				|  |  | +            if (!empty($result)) {
 | 
	
		
			
				|  |  | +                foreach ($result as $key => &$value) {
 | 
	
		
			
				|  |  | +                    $value['money'] = '-'.$value['money'];
 | 
	
		
			
				|  |  | +                    $value['createtime'] = !empty($value['createtime']) ? date('Y-m-d H:i', $value['createtime']) : '';
 | 
	
		
			
				|  |  | +                    $value['transfertime'] = !empty($value['transfertime']) ? date('Y-m-d H:i', $value['transfertime']) : '';
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $this->success('获取成功',$result);
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  |              $this->error($e->getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 |