All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 48s
1. 新增廣告排程功能,支援設定發布時間與下架時間。 2. 整合 Flatpickr 時間選擇器,提供與機台日誌一致的極簡奢華風 UI。 3. 優化廣告列表中的數字字體,套用 font-mono 與 tabular-nums,與客戶管理模組風格同步。 4. 修正 Alpine.js 資料同步邏輯,確保編輯模式下排程時間能正確回填。
73 lines
1.7 KiB
PHP
73 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models\System;
|
|
|
|
use App\Models\Machine\MachineAdvertisement;
|
|
use App\Traits\TenantScoped;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Advertisement extends Model
|
|
{
|
|
use HasFactory, TenantScoped;
|
|
|
|
protected $fillable = [
|
|
'company_id',
|
|
'name',
|
|
'type',
|
|
'duration',
|
|
'url',
|
|
'is_active',
|
|
'start_at',
|
|
'end_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'duration' => 'integer',
|
|
'is_active' => 'boolean',
|
|
'start_at' => 'datetime',
|
|
'end_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* Get the machine assignments for this advertisement.
|
|
*/
|
|
public function machineAdvertisements()
|
|
{
|
|
return $this->hasMany(MachineAdvertisement::class);
|
|
}
|
|
|
|
/**
|
|
* Get the company that owns the advertisement.
|
|
*/
|
|
public function company()
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include active advertisements.
|
|
*/
|
|
public function scopeActive($query)
|
|
{
|
|
return $query->where('is_active', true);
|
|
}
|
|
|
|
/**
|
|
* Scope a query to only include advertisements that should be playing now.
|
|
*/
|
|
public function scopePlaying($query)
|
|
{
|
|
$now = now();
|
|
return $query->where('is_active', true)
|
|
->where(function ($q) use ($now) {
|
|
$q->whereNull('start_at')
|
|
->orWhere('start_at', '<=', $now);
|
|
})
|
|
->where(function ($q) use ($now) {
|
|
$q->whereNull('end_at')
|
|
->orWhere('end_at', '>=', $now);
|
|
});
|
|
}
|
|
}
|