Withdraw.php 2.9 KB

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