Takecash.php 5.2 KB

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