|
|
@@ -2,6 +2,7 @@
|
|
|
|
|
|
namespace shop\controllers;
|
|
|
|
|
|
+use biz\admin\services\AdminRelateService;
|
|
|
use biz\admin\services\AdminService;
|
|
|
use biz\auth\services\AuthService;
|
|
|
use biz\user\classes\UserClass;
|
|
|
@@ -157,7 +158,7 @@ class AuthController extends PublicController
|
|
|
$token = jwt::getNewToken($adminId);
|
|
|
util::success(['token' => $token, 'account' => $admin['merchantId'], 'merchantId' => $admin['merchantId']]);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
//静默获取小程序用户信息
|
|
|
public function actionMiniInfo()
|
|
|
{
|
|
|
@@ -176,6 +177,8 @@ class AuthController extends PublicController
|
|
|
$result = $curl->get($url);
|
|
|
$arr = Json::decode($result);
|
|
|
$sessionKey = isset($arr['session_key']) ? $arr['session_key'] : '';
|
|
|
+ $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
|
|
|
+ Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
|
|
|
$openid = isset($arr['openid']) ? $arr['openid'] : '';
|
|
|
if (empty($openid)) {
|
|
|
Yii::info(json_encode($arr));
|
|
|
@@ -184,15 +187,20 @@ class AuthController extends PublicController
|
|
|
//用户来源
|
|
|
$userSource = UserClass::$userSourceId['mini']['name'];
|
|
|
$admin = AdminService::getByMiniOpenId($openid);
|
|
|
+ $relateId = 0;
|
|
|
if (empty($admin)) {
|
|
|
$adminInfo = ['miniOpenId' => $openid];
|
|
|
Yii::info(json_encode($adminInfo));
|
|
|
$admin = AdminService::replaceAdmin($adminInfo, $userSource);
|
|
|
+ $adminId = $admin['id'];
|
|
|
+ } else {
|
|
|
+ $adminId = $admin['id'];
|
|
|
+ $relate = AdminRelateService::getByCondition(['adminId' => $adminId]);
|
|
|
+ $relateId = isset($relate['id']) ? $relate['id'] : 0;
|
|
|
}
|
|
|
- $cacheKey = 'SHOP_MINI_SESSION_KEY_' . $openid;
|
|
|
- Yii::$app->redis->executeCommand('SET', [$cacheKey, $sessionKey]);
|
|
|
- $userId = $admin['id'];
|
|
|
- $token = jwt::getNewToken($userId);
|
|
|
+ //管理员关联商家
|
|
|
+ Yii::$app->redis->executeCommand('SET', ['ADMIN_RELATION_' . $adminId, $relateId]);
|
|
|
+ $token = jwt::getNewToken($adminId);
|
|
|
util::success(['token' => $token, 'admin' => $admin]);
|
|
|
}
|
|
|
|