Withdraw.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /**
  3. *
  4. * @copyright ©2020 点小铺
  5. * @author hanj
  6. * @link: https://dyuit.com
  7. * Created by VSCode
  8. */
  9. namespace app\api\model\dealer;
  10. use app\common\exception\BaseException;
  11. use app\common\model\dealer\Withdraw as WithdrawModel;
  12. /**
  13. * 分销商提现明细模型
  14. * Class Withdraw
  15. * @package app\api\model\dealer
  16. */
  17. class Withdraw extends WithdrawModel
  18. {
  19. /**
  20. * 隐藏字段
  21. * @var array
  22. */
  23. protected $hidden = [
  24. 'update_time',
  25. ];
  26. /**
  27. * 获取分销商提现明细
  28. * @param $user_id
  29. * @param int $apply_status
  30. * @return \think\Paginator
  31. * @throws \think\exception\DbException
  32. */
  33. public function getList($user_id, $apply_status = -1)
  34. {
  35. $this->where('user_id', '=', $user_id);
  36. $apply_status > -1 && $this->where('apply_status', '=', $apply_status);
  37. return $this->order(['create_time' => 'desc'])
  38. ->paginate(15, false, [
  39. 'query' => \request()->request()
  40. ]);
  41. }
  42. /**
  43. * 提交申请
  44. * @param User $dealer
  45. * @param $data
  46. * @return false|int
  47. * @throws BaseException
  48. */
  49. public function submit($dealer, $data)
  50. {
  51. // 数据验证
  52. $this->validation($dealer, $data);
  53. // 新增申请记录
  54. $this->save(array_merge($data, [
  55. 'user_id' => $dealer['user_id'],
  56. 'apply_status' => 10,
  57. 'wxapp_id' => self::$wxapp_id,
  58. ]));
  59. // 冻结用户资金
  60. $dealer->freezeMoney($data['money']);
  61. return true;
  62. }
  63. /**
  64. * 数据验证
  65. * @param $dealer
  66. * @param $data
  67. * @throws BaseException
  68. */
  69. private function validation($dealer, $data)
  70. {
  71. // 结算设置
  72. $settlement = Setting::getItem('settlement');
  73. // 最低提现佣金
  74. if ($data['money'] <= 0) {
  75. throw new BaseException(['msg' => '提现金额不正确']);
  76. }
  77. if ($dealer['money'] <= 0) {
  78. throw new BaseException(['msg' => '当前用户没有可提现佣金']);
  79. }
  80. if ($data['money'] > $dealer['money']) {
  81. throw new BaseException(['msg' => '提现金额不能大于可提现佣金']);
  82. }
  83. if ($data['money'] < $settlement['min_money']) {
  84. throw new BaseException(['msg' => '最低提现金额为' . $settlement['min_money']]);
  85. }
  86. if (!in_array($data['pay_type'], $settlement['pay_type'])) {
  87. throw new BaseException(['msg' => '提现方式不正确']);
  88. }
  89. if ($data['pay_type'] == '20') {
  90. if (empty($data['alipay_name']) || empty($data['alipay_account'])) {
  91. throw new BaseException(['msg' => '请补全提现信息']);
  92. }
  93. } elseif ($data['pay_type'] == '30') {
  94. if (empty($data['bank_name']) || empty($data['bank_account']) || empty($data['bank_card'])) {
  95. throw new BaseException(['msg' => '请补全提现信息']);
  96. }
  97. }
  98. }
  99. }