Apply.php 2.0 KB

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