Takecash.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. public function _initialize()
  13. {
  14. parent::_initialize();
  15. }
  16. //提现配置
  17. public function take_cash_config(){
  18. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  19. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  20. $data = [
  21. 'money' => model('walletcompany')->getwallet($this->auth->company_id,'money'),
  22. 'bank_name' => $this->auth->bank_name,
  23. 'bank_branchname' => $this->auth->bank_branchname,
  24. 'bank_account' => $this->auth->bank_account,
  25. 'bank_card' => $this->auth->bank_card,
  26. 'min' => $min_withdrawal_money,
  27. 'max' => $max_withdrawal_money,
  28. ];
  29. $this->success('success',$data);
  30. }
  31. //提现
  32. public function take_cash(){
  33. $money = floatval(input('money', 0, 'trim'));
  34. //格式
  35. if(empty($money) || $money <= 0){
  36. $this->error('请输入正确提现金额');
  37. }
  38. //最低提现金额
  39. $min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
  40. $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
  41. if ($money < $min_withdrawal_money) {
  42. $this->error('最低提现金额' . $min_withdrawal_money . '元');
  43. }
  44. if ($money > $max_withdrawal_money) {
  45. $this->error('最高提现金额' . $max_withdrawal_money . '元');
  46. }
  47. //查重
  48. $check = Db::name('company_take_cash')->where(['user_id'=>$this->auth->id,'status'=>0])->find();
  49. if($check){
  50. $this->error('您已经申请了提现,请等待审核');
  51. }
  52. //对比
  53. $user_money = model('walletcompany')->getwallet($this->auth->id,'money');
  54. if($money > $user_money){
  55. $this->error('提现金额不能大于可提现余额');
  56. }
  57. //查询提现手续费百分比
  58. $withdrawal_server_fee = (int)config('site.withdrawal_server_fee') ? : 0;
  59. if ($withdrawal_server_fee < 0 || $withdrawal_server_fee >= 100) {
  60. $this->error('提现手续费异常');
  61. }
  62. //
  63. $real_money = bcdiv(bcmul($money,bcsub(100,$withdrawal_server_fee,2),2),100,2);
  64. $data = [
  65. 'order_no' => createUniqueNo('T',$this->auth->id),
  66. 'user_id' => $this->auth->id,
  67. 'money' => $money,
  68. 'real_money' => $real_money,
  69. 'bank_name' => $this->auth->bank_name,
  70. 'bank_branchname' => $this->auth->bank_branchname,
  71. 'bank_account' => $this->auth->bank_account,
  72. 'bank_card' => $this->auth->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->id,'money',-$money,101,'提现','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->id])->autopage()->select();
  94. $this->success('success',$list);
  95. }
  96. }