Files
boursecu_server/app/Models/PriceSyncLog.php
T

69 lines
1.6 KiB
PHP
Raw Normal View History

2026-06-13 12:42:42 +03:30
<?php
namespace App\Models;
use App\Services\ZaarboxPriceService;
2026-06-13 12:42:42 +03:30
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class PriceSyncLog extends Model
{
protected $table = 'price_sync_logs';
public $timestamps = false;
protected $fillable = [
'source',
'source_url',
'liquid_gold_price',
'products_updated',
'created_at',
];
protected $casts = [
'liquid_gold_price' => 'integer',
'products_updated' => 'integer',
'created_at' => 'datetime',
];
protected $appends = [
'source_label',
];
public function getSourceLabelAttribute(): string
{
$source = (string) ($this->source ?? '');
if ($source === 'zaarbox' || $source === 'store') {
try {
return app(ZaarboxPriceService::class)->priceSourceTitle();
} catch (\Throwable) {
return 'گواهی سپرده کاتد';
}
}
if ($source === 'montzar') {
return 'تابلو montzar';
}
if ($source === 'main_product') {
return 'محصول اصلی';
}
if ($source === 'legacy') {
return 'فید قدیمی';
}
if ($source === 'database_last') {
return 'آخرین قیمت DB';
}
return $source !== '' ? $source : 'گواهی سپرده کاتد';
}
2026-06-13 12:42:42 +03:30
public function items(): HasMany
{
return $this->hasMany(PriceSyncLogItem::class, 'log_id');
}
}