all customer from pargar fixing 3

This commit is contained in:
2026-07-22 01:05:00 +03:30
parent 01031e9e01
commit 133f4156c6
13 changed files with 214 additions and 59 deletions
@@ -219,7 +219,12 @@ class PargarInboundController extends Controller
], 422);
}
$this->sync()->confirmOrders($orderIds);
$result = $this->sync()->confirmOrders($orderIds);
// سند در پرگار ثبت شد → ماندهٔ معطل‌مانده را همگام کن
foreach ($result['customer_ids'] ?? [] as $customerId) {
$this->inboundWallet()->queueWalletSyncAfterResponse((int) $customerId);
}
return response()->json([
'success' => true,
@@ -243,37 +248,41 @@ class PargarInboundController extends Controller
? Customer::where('pargar_account_id', $accountId)->first()
: null;
// فقط لاگ — اعمال خودکار روی کیف کاملاً خاموش است
// اگر هنوز موجودی بالا می‌رود = worker/php قدیمی هنوز زنده است → ری‌استارت الزامی
// فقط لاگ — replay تاریخچه روی کیف خاموش است؛ بعد از ذخیره، مانده به‌صورت خودکار هم‌تراز می‌شود
PargarSyncLog::create([
'customer_id' => $customer?->id,
'amount' => $summary['amount'],
'desc' => $customer
? ('[no-apply] '.($summary['desc'] !== '' ? $summary['desc'] : 'دریافت اسناد از پرگار'))
: '[no-apply] دریافت اسناد از پرگار — مشتری یافت نشد',
? ($summary['desc'] !== '' ? $summary['desc'] : 'دریافت اسناد از پرگار')
: 'دریافت اسناد از پرگار — مشتری یافت نشد',
'type' => PargarSyncService::TYPE_DOCUMENT,
'sync_status' => PargarSyncService::STATUS_SUCCESS,
'pargar_ref' => $accountId !== '' ? $accountId : null,
'data' => json_encode(array_merge($data, [
'_summary' => $summary,
'wallet_applied' => false,
'auto_apply_disabled' => true,
'code_build' => 'no-apply-v2',
'code_build' => 'docs-then-mande-auto',
]), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
]);
\Illuminate\Support\Facades\Log::info('Pargar documents stored without wallet apply', [
\Illuminate\Support\Facades\Log::info('Pargar documents stored; queue auto mande sync', [
'account_id' => $accountId,
'customer_id' => $customer?->id,
'tx_count' => is_array($data['transactions'] ?? null) ? count($data['transactions']) : 0,
]);
// به‌محض ورود اسناد → ack + اعمال آخرین مانده
if ($customer) {
$this->inboundWallet()->queueWalletSyncAfterResponse((int) $customer->id);
}
return response()->json([
'success' => true,
'message' => 'اسناد ثبت شد بدون تغییر کیف (no-apply-v2)',
'message' => 'اسناد ثبت شد؛ همگام‌سازی مانده در صف است',
'data' => [
'wallet_applied' => false,
'build' => 'no-apply-v2',
'auto_mande_queued' => (bool) $customer,
'build' => 'docs-then-mande-auto',
],
]);
}
@@ -285,7 +294,6 @@ class PargarInboundController extends Controller
$customer = Customer::where('pargar_account_id', $accountId)->first();
// اگر مشتری هنوز وارد نشده، مانده را با pargar_ref نگه می‌داریم تا بعد از import/claim اعمال شود
$goldInv = isset($data['GoldInv']) ? (float) str_replace('/', '.', (string) $data['GoldInv']) : 0;
$rialInv = isset($data['RialInv']) ? (float) str_replace('/', '.', (string) $data['RialInv']) : 0;
@@ -310,7 +318,6 @@ class PargarInboundController extends Controller
]);
}
// فقط مقایسه برای لاگ — اعمال روی کیف فقط با دکمه ادمین / صف auto پس از import-claim
$ownerType = (int) ($customer->type ?? 2);
$walletInterface = new WalletInterface($customer->id, $ownerType);
$wallet = $walletInterface->wallet;
@@ -321,9 +328,13 @@ class PargarInboundController extends Controller
$rialDiff = $rialInv - $appCash;
$hasDiff = abs($goldDiff) >= 0.01 || abs($rialDiff) >= 1;
$desc = $hasDiff
? 'اختلاف مانده پرگار با اپ — کیف اپ دست نخورده'
: 'دریافت مانده از پرگار — بدون اختلاف';
$pendingOutbound = $this->inboundWallet()->hasPendingOutboundToPargar($customer);
$desc = $pendingOutbound
? 'مانده دریافت شد — منتظر ثبت سند پنل در پرگار'
: ($hasDiff
? 'اختلاف مانده پرگار با اپ — در صف همگام‌سازی خودکار'
: 'دریافت مانده از پرگار — بدون اختلاف');
PargarSyncLog::create([
'customer_id' => $customer->id,
@@ -338,18 +349,22 @@ class PargarInboundController extends Controller
'gold_diff' => $goldDiff,
'rial_diff' => $rialDiff,
'wallet_adjusted' => false,
'awaiting_outbound_confirm' => $pendingOutbound,
]), JSON_UNESCAPED_UNICODE),
]);
// اولین مانده برای مشتریِ هنوز واردنشده به اپ — یک‌بار هم‌تراز کن
if ($customer->last_seen_at === null && $hasDiff) {
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $customer->id);
}
// همیشه صف همگام‌سازی: اگر سند pending نباشد اعمال می‌شود؛ وگرنه بعد از تأیید سند اعمال می‌شود
$this->inboundWallet()->queueWalletSyncAfterResponse((int) $customer->id);
return response()->json([
'success' => true,
'message' => 'مانده مشتری با موفقیت دریافت شد',
'data' => null,
'message' => $pendingOutbound
? 'مانده ذخیره شد؛ بعد از ثبت سند در پرگار خودکار سینک می‌شود'
: 'مانده دریافت شد؛ همگام‌سازی خودکار در صف است',
'data' => [
'awaiting_outbound_confirm' => $pendingOutbound,
'auto_sync_queued' => true,
],
]);
}