Apply.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. * @noinspection PhpUndefinedMethodInspection
  14. */
  15. public function getList($search)
  16. {
  17. $model = $this->alias('apply')
  18. ->field('apply.*, user.nickName, user.avatarUrl')
  19. ->with(['referee'])
  20. ->join('user', 'user.user_id = apply.user_id')
  21. ->order(['apply.create_time' => 'desc']);
  22. if (!empty($search['nick_name'])) {
  23. $model = $model->where('user.nickName|apply.real_name|apply.mobile', 'like', '%' . $search['nick_name'] . '%');
  24. }
  25. // 获取列表数据
  26. return $model->paginate($search['list_rows']);
  27. }
  28. /**
  29. * 分销商入驻审核
  30. * @param $data
  31. * @return bool
  32. */
  33. public function submit($data)
  34. {
  35. if ($data['apply_status'] == '30' && empty($data['reject_reason'])) {
  36. $this->error = '请填写驳回原因';
  37. return false;
  38. }
  39. $this->startTrans();
  40. if ($data['apply_status'] == '20') {
  41. // 新增分销商用户
  42. User::add($data['user_id'], [
  43. 'real_name' => $data['real_name'],
  44. 'mobile' => $data['mobile'],
  45. 'referee_id' => $data['referee_id'],
  46. ]);
  47. }
  48. $save_data = [
  49. 'audit_time' => time(),
  50. 'apply_status' => $data['apply_status'],
  51. 'reject_reason' => $data['reject_reason'],
  52. ];
  53. $this->save($save_data);
  54. // 记录推荐人关系
  55. if ($data['referee_id'] > 0) {
  56. RefereeModel::createRelation($data['user_id'], $data['referee_id']);
  57. }
  58. // 发送模板消息
  59. (new MessageService)->agent($this);
  60. $this->commit();
  61. return true;
  62. }
  63. /**
  64. * 获取申请中的数量
  65. */
  66. public static function getApplyCount(){
  67. return (new static())->where('apply_status', '=', 10)->count();
  68. }
  69. }