2026-06-13 12:42:42 +03:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-11-18 18:25:34 +03:30
|
|
|
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',
|
|
|
|
|
];
|
|
|
|
|
|
2026-11-18 18:25:34 +03:30
|
|
|
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');
|
|
|
|
|
}
|
|
|
|
|
}
|