MerchantCheckBaseInfoMiddleware.php 1.4 KB

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