Takecash.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. if($rc_id){
  39. $recharge_config = Db::name('take_cash_config')->where('id',$rc_id)->find();
  40. $money = $recharge_config['money'] ?: 0;
  41. $jewel = $recharge_config['jewel'] ?: 0;
  42. }
  43. //
  44. if($money<=0 || $jewel<=0)
  45. {
  46. $this->error('金额必须大于0');
  47. }
  48. $check = Db::name('take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  49. if($check){
  50. $this->error('您已经申请了提现,请等待审核');
  51. }
  52. $user_money = model('wallet')->getwallet($this->auth->id,'jewel');
  53. if($money > $user_money){
  54. $this->error('提现金额不能大于可提现余额');
  55. }
  56. if($type == 1){
  57. $table_name = 'user_alipay';
  58. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  59. if(empty($account_json)){
  60. $this->error('未绑定对应的提现账号');
  61. }
  62. }else{
  63. $table_name = 'user_bank';
  64. $account_json = Db::name($table_name)->where('user_id',$this->auth->id)->find();
  65. if(empty($account_json)){
  66. $this->error('未绑定对应的提现账号');
  67. }
  68. }
  69. $data = [
  70. 'user_id' => $this->auth->id,
  71. 'money' => $money,
  72. 'jewel' => $jewel,
  73. 'type' => $type,
  74. 'acount_json' => json_encode($account_json),
  75. 'createtime' => time(),
  76. 'updatetime' => time(),
  77. 'status' => 0,
  78. ];
  79. Db::startTrans();
  80. $log_id = Db::name('take_cash')->insertGetId($data);
  81. if(!$log_id){
  82. Db::rollback();
  83. $this->error('提现失败');
  84. }
  85. //扣除money
  86. $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'jewel',-$jewel,30,'提现','take_cash',$log_id);
  87. if($rs_wallet['status']===false)
  88. {
  89. Db::rollback();
  90. $this->error($rs_wallet['msg']);
  91. }
  92. Db::commit();
  93. $this->success('申请成功请等待审核');
  94. }
  95. //提现记录
  96. public function take_cash_log(){
  97. $list = Db::name('take_cash')->field('id,jewel,money,type,createtime')->where(['user_id'=>$this->auth->id])->autopage()->select();
  98. foreach($list as $key => &$val){
  99. $val['remark'] = '';
  100. if($val['type'] == 1){
  101. $val['remark'] = '支付宝提现';
  102. }else{
  103. $val['remark'] = '银行卡提现';
  104. }
  105. }
  106. $this->success('success',$list);
  107. }
  108. }