Keep the newest 2000 success rows per inbound type so dumps stop growing from Pargar webhooks, and store compact document payloads instead of full JSON. Co-authored-by: Cursor <cursoragent@cursor.com>
81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Services\DatabaseLogPruneService;
|
|
use App\Services\PargarSyncService;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
class PargarSyncLog extends Model
|
|
{
|
|
protected $table = 'pargar_sync_logs';
|
|
|
|
protected $fillable = [
|
|
'customer_id',
|
|
'amount',
|
|
'desc',
|
|
'order_id',
|
|
'withdraw_id',
|
|
'date',
|
|
'type',
|
|
'sync_status',
|
|
'sync_log',
|
|
'pargar_ref',
|
|
'res',
|
|
'data',
|
|
'confirmed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'confirmed_at' => 'datetime',
|
|
];
|
|
|
|
private static ?bool $hasConfirmedAtColumn = null;
|
|
|
|
/** سازگاری با نصبهایی که هنوز مایگریشن confirmed_at را اجرا نکردهاند */
|
|
public static function hasConfirmedAtColumn(): bool
|
|
{
|
|
if (self::$hasConfirmedAtColumn === null) {
|
|
try {
|
|
self::$hasConfirmedAtColumn = Schema::hasColumn('pargar_sync_logs', 'confirmed_at');
|
|
} catch (\Throwable) {
|
|
self::$hasConfirmedAtColumn = false;
|
|
}
|
|
}
|
|
|
|
return self::$hasConfirmedAtColumn;
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::created(function (self $log) {
|
|
if (! in_array($log->type, [PargarSyncService::TYPE_MANDE, PargarSyncService::TYPE_DOCUMENT], true)) {
|
|
return;
|
|
}
|
|
|
|
dispatch(function () {
|
|
if (function_exists('fastcgi_finish_request')) {
|
|
@fastcgi_finish_request();
|
|
}
|
|
try {
|
|
app(DatabaseLogPruneService::class)->prunePargarInboundOverflow();
|
|
} catch (\Throwable) {
|
|
// وبهوک پرگار نباید بهخاطر پاکسازی قطع شود
|
|
}
|
|
})->afterResponse();
|
|
});
|
|
}
|
|
|
|
public function customer(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Customer::class);
|
|
}
|
|
|
|
public function order(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Order::class);
|
|
}
|
|
}
|