MerchantCheckBaseInfoMiddleware.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 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. 'merchant.Common/uploadCertificate',
  23. 'merchantAttachmentCategoryUpdate',
  24. 'merchantAttachmentCategoryDelete',
  25. 'merchantAttachmentUpdate',
  26. 'merchantAttachmentDelete'
  27. ];
  28. public function before(Request $request)
  29. {
  30. $name = $this->request->rule()->getName();
  31. if ($this->request->method() == 'GET' || in_array($name, $this->rules)) return;
  32. $cache = Cache::store('file');
  33. $merchant = $request->merchant();
  34. $key = 'mer_valid_' . $merchant->mer_id;
  35. if ($cache->has($key)) return;
  36. if (!$merchant->mer_avatar || !$merchant->mer_banner || !$merchant->mer_info || !$merchant->service_phone || !$merchant->mer_address) {
  37. throw new ValidateException('您好,请前往左侧菜单【设置】-【商户基本信息】完善商户基本信息。');
  38. }
  39. Cache::store('file')->set('mer_valid_' . $merchant->mer_id, 1, 3600 * 8);
  40. }
  41. public function after(Response $response)
  42. {
  43. // TODO: Implement after() method.
  44. }
  45. }