MerchantIntention.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace app\controller\api\store\merchant;
  3. use app\common\repositories\system\merchant\MerchantCategoryRepository;
  4. use app\common\repositories\system\merchant\MerchantTypeRepository;
  5. use app\validate\api\MerchantIntentionValidate;
  6. use ln\services\SwooleTaskService;
  7. use ln\services\YunxinSmsService;
  8. use think\App;
  9. use ln\basic\BaseController;
  10. use app\common\repositories\system\merchant\MerchantIntentionRepository as repository;
  11. use think\exception\ValidateException;
  12. class MerchantIntention extends BaseController
  13. {
  14. protected $repository;
  15. protected $userInfo;
  16. public function __construct(App $app, repository $repository)
  17. {
  18. parent::__construct($app);
  19. $this->repository = $repository;
  20. $this->userInfo = $this->request->isLogin() ? $this->request->userInfo() : null;
  21. }
  22. public function create()
  23. {
  24. $data = $this->checkParams();
  25. if ($this->userInfo) $data['uid'] = $this->userInfo->uid;
  26. $intention = $this->repository->create($data);
  27. SwooleTaskService::admin('notice', [
  28. 'type' => 'new_intention',
  29. 'data' => [
  30. 'title' => '商户入驻申请',
  31. 'message' => '您有一个新的商户入驻申请',
  32. 'id' => $intention->mer_intention_id
  33. ]
  34. ]);
  35. return app('json')->success('提交成功');
  36. }
  37. public function update($id)
  38. {
  39. if (!$this->repository->getWhere(['mer_intention_id' => (int)$id, 'uid' => $this->userInfo->uid, 'is_del' => 0]))
  40. return app('json')->fail('数据不存在');
  41. $data = $this->checkParams();
  42. $data['create_time'] = date('Y-m-d H:i:s',time());
  43. $this->repository->updateIntention((int)$id, $data);
  44. SwooleTaskService::admin('notice', [
  45. 'type' => 'new_intention',
  46. 'data' => [
  47. 'title' => '商户入驻申请',
  48. 'message' => '您有一个新的商户入驻申请',
  49. 'id' => $id
  50. ]
  51. ]);
  52. return app('json')->success('修改成功');
  53. }
  54. public function lst()
  55. {
  56. [$page, $limit] = $this->getPage();
  57. $data = $this->repository->getList(['uid' => $this->userInfo->uid], $page, $limit);
  58. return app('json')->success($data);
  59. }
  60. function detail($id)
  61. {
  62. $data = $this->repository->detail((int)$id, $this->userInfo->uid);
  63. if (!$data) {
  64. return app('json')->fail('数据不存在');
  65. }
  66. if ($data->status == 1) {
  67. $data['login_url'] = rtrim(systemConfig('site_url'), '/') . '/' . config('admin.merchant_prefix');
  68. }
  69. return app('json')->success($data);
  70. }
  71. protected function checkParams()
  72. {
  73. $data = $this->request->params(['phone', 'mer_name', 'name', 'code', 'images', 'merchant_category_id', 'mer_type_id']);
  74. app()->make(MerchantIntentionValidate::class)->check($data);
  75. $check = (YunxinSmsService::create())->checkSmsCode($data['phone'], $data['code'], 'intention');
  76. $data['mer_type_id'] = (int)$data['mer_type_id'];
  77. if (!$check) throw new ValidateException('验证码不正确');
  78. if (!app()->make(MerchantCategoryRepository::class)->get($data['merchant_category_id'])) throw new ValidateException('商户分类不存在');
  79. if ($data['mer_type_id'] && !app()->make(MerchantTypeRepository::class)->exists($data['mer_type_id']))
  80. throw new ValidateException('店铺类型不存在');
  81. unset($data['code']);
  82. return $data;
  83. }
  84. /**
  85. * 商户分类
  86. * @Author:Qinii
  87. * @Date: 2020/9/15
  88. * @return mixed
  89. */
  90. public function cateLst()
  91. {
  92. $lst = app()->make(MerchantCategoryRepository::class)->getSelect();
  93. return app('json')->success($lst);
  94. }
  95. public function typeLst()
  96. {
  97. $lst = app()->make(MerchantTypeRepository::class)->getSelect();
  98. return app('json')->success($lst);
  99. }
  100. }