Takecash.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. if($this->auth->type != 1){
  27. $this->error('只有门店老板才能操作');
  28. }
  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->company_id,'status'=>0])->find();
  45. if($check){
  46. $this->error('您已经申请了提现,请等待审核');
  47. }
  48. //对比
  49. $user_money = model('walletcompany')->getwallet($this->auth->company_id,'money');
  50. if($money > $user_money){
  51. $this->error('提现金额不能大于可提现余额');
  52. }
  53. //查询提现手续费百分比
  54. $withdrawal_service_fee = (int)config('site.withdrawal_service_fee') ? : 0;
  55. if ($withdrawal_service_fee < 0 || $withdrawal_service_fee >= 100) {
  56. $this->error('提现手续费异常');
  57. }
  58. $bank_info = Db::name('company_bank')->where('company_id',$this->auth->company_id)->find();
  59. if(empty($bank_info)){
  60. $this->error('请先设置银行卡');
  61. }
  62. //
  63. $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_service_fee,2),2),100,2);
  64. $data = [
  65. 'order_no' => createUniqueNo('T',$this->auth->id),
  66. 'user_id' => $this->auth->company_id,
  67. 'money' => $money,
  68. 'real_money' => $real_money,
  69. 'bank_name' => $bank_info['bank_name'],
  70. 'bank_branchname' => $bank_info['bank_branchname'],
  71. 'bank_account' => $bank_info['bank_account'],
  72. 'bank_card' => $bank_info['bank_card'],
  73. 'status' => 0,
  74. 'createtime' => time(),
  75. 'updatetime' => time(),
  76. ];
  77. Db::startTrans();
  78. $logid = Db::name('company_take_cash')->insertGetId($data);
  79. if (!$logid) {
  80. Db::rollback();
  81. $this->error('提现失败');
  82. }
  83. $rs_wallet = model('walletcompany')->lockChangeAccountRemain($this->auth->company_id,'money',-$money,205,'提现','company_take_cash',$logid);
  84. if($rs_wallet['status'] === false){
  85. Db::rollback();
  86. $this->error($rs_wallet['msg']);
  87. }
  88. Db::commit();
  89. $this->success('申请提现成功,请等待审核');
  90. }
  91. //提现记录
  92. public function take_cash_log(){
  93. $list = Db::name('company_take_cash')->where('user_id',$this->auth->company_id)->autopage()->select();
  94. $this->success('success',$list);
  95. }
  96. }