Takecash.php 4.1 KB

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