fix some bugs
This commit is contained in:
@@ -164,6 +164,9 @@ class PargarInboundWalletService
|
||||
|
||||
$lock = Cache::lock('pargar-wallet-sync:'.$customer->id, 60);
|
||||
if (! $lock->get()) {
|
||||
// سند و مانده اغلب پشتسرهم میآیند؛ اگر قفل اشغال است دوباره صف کن
|
||||
$this->queueWalletSyncAfterResponse((int) $customer->id, delaySeconds: 3);
|
||||
|
||||
return [
|
||||
'documents' => [
|
||||
'applied' => 0,
|
||||
@@ -172,7 +175,7 @@ class PargarInboundWalletService
|
||||
'acknowledged' => 0,
|
||||
'errors' => ['همگامسازی در حال اجراست'],
|
||||
],
|
||||
'mande' => ['applied' => false, 'message' => 'همگامسازی دیگری برای این مشتری در حال اجراست'],
|
||||
'mande' => ['applied' => false, 'message' => 'همگامسازی دیگری برای این مشتری در حال اجراست — در صف تکرار'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -381,7 +384,7 @@ class PargarInboundWalletService
|
||||
if (! $force) {
|
||||
$block = $this->mandeBlockReason($customer, $log, $data);
|
||||
if ($block !== null) {
|
||||
$this->markMandeSkipped($log, $data, $block['reason']);
|
||||
$this->markMandeSkipped($log, $data, $block['reason'], $block['message']);
|
||||
|
||||
return ['applied' => false, 'message' => $block['message']];
|
||||
}
|
||||
@@ -402,7 +405,9 @@ class PargarInboundWalletService
|
||||
|
||||
if (abs($goldDiff) < 0.01 && abs($rialDiff) < 1) {
|
||||
$data['wallet_applied_from_mande'] = true;
|
||||
unset($data['mande_skip_reason'], $data['mande_skipped_at']);
|
||||
$log->data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
$log->desc = 'دریافت مانده از پرگار — بدون اختلاف';
|
||||
$log->save();
|
||||
|
||||
return ['applied' => false, 'message' => 'مانده با پرگار یکسان است'];
|
||||
@@ -601,7 +606,7 @@ class PargarInboundWalletService
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
private function markMandeSkipped(PargarSyncLog $log, array $data, string $reason): void
|
||||
private function markMandeSkipped(PargarSyncLog $log, array $data, string $reason, ?string $message = null): void
|
||||
{
|
||||
if (($data['mande_skip_reason'] ?? null) === $reason) {
|
||||
return;
|
||||
@@ -611,6 +616,12 @@ class PargarInboundWalletService
|
||||
$data['mande_skipped_at'] = now()->toDateTimeString();
|
||||
|
||||
$log->data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||
// تا UI روی «در حال اعمال» گیر نکند
|
||||
if ($message !== null && $message !== '') {
|
||||
$log->desc = mb_substr($message, 0, 250);
|
||||
} elseif (is_string($log->desc) && str_contains($log->desc, 'در حال اعمال')) {
|
||||
$log->desc = mb_substr('مانده نگهداشته شد — '.$reason, 0, 250);
|
||||
}
|
||||
$log->save();
|
||||
}
|
||||
|
||||
@@ -625,10 +636,16 @@ class PargarInboundWalletService
|
||||
|
||||
/**
|
||||
* همگامسازی خودکار در پسزمینه — بعد از مانده / تأیید سند در پرگار / import.
|
||||
*
|
||||
* @param int $delaySeconds تأخیر داخل afterResponse (برای رد شدن از قفل webhook قبلی)
|
||||
*/
|
||||
public function queueWalletSyncAfterResponse(int $customerId): void
|
||||
public function queueWalletSyncAfterResponse(int $customerId, int $delaySeconds = 0): void
|
||||
{
|
||||
dispatch(function () use ($customerId) {
|
||||
dispatch(function () use ($customerId, $delaySeconds) {
|
||||
if ($delaySeconds > 0) {
|
||||
sleep(min($delaySeconds, 10));
|
||||
}
|
||||
|
||||
$customer = Customer::find($customerId);
|
||||
if ($customer === null || ! $customer->hasValidPargarAccountId()) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user