Explorar o código

没有管理店铺不允许登录

shish %!s(int64=4) %!d(string=hai) anos
pai
achega
f1a9145a0a
Modificáronse 1 ficheiros con 34 adicións e 60 borrados
  1. 34 60
      app-ghs/controllers/AuthController.php

+ 34 - 60
app-ghs/controllers/AuthController.php

@@ -272,74 +272,48 @@ class AuthController extends PublicController
         //供应商平台
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
         $code = Yii::$app->request->get('code', '');
-        if (empty($code)) {
-            $experienceCode = Yii::$app->request->get('experienceCode', '');
-
-            if (getenv('YII_ENV') == 'production') {
-                $code = '1988';
-            } else {
-                $code = '1964';
-            }
-
-            if ($experienceCode != $code) {
-                util::fail('验证码错误');
-            }
-            $demoId = getenv('GHS_DEMO_ADMIN_ID');
-            $demoId = $demoId === false ? 4 : $demoId;
-            $admin = AdminClass::getById($demoId);
-            if (empty($admin)) {
-                util::fail('没有演示权限');
-            }
-        } else {
-            $wxMiniBase = WxOpenClass::getGhsWxInfo();
-            $appId = $wxMiniBase['miniAppId'];
-            $appSecret = $wxMiniBase['miniAppSecret'];
-            if (empty($appSecret)) {
-                util::fail('没有找到小程序的密钥');
-            }
-            $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
-            $curl = new curl\Curl();
-            $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
-            $result = $curl->get($url);
-            $arr = Json::decode($result);
-            $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
-            $openid = $arr['openid'] ?? '';
-            $unionId = $arr['unionid'] ?? '';
-            if (empty($openid)) {
-                Yii::info(json_encode($arr));
-                util::fail('没有获取到小程序openId');
-            }
-            $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
-            Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-            //用户来源
-            $userSource = UserClass::$userSourceId['mini']['name'];
-            $admin = AdminService::getByMiniOpenId($openid);
+        $wxMiniBase = WxOpenClass::getGhsWxInfo();
+        $appId = $wxMiniBase['miniAppId'];
+        $appSecret = $wxMiniBase['miniAppSecret'];
+        if (empty($appSecret)) {
+            util::fail('没有找到小程序的密钥');
+        }
+        $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appId}&secret={$appSecret}&js_code={$code}&grant_type=authorization_code";
+        $curl = new curl\Curl();
+        $curl->setOption(CURLOPT_SSL_VERIFYPEER, false);
+        $result = $curl->get($url);
+        $arr = Json::decode($result);
+        $sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
+        $openid = $arr['openid'] ?? '';
+        if (empty($openid)) {
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
         }
+        $cacheKey = 'GHS_SHOP_MINI_SESSION_KEY_' . $openid;
+        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+        $admin = AdminService::getByMiniOpenId($openid);
         if (empty($admin)) {
-            $adminInfo = [
-                'miniOpenId' => $openid,
-                'unionId' => $unionId
-            ];
-            $admin = AdminService::replaceAdmin($adminInfo, $userSource);
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
         }
         $adminId = $admin['id'];
         //1没有开店 2已申请待审核 3已开店
         $openShop = $admin['openShop'] ?? 1;
         $currentShopId = $admin['currentShopId'] ?? 0;
-        //员工id
-        $shopAdminId = 0;
-        $switchShop = 0;
-        if (!empty($currentShopId)) {
-            $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
-            if (empty($shopAdmin)) {
-                util::fail('没有找到员工哦');
-            }
-            $shopAdmin->lastLogin = date("Y-m-d H:i:s");
-            $shopAdmin->save();
-            $shopAdminId = $shopAdmin->id ?? 0;
-            //是否有切换门店的权限
-            $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        if (empty($currentShopId)) {
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
+        }
+        $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
+        if (empty($shopAdmin)) {
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
         }
+        $shopAdmin->lastLogin = date("Y-m-d H:i:s");
+        $shopAdmin->save();
+        $shopAdminId = $shopAdmin->id ?? 0;
+        //是否有切换门店的权限
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
         $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
         $token = jwt::getNewToken($adminId);
         $showDemo = 1;