shish 3 жил өмнө
parent
commit
923bc2b422

+ 44 - 8
app-hd/controllers/AuthController.php

@@ -451,7 +451,7 @@ class AuthController extends PublicController
         if (empty($password)) {
             util::fail('请输入密码');
         }
-        $admin = AdminService::getByCondition(['mobile' => $mobile, 'style' => AdminClass::STYLE_HD]);
+        $admin = AdminService::getByCondition(['mobile' => $mobile]);
         if (empty($admin)) {
             util::fail('请先注册哦');
         }
@@ -459,15 +459,51 @@ class AuthController extends PublicController
             util::fail('密码错误');
         }
         $adminId = $admin['id'];
-        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'delStatus' => 0]);
-        $sjId = isset($shopAdmin['sjId']) ? $shopAdmin['sjId'] : 0;
-        $shopId = $shopAdmin['shopId'] ?? 0;
-        if (empty($shopId)) {
-            util::fail('您不是管理员');
+        $openShop = $admin['openShop'] ?? 1;
+        $currentShopId = $admin['currentShopId'] ?? 0;
+        if (empty($currentShopId)) {
+            if ($openShop == 2) {
+                util::fail('审核中');
+            }
+            util::fail('请先注册');
         }
-        //获取token
+        $currentShop = ShopClass::getById($currentShopId, true);
+        if (empty($currentShop)) {
+            util::fail('没有找到门店');
+        }
+        $pfShopId = $currentShop->pfShopId ?? 0;
+        if (!empty($pfShopId)) {
+            util::fail('批发店请不要在零售端登录');
+        }
+        $sjId = $currentShop->sjId ?? 0;
+        $mainId = $currentShop->mainId ?? 0;
+        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
+        if (empty($shopAdmin)) {
+            util::fail('没有权限操作');
+        }
+        if ($shopAdmin->status == 0) {
+            util::fail("您的账号已被冻结");
+        }
+
         $token = jwt::getNewToken($adminId);
-        util::success(['token' => $token, 'account' => $sjId, 'shopId' => $shopId]);
+        $shopAdmin->lastLogin = date("Y-m-d H:i:s");
+        $shopAdmin->save();
+
+        //是否有切换门店的权限
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
+        $prefix = imgUtil::getPrefix();
+        $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
+        $admin['avatar'] = $avatar;
+
+        $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
+        if ($hdUpgrading == 1) {
+            util::fail('系统升级中,稍后再试');
+        }
+
+        $apiHost = Yii::$app->params['hdHost'];
+        $imgUploadApi = $apiHost . '/upload/save-file';
+
+        util::success(['token' => $token, 'account' => $sjId, 'shopId' => $currentShopId, 'imgUploadApi' => $imgUploadApi, 'switchShop' => $switchShop,]);
     }
 
     //静默获取小程序用户信息