Takecash.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. $data = [
  16. 'config' => $config,
  17. 'jewel' => model('wallet')->getwallet($this->auth->id,'jewel'),
  18. 'user_bank' => Db::name('user_bank')->where('user_id',$this->auth->id)->find(),
  19. 'user_alipay' => Db::name('user_alipay')->where('user_id',$this->auth->id)->find(),
  20. 'remark' => config('site.takecash_rule'),
  21. ];
  22. $this->success('success',$data);
  23. }
  24. //提现
  25. public function take_cash(){
  26. $rc_id = input('rc_id',0);
  27. $type = input('type',1);
  28. if(!$rc_id){
  29. $this->error('请选择金额');
  30. }
  31. if (!in_array($type,[1,2])) {
  32. $this->error('未知的提现类型');
  33. }
  34. if(!$this->user_auth_limit()){
  35. $this->error('请先完成实名认证');
  36. }
  37. //赋值money
  38. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  39. $money = $recharge_config['money'] ?: 0;
  40. $jewel = $recharge_config['jewel'] ?: 0;
  41. //
  42. if($money<=0 || $jewel<=0)
  43. {
  44. $this->error('金额必须大于0');
  45. }
  46. /*$check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  47. if($check){
  48. $this->error('您已经申请了提现,请等待审核');
  49. }*/
  50. $check = Db::name('take_cash')->where('user_id',$this->auth->id)->whereTime('createtime','today')->find();
  51. if($check){
  52. $this->error('您今天已经申请了提现,明天再来吧');
  53. }
  54. $user_money = model('wallet')->getwallet($this->auth->id,'jewel');
  55. if($jewel > $user_money){
  56. $this->error('提现金额不能大于可提现余额');
  57. }
  58. if($type == 1){
  59. $table_name = 'user_alipay';
  60. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  61. if(empty($account_json)){
  62. $this->error('未绑定对应的提现账号');
  63. }
  64. }else{
  65. $table_name = 'user_bank';
  66. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  67. if(empty($account_json)){
  68. $this->error('未绑定对应的提现账号');
  69. }
  70. }
  71. //平台手续费
  72. $plat_bilv = $recharge_config['plat_bilv'];
  73. $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
  74. //减去手续费,得实得金额
  75. $get_money = bcsub($money,$plat_money,2);
  76. $data = [
  77. 'user_id' => $this->auth->id,
  78. 'jewel' => $jewel,
  79. 'money' => $money,
  80. 'plat_bilv' => $plat_bilv,
  81. 'plat_money' => $plat_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,'jewel',-$jewel,30,'提现(审核中)','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('acount_json',true)->where(['user_id'=>$this->auth->id])->order('id desc')->autopage()->select();
  108. foreach($list as $key => &$val){
  109. $val['remark'] = '';
  110. if($val['type'] == 1){
  111. $val['remark'] = '支付宝提现';
  112. }else{
  113. $val['remark'] = '银行卡提现';
  114. }
  115. }
  116. $this->success('success',$list);
  117. }
  118. }