|
|
@@ -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()
|
|
|
{
|