Takecash.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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_post('rc_id',0);
  34. $freemoney = input_post('freemoney',0);
  35. $type = input_post('type',1);
  36. if(!$rc_id && !$freemoney){
  37. $this->error('请选择或填写金额');
  38. }
  39. //赋值money
  40. if($rc_id){
  41. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  42. $money = $recharge_config['money'] ?: 0;
  43. }
  44. //自由输入覆盖
  45. if(!empty($freemoney)){
  46. $rc_id = 0;
  47. $money = floatval($freemoney);
  48. }
  49. //
  50. if($money<=0)
  51. {
  52. $this->error('金额必须大于0');
  53. }
  54. $min = config('site.min_withdrawal_money');
  55. $max = config('site.max_withdrawal_money');
  56. if($money < $min){
  57. $this->error('提现金额不能小于'.$min);
  58. }
  59. if($money > $max){
  60. $this->error('提现金额不能大于'.$max);
  61. }
  62. if(empty($this->auth->idcard_status)){
  63. $this->error('请先完成实名认证');
  64. }
  65. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  66. if($check){
  67. $this->error('您已经申请了提现,请等待审核');
  68. }
  69. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  70. if($money > $user_money){
  71. $this->error('提现金额不能大于可提现余额');
  72. }
  73. $table_name = $type == 1 ? 'user_alipay' : 'user_bank';
  74. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  75. if(empty($account_json)){
  76. $this->error('未绑定对应的提现账号');
  77. }
  78. $plat_bilv = config('site.withdrawal_plat_bili');
  79. $get_money = bcdiv(bcmul($money,(100-$plat_bilv),2),100,2);
  80. $data = [
  81. 'user_id' => $this->auth->id,
  82. 'money' => $money,
  83. 'get_money' => $get_money,
  84. 'type' => $type,
  85. 'acount_json' => json_encode($account_json),
  86. 'createtime' => time(),
  87. 'updatetime' => time(),
  88. 'status' => 0,
  89. ];
  90. Db::startTrans();
  91. $log_id = Db::name('take_cash')->insertGetId($data);
  92. if(!$log_id){
  93. Db::rollback();
  94. $this->error('提现失败');
  95. }
  96. //扣除money
  97. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,15,'提现','take_cash',$log_id);
  98. if($rs_wallet['status']===false)
  99. {
  100. Db::rollback();
  101. $this->error($rs_wallet['msg']);
  102. }
  103. Db::commit();
  104. $this->success('申请成功请等待审核');
  105. }
  106. //提现记录
  107. public function take_cash_log(){
  108. $list = Db::name('take_cash')->field('id,money,type,createtime')->where(['user_id'=>$this->auth->id])->autopage()->select();
  109. foreach($list as $key => &$val){
  110. $val['remark'] = $val['type'] == 1 ? '支付宝提现' : '银行卡提现';
  111. }
  112. $this->success('success',$list);
  113. }
  114. }