CustomerMiddleware.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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\api;
  12. use app\services\message\service\StoreServiceServices;
  13. use app\services\store\DeliveryServiceServices;
  14. use app\services\store\SystemStoreStaffServices;
  15. use crmeb\interfaces\MiddlewareInterface;
  16. use app\Request;
  17. class CustomerMiddleware implements MiddlewareInterface
  18. {
  19. public function handle(Request $request, \Closure $next)
  20. {
  21. $uid = $request->uid();
  22. /** @var StoreServiceServices $services */
  23. $services = app()->make(StoreServiceServices::class);
  24. /** @var SystemStoreStaffServices $storeServices */
  25. $storeServices = app()->make(SystemStoreStaffServices::class);
  26. $rule = trim(strtolower($request->rule()->getRule()));
  27. /** @var DeliveryServiceServices $deliveryService */
  28. $deliveryService = app()->make(DeliveryServiceServices::class);
  29. $isDelivery = $deliveryService->checkoutIsService($uid);
  30. $withRule = ['/api/order/order_verific', "/api/admin/order/detail/<orderId>"];
  31. if (((!$services->checkoutIsService(['uid' => $uid, 'account_status' => 1, 'customer' => 1]) && !$storeServices->verifyStatus($uid)) && !$isDelivery) && !(in_array($rule, $withRule)))
  32. return app('json')->fail('权限不足');
  33. return $next($request);
  34. }
  35. }