Apply.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\shop\model\plus\agent;
  3. use app\api\model\plus\agent\Referee as RefereeModel;
  4. use app\common\model\plus\agent\Apply as ApplyModel;
  5. use app\common\service\message\MessageService;
  6. /**
  7. * 分销商入驻申请模型
  8. */
  9. class Apply extends ApplyModel
  10. {
  11. /**
  12. * 获取分销商申请列表
  13. */
  14. public function getList($search)
  15. {
  16. $model = $this->alias('apply')
  17. ->field('apply.*, user.nickName, user.avatarUrl')
  18. ->with(['referee'])
  19. ->join('user', 'user.user_id = apply.user_id')
  20. ->order(['apply.create_time' => 'desc']);
  21. if (!empty($search['nick_name'])) {
  22. $model = $model->where('user.nickName|apply.real_name|apply.mobile', 'like', '%' . $search['nick_name'] . '%');
  23. }
  24. // 获取列表数据
  25. return $model->paginate($search['list_rows']);
  26. }
  27. /**
  28. * 分销商入驻审核
  29. * @param $data
  30. * @return bool
  31. */
  32. public function submit($data)
  33. {
  34. if ($data['apply_status'] == '30' && empty($data['reject_reason'])) {
  35. $this->error = '请填写驳回原因';
  36. return false;
  37. }
  38. $this->startTrans();
  39. if ($data['apply_status'] == '20') {
  40. // 新增分销商用户
  41. User::add($data['user_id'], [
  42. 'real_name' => $data['real_name'],
  43. 'mobile' => $data['mobile'],
  44. 'referee_id' => $data['referee_id'],
  45. ]);
  46. }
  47. $save_data = [
  48. 'audit_time' => time(),
  49. 'apply_status' => $data['apply_status'],
  50. 'reject_reason' => $data['reject_reason'],
  51. ];
  52. $this->save($save_data);
  53. // 记录推荐人关系
  54. if ($data['referee_id'] > 0) {
  55. RefereeModel::createRelation($data['user_id'], $data['referee_id']);
  56. }
  57. // 发送模板消息
  58. (new MessageService)->agent($this);
  59. $this->commit();
  60. return true;
  61. }
  62. }