Takecash.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 提现
  7. */
  8. class Takecash extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //提现配置
  13. public function take_cash_config(){
  14. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  15. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  16. $data = [
  17. 'money' => model('walletcompany')->getwallet($this->auth->company_id,'money'),
  18. 'bank_name' => $this->auth->bank_name,
  19. 'bank_branchname' => $this->auth->bank_branchname,
  20. 'bank_account' => $this->auth->bank_account,
  21. 'bank_card' => $this->auth->bank_card,
  22. 'min' => $min_withdrawal_money,
  23. 'max' => $max_withdrawal_money,
  24. ];
  25. $this->success('success',$data);
  26. }
  27. //提现
  28. public function take_cash(){
  29. $money = floatval(input('money', 0, 'trim'));
  30. //格式
  31. if(empty($money) || $money <= 0){
  32. $this->error('请输入正确提现金额');
  33. }
  34. //最低提现金额
  35. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  36. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  37. if ($money < $min_withdrawal_money) {
  38. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  39. }
  40. if ($money > $max_withdrawal_money) {
  41. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  42. }
  43. //查重
  44. $check = Db::name('company_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  45. if($check){
  46. $this->error('您已经申请了提现,请等待审核');
  47. }
  48. //对比
  49. $user_money = model('walletcompany')->getwallet($this->auth->id,'money');
  50. if($money > $user_money){
  51. $this->error('提现金额不能大于可提现余额');
  52. }
  53. //查询提现手续费百分比
  54. $withdrawal_server_fee = (int)config('site.withdrawal_server_fee') ? : 0;
  55. if ($withdrawal_server_fee < 0 || $withdrawal_server_fee >= 100) {
  56. $this->error('提现手续费异常');
  57. }
  58. //
  59. $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_server_fee,2),2),100,2);
  60. $data = [
  61. 'order_no' => createUniqueNo('T',$this->auth->id),
  62. 'user_id' => $this->auth->id,
  63. 'money' => $money,
  64. 'real_money' => $real_money,
  65. 'bank_name' => $this->auth->bank_name,
  66. 'bank_branchname' => $this->auth->bank_branchname,
  67. 'bank_account' => $this->auth->bank_account,
  68. 'bank_card' => $this->auth->bank_card,
  69. 'status' => 0,
  70. 'createtime' => time(),
  71. 'updatetime' => time(),
  72. ];
  73. Db::startTrans();
  74. $logid = Db::name('company_take_cash')->insertGetId($data);
  75. if (!$logid) {
  76. Db::rollback();
  77. $this->error('提现失败');
  78. }
  79. $rs_wallet = model('walletcompany')->lockChangeAccountRemain($this->auth->id,'money',-$money,101,'提现','company_take_cash',$logid);
  80. if($rs_wallet['status'] === false){
  81. Db::rollback();
  82. $this->error($rs_wallet['msg']);
  83. }
  84. Db::commit();
  85. $this->success('申请提现成功,请等待审核');
  86. }
  87. //提现记录
  88. public function take_cash_log(){
  89. $list = Db::name('company_take_cash')->where(['user_id'=>$this->auth->id])->autopage()->select();
  90. $this->success('success',$list);
  91. }
  92. }