|
@@ -444,176 +444,4 @@ class UserCenter extends Common
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 提现配置列表
|
|
|
- * @return void
|
|
|
- */
|
|
|
- public function withdrawalConfigList()
|
|
|
- {
|
|
|
- try {
|
|
|
- $field = 'id,money,real_money';
|
|
|
- $result = model('WithdrawalConfig')->field($field)->autopage()->order('weigh asc')->select();
|
|
|
- if (!empty($result)) {
|
|
|
- //设置是否使用自定义
|
|
|
- $withdrawDefine = config('site.withdraw_define');
|
|
|
- if ($withdrawDefine == 1) {
|
|
|
- $fieldArr = [[
|
|
|
- 'id' => -1,
|
|
|
- 'money' => 0,
|
|
|
- 'real_money' => 0.00,
|
|
|
- ],];
|
|
|
- $result = array_merge($result,$fieldArr);
|
|
|
- }
|
|
|
- }
|
|
|
- $this->success('获取成功',$result);
|
|
|
- } catch (Exception $e) {
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 提现
|
|
|
- * @return void
|
|
|
- */
|
|
|
- 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('参数错误');
|
|
|
- }
|
|
|
- //只有主播可以提现
|
|
|
- if ($isAnchor != 2) {
|
|
|
- throw new Exception('您不是主播不允许提现');
|
|
|
- }
|
|
|
- if ($this->auth->power->withdraw == 1) {
|
|
|
- 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('金额有误');
|
|
|
- }
|
|
|
- $inputMoney = $money;
|
|
|
- $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('未知的配置信息');
|
|
|
- }
|
|
|
- $inputMoney = $withdrawalConfig['money'];
|
|
|
- $moneys = $withdrawalConfig['money'];
|
|
|
- $platformMoney = bcsub($moneys,$withdrawalConfig['real_money'],2);;
|
|
|
- }
|
|
|
- if ($moneys <= 0) {
|
|
|
- throw new Exception('申请金额异常');
|
|
|
- }
|
|
|
- //扣减余额 记录余额日志
|
|
|
- $walletRes = model('wallet')->lockChangeAccountRemain($userId, $inputMoney, '-', $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'];
|
|
|
- }
|
|
|
- $realMoney = bcsub($inputMoney,$platformMoney,2);
|
|
|
- if ($realMoney < 0.1) {
|
|
|
- throw new Exception('输入金额请大于0.1');
|
|
|
- }
|
|
|
- $data = [
|
|
|
- 'user_id' => $userId,//用户ID
|
|
|
- 'money' => $inputMoney,//金额
|
|
|
- 'handingfee' => $platformMoney,//手续费
|
|
|
- 'real_money' => $realMoney,//金额
|
|
|
- 'taxes' => 0.00,//税费
|
|
|
- 'type' => $typeStr,//类型
|
|
|
- 'account' => $account,//提现账户
|
|
|
- 'name' => $name,//真实姓名
|
|
|
- //'memo' => '',//备注
|
|
|
- 'orderid' => getMillisecond() . mt_rand(1, 1000),//订单号
|
|
|
- //'transactionid' => '',//流水号
|
|
|
- 'status' => 'created',//状态:created=申请中,successed=成功,rejected=已拒绝
|
|
|
- //'transfertime' => '',//转账时间
|
|
|
- 'createtime' => time(),//添加时间
|
|
|
- ];
|
|
|
- $withdrawRes = model('Withdraw')->insertGetId($data);
|
|
|
- if (!$withdrawRes) {
|
|
|
- throw new Exception('提现失败');
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- $vbot = new \addons\vbot\Vbot();
|
|
|
- $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
|
|
|
- 'name' => $name,
|
|
|
- 'account' => $account,
|
|
|
- 'real_money' => $realMoney,
|
|
|
- 'type' => $typeStr,
|
|
|
- 'handingfee' => $platformMoney
|
|
|
- ]);
|
|
|
- $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['user_id'] = $this->auth->id;
|
|
|
- //$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());
|
|
|
- }
|
|
|
- }
|
|
|
}
|