From 1a54a55653c4c19f669f91cc9f1c77290edcbc91 Mon Sep 17 00:00:00 2001 From: mzl92 Date: Mon, 28 Jul 2025 14:03:15 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9E=E4=B9=A6=E5=A2=9E=E5=8A=A0=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E4=BC=81=E4=B8=9A=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/logic/AuthLogic.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/common/logic/AuthLogic.php b/app/common/logic/AuthLogic.php index e6022f3..754504b 100644 --- a/app/common/logic/AuthLogic.php +++ b/app/common/logic/AuthLogic.php @@ -86,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'], @@ -112,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) {