Takecash.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. $user_money = model('wallet')->getwallet($this->auth->id,'jewel');
  51. if($jewel > $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. }else{
  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. }
  67. //平台手续费
  68. $plat_bilv = $recharge_config['plat_bilv'];
  69. $plat_money = bcdiv(bcmul($money,$plat_bilv,2),100,2);
  70. //减去手续费,得实得金额
  71. $get_money = bcsub($money,$plat_money,2);
  72. $data = [
  73. 'user_id' => $this->auth->id,
  74. 'jewel' => $jewel,
  75. 'money' => $money,
  76. 'plat_bilv' => $plat_bilv,
  77. 'plat_money' => $plat_money,
  78. 'get_money' => $get_money,
  79. 'type' => $type,
  80. 'acount_json' => json_encode($account_json),
  81. 'createtime' => time(),
  82. 'updatetime' => time(),
  83. 'status' => 0,
  84. ];
  85. Db::startTrans();
  86. $log_id = Db::name('take_cash')->insertGetId($data);
  87. if(!$log_id){
  88. Db::rollback();
  89. $this->error('提现失败');
  90. }
  91. //扣除money
  92. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'jewel',-$jewel,30,'提现(审核中)','take_cash',$log_id);
  93. if($rs_wallet['status']===false)
  94. {
  95. Db::rollback();
  96. $this->error($rs_wallet['msg']);
  97. }
  98. Db::commit();
  99. $this->success('申请成功请等待审核');
  100. }
  101. //提现记录
  102. public function take_cash_log(){
  103. $list = Db::name('take_cash')->field('acount_json',true)->where(['user_id'=>$this->auth->id])->autopage()->select();
  104. foreach($list as $key => &$val){
  105. $val['remark'] = '';
  106. if($val['type'] == 1){
  107. $val['remark'] = '支付宝提现';
  108. }else{
  109. $val['remark'] = '银行卡提现';
  110. }
  111. }
  112. $this->success('success',$list);
  113. }
  114. }