1. 新增 ProductCatalogService 負責商品清單轉換與 Redis 快取邏輯。 2. 新增 WarmProductsCacheCommand (artisan products:warm-cache) 用於預熱快取。 3. 修改 ProductController 在商品異動時自動重建快取。 4. 修改 MachineController@getProducts (B012) 改為 Cache-First 讀取。 5. 在 Company 模型補上 products 關聯以支援暖機指令。
87 lines
1.9 KiB
PHP
87 lines
1.9 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);
|
||
}
|
||
}
|