Takecash.php 5.8 KB

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