Files
x-server-mobile/backend/app/model/UserFeishuApp.php
T
root 0489da5e40 refactor: 重构多飞书应用绑定架构和数据库清理
- 新增 user_feishu_apps 表支持用户绑定多个飞书应用
- users 表添加唯一约束(公司内邮箱/手机唯一)
- 迁移现有飞书数据到 user_feishu_apps 表
- 清理冗余表(users_bak, user_feishu_binding)
- 废弃 users 表中的 feishu_user_id/feishu_open_id/tenant_key 字段
- 更新 FeishuNotificationService 使用新的数据获取方式
- User 模型新增 getFeishuUserId() 等便捷方法

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-26 16:27:33 +08:00

79 lines
1.6 KiB
PHP

<?php
namespace app\model;
use support\Model;
/**
* 用户飞书应用绑定模型
*/
class UserFeishuApp extends Model
{
protected $table = 'user_feishu_apps';
protected $fillable = [
'user_id',
'company_id',
'feishu_app_id',
'feishu_user_id',
'feishu_open_id',
'tenant_key',
'is_default',
'last_login_at',
];
protected $casts = [
'user_id' => 'integer',
'company_id' => 'integer',
'feishu_app_id' => 'integer',
'is_default' => 'boolean',
'last_login_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
/**
* 关联用户
*/
public function user()
{
return $this->belongsTo(User::class, 'user_id');
}
/**
* 关联公司
*/
public function company()
{
return $this->belongsTo(Company::class, 'company_id');
}
/**
* 关联飞书应用配置
*/
public function feishuApp()
{
return $this->belongsTo(CompanyFeishuApp::class, 'feishu_app_id');
}
/**
* 获取启用的绑定
*/
public function scopeActive($query)
{
return $query->whereHas('feishuApp', function ($q) {
$q->where('status', 1);
});
}
/**
* 获取用户在某公司的默认应用
*/
public function scopeDefaultApp($query, int $userId, int $companyId)
{
return $query->where('user_id', $userId)
->where('company_id', $companyId)
->where('is_default', 1);
}
}