MerchantCheckBaseInfoMiddleware.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\common\middleware;
  12. use app\Request;
  13. use think\exception\ValidateException;
  14. use think\facade\Cache;
  15. use think\Response;
  16. class MerchantCheckBaseInfoMiddleware extends BaseMiddleware
  17. {
  18. protected $rules = [
  19. 'merchantAttachmentCategoryCreate',
  20. 'merchantUpdate',
  21. 'merchantUploadImage',
  22. 'merchantAttachmentCategoryUpdate',
  23. 'merchantAttachmentCategoryDelete',
  24. 'merchantAttachmentUpdate',
  25. 'merchantAttachmentDelete'
  26. ];
  27. public function before(Request $request)
  28. {
  29. if ($this->request->method() == 'GET' || in_array($this->request->rule()->getName(), $this->rules)) return;
  30. $cache = Cache::store('file');
  31. $merchant = $request->merchant();
  32. $key = 'mer_valid_' . $merchant->mer_id;
  33. if ($cache->has($key)) return;
  34. if (!$merchant->mer_avatar || !$merchant->mer_banner || !$merchant->mer_info || !$merchant->service_phone || !$merchant->mer_address) {
  35. throw new ValidateException('您好,请前往左侧菜单【设置】-【商户基本信息】完善商户基本信息。');
  36. }
  37. Cache::store('file')->set('mer_valid_' . $merchant->mer_id, 1, 3600 * 8);
  38. }
  39. public function after(Response $response)
  40. {
  41. // TODO: Implement after() method.
  42. }
  43. }