Apply.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\store\model\dealer;
  3. use app\common\model\dealer\Apply as ApplyModel;
  4. use app\common\service\Message as MessageService;
  5. use app\common\enum\dealer\ApplyStatus as ApplyStatusEnum;
  6. /**
  7. * 分销商入驻申请模型
  8. * Class Apply
  9. * @package app\store\model\dealer
  10. */
  11. class Apply extends ApplyModel
  12. {
  13. /**
  14. * 获取分销商申请列表
  15. * @param string $search
  16. * @return \think\Paginator
  17. * @throws \think\exception\DbException
  18. */
  19. public function getList($search = '')
  20. {
  21. // 构建查询规则
  22. $this->alias('apply')
  23. ->field('apply.*, user.nickName, user.avatarUrl')
  24. ->with(['referee'])
  25. ->join('user', 'user.user_id = apply.user_id')
  26. ->order(['apply.create_time' => 'desc']);
  27. // 查询条件
  28. !empty($search) && $this->where('user.nickName|apply.real_name|apply.mobile', 'like', "%$search%");
  29. // 获取列表数据
  30. return $this->paginate(15, false, [
  31. 'query' => \request()->request()
  32. ]);
  33. }
  34. /**
  35. * 分销商入驻审核
  36. * @param $data
  37. * @return bool
  38. */
  39. public function submit($data)
  40. {
  41. if ($data['apply_status'] == ApplyStatusEnum::AUDIT_REJECT && empty($data['reject_reason'])) {
  42. $this->error = '请填写驳回原因';
  43. return false;
  44. }
  45. $this->transaction(function () use ($data) {
  46. if ($data['apply_status'] == ApplyStatusEnum::AUDIT_PASS) {
  47. // 新增分销商用户
  48. User::add($this['user_id'], [
  49. 'real_name' => $this['real_name'],
  50. 'mobile' => $this['mobile'],
  51. 'referee_id' => $this['referee_id'],
  52. ]);
  53. }
  54. // 更新申请记录
  55. $data['audit_time'] = time();
  56. $this->allowField(true)->save($data);
  57. // 发送订阅消息
  58. MessageService::send('dealer.apply', [
  59. 'apply' => $this, // 申请记录
  60. 'user' => $this['user'], // 用户信息
  61. ]);
  62. });
  63. return true;
  64. }
  65. }