1. 實作多租戶專屬自訂登入頁面:支援 `/c/{company_code}/login` 特殊入口,自動載入租戶專屬 Logo 網址、名稱與歡迎詞。
2. 支援客製化品牌視覺設定:於客戶管理清單中,提供 SaaS 管理者可自訂租戶 Logo 圖片與歡迎副標題,且系統後台 Header/Sidebar 與登入頁能動態依該配置載入租戶專屬商標。
3. 擴充多語系字典並完成三檔對齊:新增 "Upload Time" 欄位與翻譯,執行 `ksort` 以維持 zh_TW、en 與 ja 語系檔對齊。
4. APK 版本清單增加上傳時間欄位:於 APK 版本表格中呈現上傳時間(created_at),使用 font-mono 奢華風小尺寸樣式呈現。
116 lines
2.8 KiB
PHP
116 lines
2.8 KiB
PHP
<?php
|
||
|
||
namespace App\Models\System;
|
||
|
||
use App\Models\Machine\Machine;
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
use Spatie\Permission\Models\Role;
|
||
|
||
class Company extends Model
|
||
{
|
||
use HasFactory, SoftDeletes;
|
||
|
||
protected $fillable = [
|
||
'name',
|
||
'code',
|
||
'original_type',
|
||
'current_type',
|
||
'tax_id',
|
||
'contact_name',
|
||
'contact_phone',
|
||
'contact_email',
|
||
'status',
|
||
'start_date',
|
||
'end_date',
|
||
'warranty_start_date',
|
||
'warranty_end_date',
|
||
'software_start_date',
|
||
'software_end_date',
|
||
'note',
|
||
'settings',
|
||
];
|
||
|
||
protected $casts = [
|
||
'start_date' => 'date:Y-m-d',
|
||
'end_date' => 'date:Y-m-d',
|
||
'warranty_start_date' => 'date:Y-m-d',
|
||
'warranty_end_date' => 'date:Y-m-d',
|
||
'software_start_date' => 'date:Y-m-d',
|
||
'software_end_date' => 'date:Y-m-d',
|
||
'status' => 'integer',
|
||
'settings' => 'array',
|
||
];
|
||
|
||
/**
|
||
* Get the contract history for the company.
|
||
*/
|
||
public function contracts(): HasMany
|
||
{
|
||
return $this->hasMany(CompanyContract::class)->latest();
|
||
}
|
||
|
||
/**
|
||
* Get the users for the company.
|
||
*/
|
||
public function users(): HasMany
|
||
{
|
||
return $this->hasMany(User::class);
|
||
}
|
||
|
||
/**
|
||
* Get the machines for the company.
|
||
*/
|
||
public function machines(): HasMany
|
||
{
|
||
return $this->hasMany(Machine::class);
|
||
}
|
||
|
||
/**
|
||
* Get the products for the company.
|
||
*/
|
||
public function products(): HasMany
|
||
{
|
||
return $this->hasMany(\App\Models\Product\Product::class);
|
||
}
|
||
|
||
/**
|
||
* Scope:僅篩選啟用的公司
|
||
*/
|
||
public function scopeActive($query)
|
||
{
|
||
return $query->where('status', 1);
|
||
}
|
||
|
||
/**
|
||
* 獲取公司自訂 Logo 的完整 URL (Accessor)
|
||
*/
|
||
public function getLogoUrlAttribute(): ?string
|
||
{
|
||
$settings = $this->settings ?? [];
|
||
$logoPath = $settings['logo_path'] ?? null;
|
||
|
||
// 只有在啟用品牌自訂功能且上傳了 Logo 時才使用自訂 Logo
|
||
if ($this->hasCustomBrandingEnabled() && $logoPath) {
|
||
return \Illuminate\Support\Facades\Storage::disk('public')->url($logoPath);
|
||
}
|
||
|
||
return asset('starcloud_icon.png');
|
||
}
|
||
|
||
/**
|
||
* 檢查此公司是否啟用且配置了品牌自訂功能
|
||
*/
|
||
public function hasCustomBrandingEnabled(): bool
|
||
{
|
||
$settings = $this->settings ?? [];
|
||
$enableCustomBranding = filter_var($settings['enable_custom_branding'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||
$logoPath = $settings['logo_path'] ?? null;
|
||
|
||
return $enableCustomBranding && !empty($logoPath);
|
||
}
|
||
}
|
||
|