Merge branch 'develop'
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\common\logic;
|
||||
|
||||
use app\common\model\Corp;
|
||||
use app\common\model\CorpFeishuApp;
|
||||
use app\common\model\Resource;
|
||||
use app\common\model\UserTokenLog;
|
||||
use app\common\model\Systems;
|
||||
use app\common\model\User;
|
||||
@@ -85,16 +86,23 @@ class AuthLogic
|
||||
{
|
||||
try {
|
||||
$phone = $this->sanitizePhone($feishuUserInfo['mobile'] ?? '');
|
||||
$user = User::where('phone', $phone)->where('corp_id', $feishuUserInfo['corp_id'])->first();
|
||||
$email = $feishuUserInfo['enterprise_email'];
|
||||
$user = User::where('corp_id', $feishuUserInfo['corp_id'])
|
||||
->where(function($query) use ($phone, $email) {
|
||||
$query->where('phone', $phone)
|
||||
->orWhere('email', $email);
|
||||
})
|
||||
->first();
|
||||
|
||||
if (!$user) {
|
||||
// 获取编号
|
||||
$userSn = $this->getAvailableUserSn();
|
||||
// 创建用户
|
||||
$user = User::create([
|
||||
'name' => $feishuUserInfo['en_name'],
|
||||
'name' => $feishuUserInfo['name'],
|
||||
'avatar' => $feishuUserInfo['avatar_middle'],
|
||||
'phone' => $this->sanitizePhone($feishuUserInfo['mobile'] ?? ''),
|
||||
'email' => $feishuUserInfo['enterprise_email'],
|
||||
'union_id' => $feishuUserInfo['union_id'],
|
||||
'user_id' => $feishuUserInfo['user_id'],
|
||||
'open_id' => $feishuUserInfo['open_id'],
|
||||
@@ -111,12 +119,20 @@ class AuthLogic
|
||||
// 是否登陆
|
||||
$user->isLogin = false;
|
||||
} else {
|
||||
$user->update([
|
||||
$updated = [
|
||||
'union_id' => $feishuUserInfo['union_id'],
|
||||
'user_id' => $feishuUserInfo['user_id'],
|
||||
'open_id' => $feishuUserInfo['open_id'],
|
||||
'tenant_key' => $feishuUserInfo['tenant_key']
|
||||
]);
|
||||
];
|
||||
if ($phone && $phone == $user->phone) {
|
||||
$updated['phone'] = $phone;
|
||||
}
|
||||
if ($phone && $phone == $user->phone) {
|
||||
$updated['email'] = $email;
|
||||
}
|
||||
// 更新飞书信息
|
||||
$user->update($updated);
|
||||
}
|
||||
return $user;
|
||||
} catch (\Throwable $e) {
|
||||
@@ -140,6 +156,7 @@ class AuthLogic
|
||||
$payload = $this->buildJwtPayload($user, $system);
|
||||
$token = $this->generateAccessToken($payload);
|
||||
$refreshToken = $this->generateRefreshToken($user->id, $data['system_code']);
|
||||
$homeUrl = $this->getHome($system->id);
|
||||
|
||||
// 记录 token 到 Redis 和 MySQL
|
||||
$this->recordUserToken($user->id, $token, $data['system_code']);
|
||||
@@ -150,7 +167,8 @@ class AuthLogic
|
||||
'expires_in' => config('jwt.jwt_expiration'),
|
||||
'system_code' => $data['system_code'],
|
||||
'corp_abbr' => $data['corp_abbr'],
|
||||
'login_type' => $data['login_type']
|
||||
'login_type' => $data['login_type'],
|
||||
'home_url' => $homeUrl,
|
||||
// 'payload' => $payload,
|
||||
];
|
||||
}
|
||||
@@ -500,4 +518,42 @@ class AuthLogic
|
||||
Redis::del("user_token_meta:{$token}");
|
||||
UserTokenLog::where('token', $token)->update(['is_valid'=>0]);
|
||||
}
|
||||
|
||||
|
||||
public function getHome($systemId)
|
||||
{
|
||||
$info = Resource::where('system_id', $systemId)
|
||||
->where('is_home', 1)
|
||||
->first();
|
||||
|
||||
if (!$info) {
|
||||
return '/dashboard/console';
|
||||
}
|
||||
|
||||
// 递归拼接 URL
|
||||
$url = $this->buildParentUrl($info);
|
||||
|
||||
return $url ?: '/dashboard/console';
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建父级 URL
|
||||
* @param Resource $resource
|
||||
* @return string
|
||||
*/
|
||||
protected function buildParentUrl(Resource $resource)
|
||||
{
|
||||
$url = $resource->url ?? '';
|
||||
|
||||
// 如果存在父级,则递归拼接
|
||||
if ($resource->parent_id != 0) {
|
||||
$parent = Resource::find($resource->parent_id);
|
||||
if ($parent) {
|
||||
$parentUrl = $this->buildParentUrl($parent);
|
||||
$url = $parentUrl . ($url ? '/' . ltrim($url, '/') : '');
|
||||
}
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user