Kaynağa Gözat

花店端优化

shish 4 yıl önce
ebeveyn
işleme
2da42af626
1 değiştirilmiş dosya ile 42 ekleme ve 63 silme
  1. 42 63
      app-hd/controllers/AuthController.php

+ 42 - 63
app-hd/controllers/AuthController.php

@@ -175,71 +175,50 @@ class AuthController extends PublicController
     {
         //花店平台
         Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
-
         $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('HD_DEMO_ADMIN_ID');
-            $demoId = $demoId === false ? 3 : $demoId;
-            $admin = AdminClass::getById($demoId);
-            if (empty($admin)) {
-                util::fail('没有演示权限');
-            }
-        } else {
-            $wxMiniBase = WxOpenService::getWxMiniBase();
-            $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'] ?? '';
-            $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
-            Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
-            if (empty($openid)) {
-                Yii::info(json_encode($arr));
-                util::fail('没有获取到小程序openId');
-            }
-            //用户来源
-            $userSource = UserClass::$userSourceId['mini']['name'];
-            $admin = AdminService::getByMiniOpenId($openid);
-            if (empty($admin)) {
-                $adminInfo = ['miniOpenId' => $openid, 'style' => 1, 'unionId' => $unionId];
-                $admin = AdminService::replaceAdmin($adminInfo, $userSource);
-            }
+        $wxMiniBase = WxOpenService::getWxMiniBase();
+        $appId = $wxMiniBase['miniAppId'];
+        $appSecret = $wxMiniBase['miniAppSecret'];
+        if (empty($appSecret)) {
+            Yii::info('没有找到小程序的密钥');
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
+        }
+        $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'] ?? '';
+        $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
+        Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
+        if (empty($openid)) {
+            Yii::info(json_encode($arr));
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
+        }
+        $admin = AdminService::getByMiniOpenId($openid);
+        if (empty($admin)) {
+            //没有管理店铺不允许登录
+            util::success(['token' => '']);
         }
         $adminId = $admin['id'];
-        $shopId = $admin['currentShopId'] ?? 0;
-        $shopAdminId = 0;
-        $switchShop = 0;
-        if (!empty($shopId)) {
-            $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $shopId, 'adminId' => $adminId], true);
-            if (empty($shopAdmin)) {
-                util::fail("没有员工信息哦(adminId:{$adminId} shopId:{$shopId})");
-            }
-            $shopAdmin->lastLogin = date("Y-m-d H:i:s");
-            $shopAdmin->save();
-            $shopAdminId = $shopAdmin->id ?? 0;
-            //是否有切换门店的权限
-            $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
-        }
-        //头像
+        $currentShopId = $admin['currentShopId'] ?? 0;
+        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);
         $prefix = imgUtil::getPrefix();
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;
@@ -249,7 +228,7 @@ class AuthController extends PublicController
         util::success([
             'token' => $token,
             'admin' => $admin,
-            'shopId' => $shopId,
+            'shopId' => $currentShopId,
             'shopAdminId' => $shopAdminId,
             'switchShop' => $switchShop,
             'showDemo' => $showDemo,