AuthenticateFrontend.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/10/19
  8. * Time: 15:00
  9. */
  10. namespace app\common\middleware;
  11. use app\common\exceptions\ShopException;
  12. use app\common\exceptions\UniAccountNotFoundException;
  13. use app\common\helpers\Client;
  14. use app\common\helpers\Url;
  15. use app\common\models\Member;
  16. use app\common\modules\shop\models\Shop;
  17. use app\common\traits\JsonTrait;
  18. use app\frontend\modules\member\services\factory\MemberFactory;
  19. use Closure;
  20. class AuthenticateFrontend
  21. {
  22. use JsonTrait;
  23. public function handle($request, Closure $next)
  24. {
  25. if (empty(\YunShop::app()->account)) {
  26. throw new UniAccountNotFoundException('无此公众号', ['login_status' => -2]);
  27. }
  28. $mid = Member::getMid();
  29. $type = request()->input('type');
  30. $relation_status = Shop::current()->memberRelation['status'];
  31. $memberService = MemberFactory::create($type);
  32. $is_login = $memberService->checkLogged();
  33. \Log::info('is_login='.$is_login);
  34. //登录状态
  35. if ($is_login) {
  36. if (\app\frontend\models\Member::current()->yzMember->is_black) {
  37. return $this->errorJson('黑名单用户,请联系管理员', ['login_status' => -1]);
  38. }
  39. //发展下线
  40. Member::chkAgent(\YunShop::app()->getMemberId(), $mid);
  41. } else {
  42. $method = request()->route()->getActionMethod();
  43. $controller = $request->route()->getController();
  44. //验证是否需要登录
  45. if (($relation_status == 1 && !in_array($method, $controller->getIgnoreAction()))
  46. || ($relation_status == 0 && !in_array($method, $controller->getPublicAction()))
  47. ) {
  48. $this->jumpUrl($type, $mid);
  49. }
  50. }
  51. return $next($request);
  52. }
  53. /**
  54. * @param $type
  55. * @param $mid
  56. * @return bool|\Illuminate\Http\JsonResponse
  57. */
  58. protected function jumpUrl($type, $mid)
  59. {
  60. if (empty($type) || $type == 'undefined') {
  61. $type = Client::getType();
  62. }
  63. $scope = request()->input('scope', '');
  64. $queryString = ['type' => $type, 'i' => \YunShop::app()->uniacid, 'mid' => $mid, 'scope' => $scope];
  65. if (($scope == 'home' && !$mid) || $scope == 'pass') {
  66. return true;
  67. }
  68. if (in_array($type, [MemberFactory::LOGIN_MINI_APP, MemberFactory::LOGIN_DOUYIN, MemberFactory::LOGIN_MINI_APP_FACE])) {
  69. return $this->errorJson('请登录', ['login_status' => 0, 'login_url' => Url::absoluteApi('member.login.index', $queryString)]);
  70. }
  71. if (in_array($type, [MemberFactory::LOGIN_MOBILE, MemberFactory::LOGIN_APP_YDB, MemberFactory::LOGIN_Native, MemberFactory::LOGIN_APP_ANCHOR, MemberFactory::LOGIN_APP_LSP_WALLET])) {
  72. return $this->errorJson('请登录', ['login_status' => 1, 'login_url' => '', 'type' => $type, 'i' => \YunShop::app()->uniacid, 'mid' => $mid, 'scope' => $scope]);
  73. }
  74. return $this->errorJson('请登录', ['login_status' => 0, 'login_url' => Url::absoluteApi('member.login.index', $queryString)]);
  75. }
  76. }