2026-02-25 15:22:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-25 18:09:04 +08:00
|
|
|
namespace app\model;
|
2026-02-25 15:22:12 +08:00
|
|
|
|
2026-02-25 18:15:17 +08:00
|
|
|
use support\Model;
|
2026-02-25 15:22:12 +08:00
|
|
|
|
|
|
|
|
class Company extends Model
|
|
|
|
|
{
|
|
|
|
|
protected $table = 'companies';
|
|
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'abbr',
|
|
|
|
|
'tenant_key',
|
|
|
|
|
'sort',
|
|
|
|
|
'status',
|
|
|
|
|
'feishu_enabled',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'sort' => 'integer',
|
|
|
|
|
'status' => 'integer',
|
|
|
|
|
'feishu_enabled' => 'boolean',
|
|
|
|
|
'created_at' => 'datetime',
|
|
|
|
|
'updated_at' => 'datetime',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取启用的公司
|
|
|
|
|
*/
|
|
|
|
|
public function scopeActive($query)
|
|
|
|
|
{
|
|
|
|
|
return $query->where('status', 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 tenant_key 查找
|
|
|
|
|
*/
|
|
|
|
|
public function scopeByTenantKey($query, ?string $tenantKey)
|
|
|
|
|
{
|
|
|
|
|
if ($tenantKey === null) {
|
|
|
|
|
return $query;
|
|
|
|
|
}
|
|
|
|
|
return $query->where('tenant_key', $tenantKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关联飞书应用配置
|
|
|
|
|
*/
|
|
|
|
|
public function feishuApps()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(CompanyFeishuApp::class, 'company_id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 关联用户
|
|
|
|
|
*/
|
|
|
|
|
public function users()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(User::class, 'company_id');
|
|
|
|
|
}
|
|
|
|
|
}
|