SupplierCheckRoleMiddleware.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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\http\middleware\supplier;
  12. use app\Request;
  13. use app\services\supplier\LoginServices;
  14. use crmeb\exceptions\AuthException;
  15. use crmeb\interfaces\MiddlewareInterface;
  16. use crmeb\utils\ApiErrorCode;
  17. /**
  18. * 权限规则验证
  19. * Class SupplierCheckRoleMiddleware
  20. * @package app\http\middleware\supplier
  21. */
  22. class SupplierCheckRoleMiddleware implements MiddlewareInterface
  23. {
  24. public function handle(Request $request, \Closure $next)
  25. {
  26. if (!$request->supplierId() || !$request->supplierInfo())
  27. throw new AuthException(ApiErrorCode::ERR_ADMINID_VOID);
  28. if ($request->supplierInfo()['level'] ?? 0) {
  29. /** @var LoginServices $services */
  30. $services = app()->make(LoginServices::class);
  31. $services->verifiAuth($request);
  32. }
  33. return $next($request);
  34. }
  35. }