refactor: 删除 users 表中的冗余飞书字段
- 删除 feishu_user_id, feishu_open_id, tenant_key 字段 - JWT token 改用 feishu_app_id 代替 feishu_user_id - 删除废弃的 FeishuService::sendApprovalMessage() 方法 - 更新 User 模型移除废弃字段和 scope 方法 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -131,7 +131,7 @@ class AuthController extends BaseController
|
||||
$token = JwtUtil::encode([
|
||||
'user_id' => $user->id,
|
||||
'company_id' => $user->company_id,
|
||||
'feishu_user_id' => $user->feishu_user_id,
|
||||
'feishu_app_id' => $user->feishu_app_id,
|
||||
'union_id' => $user->union_id,
|
||||
]);
|
||||
|
||||
|
||||
@@ -10,11 +10,6 @@ class User extends Model
|
||||
|
||||
/**
|
||||
* 可填充字段
|
||||
*
|
||||
* 注意:以下字段已废弃,保留仅用于向后兼容
|
||||
* @deprecated feishu_user_id - 请使用 UserFeishuApp 模型获取
|
||||
* @deprecated feishu_open_id - 请使用 UserFeishuApp 模型获取
|
||||
* @deprecated tenant_key - 请使用 UserFeishuApp 模型获取
|
||||
*/
|
||||
protected $fillable = [
|
||||
'company_id',
|
||||
@@ -28,13 +23,8 @@ class User extends Model
|
||||
'password',
|
||||
'status',
|
||||
'user_type',
|
||||
'union_id',
|
||||
// 废弃字段 - 请使用 UserFeishuApp 模型
|
||||
'feishu_user_id', // @deprecated
|
||||
'feishu_open_id', // @deprecated
|
||||
'tenant_key', // @deprecated
|
||||
// 保留字段:记录最后登录的应用,用于快速获取默认应用
|
||||
'feishu_app_id',
|
||||
'union_id', // 飞书 UnionID - 用于跨应用识别用户
|
||||
'feishu_app_id', // 最后登录的飞书应用ID - 用于快速获取默认应用
|
||||
'position',
|
||||
'sign_img',
|
||||
];
|
||||
@@ -149,21 +139,9 @@ class User extends Model
|
||||
return $query->where('company_id', $companyId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据飞书用户ID查找
|
||||
* @deprecated 请通过 UserFeishuApp 模型查询
|
||||
*/
|
||||
public function scopeByFeishuUserId($query, ?string $feishuUserId)
|
||||
{
|
||||
if ($feishuUserId === null) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('feishu_user_id', $feishuUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据飞书 UnionID 查找
|
||||
* union_id 用于跨应用识别用户,保留此方法
|
||||
* union_id 用于跨应用识别用户
|
||||
*/
|
||||
public function scopeByFeishuUnionId($query, ?string $feishuUnionId)
|
||||
{
|
||||
@@ -173,18 +151,6 @@ class User extends Model
|
||||
return $query->where('union_id', $feishuUnionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据OpenID查找
|
||||
* @deprecated 请通过 UserFeishuApp 模型查询
|
||||
*/
|
||||
public function scopeByFeishuOpenId($query, ?string $openId)
|
||||
{
|
||||
if ($openId === null) {
|
||||
return $query;
|
||||
}
|
||||
return $query->where('feishu_open_id', $openId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索用户
|
||||
*/
|
||||
|
||||
@@ -230,76 +230,4 @@ class FeishuService
|
||||
error_log("✨ 创建飞书绑定: user_id={$userId}, app_id={$appId}, feishu_user_id={$feishuUserId}");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送审批消息通知
|
||||
* @deprecated 请使用 FeishuNotificationService::sendApprovalNotification() 代替
|
||||
*/
|
||||
public function sendApprovalMessage(int $userId, string $title, string $url): bool
|
||||
{
|
||||
try {
|
||||
$user = User::findOrFail($userId);
|
||||
$company = Company::findOrFail($user->company_id);
|
||||
|
||||
$this->setCompany($company->id);
|
||||
$token = $this->getAccessToken();
|
||||
|
||||
// 构建消息内容
|
||||
$message = [
|
||||
'msg_type' => 'interactive',
|
||||
'card' => [
|
||||
'header' => [
|
||||
'title' => [
|
||||
'content' => '审批通知',
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'template' => 'blue',
|
||||
],
|
||||
'elements' => [
|
||||
[
|
||||
'tag' => 'div',
|
||||
'text' => [
|
||||
'content' => $title,
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
],
|
||||
[
|
||||
'tag' => 'action',
|
||||
'actions' => [
|
||||
[
|
||||
'tag' => 'button',
|
||||
'text' => [
|
||||
'content' => '查看详情',
|
||||
'tag' => 'plain_text',
|
||||
],
|
||||
'type' => 'default',
|
||||
'url' => $url,
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// 发送消息
|
||||
$response = HttpClient::httpPost(
|
||||
"https://open.feishu.cn/open-apis/message/v4/send_messages",
|
||||
[
|
||||
'receive_id_type' => 'user_id',
|
||||
'receive_id' => $user->feishu_user_id,
|
||||
'msg_type' => 'interactive',
|
||||
'content' => json_encode(['card' => $message['card']]),
|
||||
],
|
||||
[
|
||||
'Authorization: Bearer ' . $token,
|
||||
]
|
||||
);
|
||||
|
||||
return ($response['code'] ?? -1) === 0;
|
||||
} catch (Exception $e) {
|
||||
// 记录错误但不中断流程
|
||||
error_log('发送飞书消息失败: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
-- X-Server 删除 users 表中的冗余飞书字段
|
||||
-- 这些字段的数据已迁移至 user_feishu_apps 表
|
||||
|
||||
USE xserver;
|
||||
|
||||
-- =====================================
|
||||
-- 删除冗余的飞书字段
|
||||
-- =====================================
|
||||
|
||||
-- 删除 feishu_user_id
|
||||
ALTER TABLE users DROP COLUMN feishu_user_id;
|
||||
|
||||
-- 删除 feishu_open_id
|
||||
ALTER TABLE users DROP COLUMN feishu_open_id;
|
||||
|
||||
-- 删除 tenant_key
|
||||
ALTER TABLE users DROP COLUMN tenant_key;
|
||||
|
||||
-- =====================================
|
||||
-- 验证结果
|
||||
-- =====================================
|
||||
|
||||
SELECT "=== users 表结构验证 ===" as "";
|
||||
DESCRIBE users;
|
||||
|
||||
SELECT "=== user_feishu_apps 表统计 ===" as "";
|
||||
SELECT
|
||||
company_id,
|
||||
COUNT(DISTINCT user_id) as users_count,
|
||||
COUNT(*) as bindings_count
|
||||
FROM user_feishu_apps
|
||||
GROUP BY company_id;
|
||||
Reference in New Issue
Block a user