shish пре 4 дана
родитељ
комит
f044a4e0a1
2 измењених фајлова са 247 додато и 0 уклоњено
  1. 131 0
      app-ghs/controllers/AuthController.php
  2. 116 0
      app-hd/controllers/AuthController.php

+ 131 - 0
app-ghs/controllers/AuthController.php

@@ -30,6 +30,137 @@ use yii\helpers\Json;
 class AuthController extends PublicController
 {
 
+    //小程序获取手机号并登录 (新接口) ssh 20250728
+    public function actionGetMiniMobile()
+    {
+        $post = Yii::$app->request->post();
+        $code = $post['code'] ?? '';
+        $miniOpenId = $post['miniOpenId'] ?? '';
+        if (empty($code)) {
+            util::fail('参数错误:缺少code');
+        }
+
+        // 使用 miniUtil 封装好的方法获取手机号 (ptStyle=2 表示供货商端)
+        $merchant = WxOpenClass::getGhsWxInfo();
+        $res = \common\components\miniUtil::getPhoneNumber($merchant, $code, 2);
+
+        if (isset($res['errcode']) && $res['errcode'] == 0) {
+            $phoneNumber = $res['phone_info']['purePhoneNumber'] ?? '';
+            if (empty($phoneNumber)) {
+                util::fail('获取手机号内容为空');
+            }
+
+            // 登录逻辑 (同步自 actionWxMobileLogin)
+            $admin = AdminClass::getByCondition(['mobile' => $phoneNumber]);
+            if (empty($admin)) {
+                util::fail('请先注册或请店长添加自己为员工');
+            }
+            $currentShopId = $admin['currentGhsShopId'] ?? 0;
+            $openShop = $admin['openGhsShop'] ?? 1;
+            if (empty($currentShopId)) {
+                if ($openShop == 2) {
+                    util::fail('审核中');
+                }
+                util::fail('请先注册..');
+            }
+            $currentShop = ShopClass::getById($currentShopId, true);
+            if (empty($currentShop)) {
+                util::fail('没有找到门店69');
+            }
+            $mainId = $currentShop->mainId ?? 0;
+            $adminId = $admin['id'] ?? 0;
+            if (isset($admin['ghsMiniOpenId']) && empty($admin['ghsMiniOpenId'])) {
+                AdminClass::updateById($adminId, ['ghsMiniOpenId' => $miniOpenId]);
+            }
+            $admin['miniOpenId'] = $miniOpenId;
+            //1没有开店 2已申请待审核 3已开店
+            $openShop = $admin['openGhsShop'] ?? 1;
+            if ($openShop == 2) {
+                util::fail('帐号审核中');
+            }
+            $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], 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);
+
+            $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
+            $token = jwt::getNewToken($adminId);
+            $showDemo = 1;
+            $remind = getenv('GHS_UPDATE_REMIND') == false ? 0 : getenv('GHS_UPDATE_REMIND');
+            $shop = ShopClass::getById($currentShopId, true);
+            $skCustomId = $shop->skCustomId ?? 0;
+            $apiHost = Yii::$app->params['ghsHost'];
+            $imgUploadApi = $apiHost . '/upload/save-file';
+
+            //使用手册
+            $cacheKey = 'close_book_' . $shopAdminId;
+            $hasClose = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+            $showBook = !empty($hasClose) ? 0 : 1;
+
+            $cacheKey = 'has_hit_navigate_' . $shopAdminId;
+            $hasHit = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+            $hasHitNavigate = !empty($hasHit) ? 1 : 0;
+
+            $ghsUpgrading = getenv('GHS_UPGRADING') == false ? 0 : getenv('GHS_UPGRADING');
+            if ($ghsUpgrading == 1) {
+                $allowShopAdminIdsStr = getenv('GHS_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
+                $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
+                if (!in_array($shopAdminId, $allowShopAdminIds)) {
+                    util::fail('系统升级中,稍后再试');
+                }
+            }
+
+            $lookAllShop = 0;
+            if (getenv('YII_ENV') == 'production') {
+                $couldLookAllShop = dict::getDict('couldLookAllShop');
+                if (in_array($adminId, $couldLookAllShop)) {
+                    $lookAllShop = 1;
+                }
+            } else {
+                $lookAllShop = 1;
+            }
+
+            //惠雅鲜花员工不能看收入情况
+            if (in_array($adminId, [2366, 2812, 4004])) {
+                $shopAdmin->super = 0;
+            }
+
+            $labelList = LabelClass::getMyUnUseLabelList($mainId);
+
+            //注意这里的输出内容有多个地方一样,要修改需要同步修改,请搜索关键词loginOK!!!!!!!!
+            util::success([
+                'token' => $token,
+                'admin' => $admin,
+                'shopAdminId' => $shopAdminId,
+                'shopId' => $currentShopId,
+                'switchShop' => $switchShop,
+                'openShop' => $openShop,
+                'showDemo' => $showDemo,
+                //有小程序新版本提示更新
+                'update' => $remind,
+                'skCustomId' => $skCustomId,
+                'apiHost' => $apiHost,
+                'imgUploadApi' => $imgUploadApi,
+                'showBook' => $showBook,
+                'hasHitNavigate' => $hasHitNavigate,
+                'staff' => $shopAdmin,
+                'lookAllShop' => $lookAllShop,
+                'labelList' => $labelList,
+            ]);
+        } else {
+            $errMsg = $res['errmsg'] ?? '获取手机号失败';
+            $errCode = $res['errcode'] ?? -1;
+            Yii::info("小程序新接口获取手机号失败 (GHS):code={$errCode}, msg={$errMsg}");
+            noticeUtil::push("供货商小程序新接口获取手机号失败:code={$errCode}, msg={$errMsg}", '15280215347');
+            util::fail("获取手机号失败:{$errMsg}({$errCode})");
+        }
+    }
+
     //获取手机号
     public function actionGetMobile()
     {

+ 116 - 0
app-hd/controllers/AuthController.php

@@ -33,6 +33,122 @@ use yii\helpers\Json;
 class AuthController extends PublicController
 {
 
+    //小程序获取手机号并登录 (新接口) ssh 20250728
+    public function actionGetMiniMobile()
+    {
+        $post = Yii::$app->request->post();
+        $code = $post['code'] ?? '';
+        $miniOpenId = $post['miniOpenId'] ?? '';
+        if (empty($code)) {
+            util::fail('参数错误:缺少code');
+        }
+
+        // 使用 miniUtil 封装好的方法获取手机号 (ptStyle=1 表示花店端)
+        $merchant = WxOpenService::getWxMiniBase();
+        $res = \common\components\miniUtil::getPhoneNumber($merchant, $code, 1);
+
+        if (isset($res['errcode']) && $res['errcode'] == 0) {
+            $phoneNumber = $res['phone_info']['purePhoneNumber'] ?? '';
+            if (empty($phoneNumber)) {
+                util::fail('获取手机号内容为空');
+            }
+
+            // 登录逻辑 (同步自 actionWxMobileLogin)
+            $admin = AdminService::getByCondition(['mobile' => $phoneNumber]);
+            if (empty($admin)) {
+                util::fail('请先注册');
+            }
+            $adminId = $admin['id'];
+            AdminClass::updateById($adminId, ['miniOpenId' => $miniOpenId]);
+            $admin['miniOpenId'] = $miniOpenId;
+            $openShop = $admin['openShop'] ?? 1;
+            $currentShopId = $admin['currentShopId'] ?? 0;
+            if (empty($currentShopId)) {
+                if ($openShop == 2) {
+                    util::fail('审核中');
+                }
+                util::fail('请先注册');
+            }
+            $currentShop = ShopClass::getById($currentShopId, true);
+            if (empty($currentShop)) {
+                util::fail('没有找到门店36');
+            }
+            $pfShopId = $currentShop->pfShopId ?? 0;
+            $onlyCg = $currentShop->onlyCg ?? 1;
+            $mainId = $currentShop->mainId ?? 0;
+
+            $shareLogo = imgUtil::groupImg('buy_logo.jpg');
+            if (isset($currentShop->shareLogo) && !empty($currentShop->shareLogo)) {
+                $shareLogo = imgUtil::groupImg($currentShop->shareLogo);
+            }
+
+            $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
+            if (empty($shopAdmin)) {
+                util::fail('无法操作');
+            }
+            if ($shopAdmin->status == 0) {
+                util::fail("您的账号已被冻结");
+            }
+            $token = jwt::getNewToken($adminId);
+            $shopAdmin->lastLogin = date("Y-m-d H:i:s");
+            $shopAdmin->save();
+            $shopAdminId = $shopAdmin->id ?? 0;
+
+            //是否有切换门店的权限
+            $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;
+            $showDemo = 1;
+            $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
+
+            $hdUpgrading = getenv('HD_UPGRADING') == false ? 0 : getenv('HD_UPGRADING');
+            if ($hdUpgrading == 1) {
+                $allowShopAdminIdsStr = getenv('HD_UPGRADE_ALLOW_SHOP_ADMIN_IDS') ?: '';
+                $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : [];
+                if (!in_array($shopAdminId, $allowShopAdminIds)) {
+                    util::fail('系统升级中,稍后再试');
+                }
+            }
+
+            $apiHost = Yii::$app->params['hdHost'];
+            $imgUploadApi = $apiHost . '/upload/save-file';
+
+            //惠雅鲜花员工不能看收入情况
+            if (in_array($adminId, [2366, 2812, 4004])) {
+                $shopAdmin->super = 0;
+            }
+
+            //充值送钱有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词recharge_sq_init ssh 20251229
+            RechargeSqClass::initData($currentShop);
+            //会员等级有没设置,没有设置则进行设置,临时方法,后面需要去掉,有多处,关键词member_level_init ssh 20251229
+            MemberLevelClass::initData($currentShop);
+
+            //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
+            util::success([
+                'token' => $token,
+                'admin' => $admin,
+                'shopId' => $currentShopId,
+                'shopAdminId' => $shopAdminId,
+                'switchShop' => $switchShop,
+                'pfShopId' => $pfShopId,
+                'onlyCg' => $onlyCg,
+                'shareLogo' => $shareLogo,
+                'showDemo' => $showDemo,
+                'imgUploadApi' => $imgUploadApi,
+                //有小程序新版本提示更新
+                'update' => $remind,
+                'staff' => $shopAdmin,
+            ]);
+        } else {
+            $errMsg = $res['errmsg'] ?? '获取手机号失败';
+            $errCode = $res['errcode'] ?? -1;
+            Yii::info("小程序新接口获取手机号失败 (HD):code={$errCode}, msg={$errMsg}");
+            noticeUtil::push("花店小程序新接口获取手机号失败:code={$errCode}, msg={$errMsg}", '15280215347');
+            util::fail("获取手机号失败:{$errMsg}({$errCode})");
+        }
+    }
+
     //获取手机号 ssh 20250217
     public function actionGetMobile()
     {