Files
x-server-mobile/backend/app/model/UserFeishuApp.php
T

79 lines
1.6 KiB
PHP
Raw Normal View History

<?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);
}
}