Takecash.php 3.8 KB

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