Apply.php 1.9 KB

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