Takecash.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 提现
  7. */
  8. class Takecash extends Api
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = ['*'];
  12. //提现配置
  13. public function take_cash_config(){
  14. $config = Db::name('take_cash_config')->order('weigh asc,id asc')->select();
  15. $plat_bilv = config('site.withdrawal_plat_bili');
  16. foreach($config as $key => &$val){
  17. $val['get_money'] = bcdiv(bcmul($val['money'],(100-$plat_bilv),2),100,2);
  18. }
  19. $data = [
  20. 'config' => $config,
  21. 'wallet' => model('wallet')->getwallet($this->auth->id),
  22. 'min' => config('site.min_withdrawal_money'),
  23. 'max' => config('site.max_withdrawal_money'),
  24. 'plat_bilv' => $plat_bilv,
  25. 'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
  26. 'user_alipay' => Db::name('user_alipay')->where('user_id',$this->auth->id)->find(),
  27. 'remark' => config('site.take_cash_rule'),
  28. ];
  29. $this->success('success',$data);
  30. }
  31. //提现
  32. public function take_cash(){
  33. $rc_id = input('rc_id',0);
  34. $freemoney = input('freemoney',0);
  35. $type = input('type',1);
  36. if(!$rc_id && !$freemoney){
  37. $this->error('请选择或填写金额');
  38. }
  39. //验证提现类型
  40. $withdraw_type = config('wallet.withdraw_type');
  41. $typeIds = array_keys($withdraw_type);
  42. if (!in_array($type,$typeIds)) {
  43. $this->error('未知的提现类型');
  44. }
  45. $typeStr = isset($withdraw_type[$type]) ? $withdraw_type[$type] : '';
  46. if($this->auth->is_auth != 2){
  47. $this->error('请先完成实名认证');
  48. }
  49. //赋值money
  50. if($rc_id){
  51. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  52. $money = $recharge_config['money'] ?: 0;
  53. }
  54. //自由输入覆盖
  55. if(!empty($freemoney)){
  56. $rc_id = 0;
  57. $money = floatval($freemoney);
  58. }
  59. //
  60. if($money<=0)
  61. {
  62. $this->error('金额必须大于0');
  63. }
  64. $min = config('site.min_withdrawal_money');
  65. $max = config('site.max_withdrawal_money');
  66. if($money < $min){
  67. $this->error('提现金额不能小于'.$min);
  68. }
  69. if($money > $max){
  70. $this->error('提现金额不能大于'.$max);
  71. }
  72. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  73. if($check){
  74. $this->error('您已经申请了提现,请等待审核');
  75. }
  76. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  77. if($money > $user_money){
  78. $this->error('提现金额不能大于可提现余额');
  79. }
  80. if($type == 1){
  81. $table_name = 'user_alipay';
  82. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  83. if(empty($account_json)){
  84. $this->error('未绑定对应的提现账号');
  85. }
  86. $account = $account_json['pay_no'];
  87. $name = $account_json['realname'];
  88. }elseif($type == 2){
  89. $table_name = 'user_bank';
  90. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  91. if(empty($account_json)){
  92. $this->error('未绑定对应的提现账号');
  93. }
  94. $account = $account_json['bank_no'];
  95. $name = $account_json['realname'];
  96. }else{
  97. //微信支付
  98. $account_json = [];
  99. $account = '';
  100. $name = '';
  101. }
  102. $plat_bilv = config('site.withdrawal_plat_bili');
  103. $get_money = bcdiv(bcmul($money,(100-$plat_bilv),2),100,2);
  104. $data = [
  105. 'user_id' => $this->auth->id,
  106. 'money' => $money,
  107. 'get_money' => $get_money,
  108. 'type' => $type,
  109. 'acount_json' => json_encode($account_json),
  110. 'createtime' => time(),
  111. 'updatetime' => time(),
  112. 'status' => 0,
  113. ];
  114. Db::startTrans();
  115. $log_id = Db::name('take_cash')->insertGetId($data);
  116. if(!$log_id){
  117. Db::rollback();
  118. $this->error('提现失败');
  119. }
  120. //扣除money
  121. // $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,15,'提现','take_cash',$log_id);
  122. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'提现',104,'money');
  123. if($rs_wallet['status']===false)
  124. {
  125. Db::rollback();
  126. $this->error($rs_wallet['msg']);
  127. }
  128. Db::commit();
  129. /*$platformMoney = bcsub($money,$get_money,2);
  130. $vbot = new \addons\vbot\Vbot();
  131. $vbot->vbotSendMsg('Withdrawal_Application_Notice', [], [
  132. 'name' => $name,
  133. 'account' => $account,
  134. 'real_money' => $get_money,
  135. 'type' => $typeStr,
  136. 'handingfee' => $platformMoney
  137. ]);*/
  138. $this->success('申请成功请等待审核');
  139. }
  140. //提现记录
  141. public function take_cash_log(){
  142. $list = Db::name('take_cash')->field('id,money,type,createtime')->where(['user_id'=>$this->auth->id])->autopage()->select();
  143. foreach($list as $key => &$val){
  144. $val['remark'] = '';
  145. if($val['type'] == 1){
  146. $val['remark'] = '支付宝提现';
  147. }elseif($val['type'] == 2){
  148. $val['remark'] = '银行卡提现';
  149. }else{
  150. $val['remark'] = '微信提现';
  151. }
  152. }
  153. $this->success('success',$list);
  154. }
  155. }