MerchantIntention.php 4.1 KB

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