Takecash.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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(){
  14. $freemoney = input('freemoney',0);
  15. // $type = input('type',1);
  16. $type = 2;
  17. if(!$freemoney){
  18. $this->error('请填写金额');
  19. }
  20. if (!in_array($type,[1,2,3])) {
  21. $this->error('未知的提现类型');
  22. }
  23. //赋值money
  24. /*if($rc_id){
  25. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  26. $money = $recharge_config['money'] ?: 0;
  27. }*/
  28. //自由输入覆盖
  29. if(!empty($freemoney)){
  30. $rc_id = 0;
  31. $money = floatval($freemoney);
  32. }
  33. //
  34. if($money<=0)
  35. {
  36. $this->error('金额必须大于0');
  37. }
  38. $min = config('site.min_takecash_money');
  39. $max = config('site.max_takecash_money');
  40. if($money < $min){
  41. $this->error('提现金额不能小于'.$min);
  42. }
  43. if($money > $max){
  44. $this->error('提现金额不能大于'.$max);
  45. }
  46. $check = Db::name('user_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  47. if($check){
  48. $this->error('您已经申请了提现,请等待审核');
  49. }
  50. $user_money = model('wallet')->getwallet($this->auth->id,'money');
  51. if($money > $user_money){
  52. $this->error('提现金额不能大于可提现余额');
  53. }
  54. if($type == 1){
  55. $table_name = 'user_alipay';
  56. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  57. if(empty($account_json)){
  58. $this->error('未绑定对应的提现账号');
  59. }
  60. }elseif($type == 2){
  61. $table_name = 'user_bank';
  62. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  63. if(empty($account_json)){
  64. $this->error('未绑定对应的提现账号');
  65. }
  66. }elseif($type == 3){
  67. //微信支付
  68. $table_name = 'user_wechat';
  69. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  70. if(empty($account_json)){
  71. $this->error('未绑定对应的提现账号');
  72. }
  73. }
  74. //平台手续费
  75. $plat_bilv = config('site.takecash_plat_bili');
  76. $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
  77. //减去手续费,得实得金额
  78. $get_money = bcsub($money,$plat_money,2);
  79. $data = [
  80. 'user_id' => $this->auth->id,
  81. 'money' => $money,
  82. 'plat_bilv' => $plat_bilv,
  83. 'plat_money' => $plat_money,
  84. 'get_money' => $get_money,
  85. 'type' => $type,
  86. 'acount_json' => json_encode($account_json),
  87. 'createtime' => time(),
  88. 'updatetime' => time(),
  89. 'status' => 0,
  90. ];
  91. Db::startTrans();
  92. $log_id = Db::name('user_take_cash')->insertGetId($data);
  93. if(!$log_id){
  94. Db::rollback();
  95. $this->error('提现失败');
  96. }
  97. //扣除money
  98. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'money',-$money,21,'提现(审核中)','user_take_cash',$log_id);
  99. if($rs_wallet['status']===false)
  100. {
  101. Db::rollback();
  102. $this->error($rs_wallet['msg']);
  103. }
  104. Db::commit();
  105. $this->success('申请成功请等待审核');
  106. }
  107. //提现记录
  108. public function take_cash_log(){
  109. $list = Db::name('user_take_cash')->field('id,money,get_money,type,createtime,status')->where(['user_id'=>$this->auth->id])->autopage()->select();
  110. foreach($list as $key => &$val){
  111. $val['remark'] = '';
  112. if($val['type'] == 1){
  113. $val['remark'] = '支付宝提现';
  114. }elseif($val['type'] == 2){
  115. $val['remark'] = '银行卡提现';
  116. }else{
  117. $val['remark'] = '微信提现';
  118. }
  119. }
  120. $this->success('success',$list);
  121. }
  122. /////////////////////////没用到/////////////////////
  123. //提现配置
  124. public function take_cash_config(){
  125. $config = Db::name('take_cash_config')->order('weigh asc,id asc')->select();
  126. $plat_bilv = config('site.takecash_plat_bili');
  127. foreach($config as $key => &$val){
  128. $val['get_money'] = bcdiv(bcmul($val['money'],(100-$plat_bilv),2),100,2);
  129. }
  130. $data = [
  131. 'config' => $config,
  132. 'wallet' => model('wallet')->getwallet($this->auth->id),
  133. 'min' => config('site.min_takecash_money'),
  134. 'max' => config('site.max_takecash_money'),
  135. 'plat_bilv' => $plat_bilv,
  136. 'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
  137. 'user_alipay' => Db::name('user_alipay')->where('user_id',$this->auth->id)->find(),
  138. 'remark' => config('site.take_cash_rule'),
  139. ];
  140. $this->success('success',$data);
  141. }
  142. }