fix(server): queue tiny Pargar gold wallet documents instead of skipping them

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-18 17:57:22 +03:30
co-authored by Cursor
parent e158831fd3
commit 0afa01eea9
3 changed files with 121 additions and 9 deletions
+44 -4
View File
@@ -28,6 +28,14 @@ class PargarSyncService
public const PAYMENT_MAIN_GOLD = 'main_gold';
public const PAYMENT_OTHER_PRODUCT = 'other_product';
/** فقط صفر اعشاری/نویز شناور رد شود — سند ریز (۰٫۰۰۴ گرم جایزه) باید برود */
public const WALLET_DOC_EPSILON = 1.0e-12;
public static function isWalletDocAmount(float $amount): bool
{
return abs($amount) >= self::WALLET_DOC_EPSILON;
}
public function buildLog(mixed $response = null, ?string $extra = null): string
{
$parts = array_filter([
@@ -176,7 +184,7 @@ class PargarSyncService
return null;
}
if (abs($signedAmount) < ($kind === 'cash' ? 1 : 0.01)) {
if (! self::isWalletDocAmount($signedAmount)) {
return null;
}
@@ -353,7 +361,7 @@ class PargarSyncService
foreach ($rows as $row) {
$withdrawId = (int) ($row->withdraw_id ?? 0);
$cash = (float) ($row->cash ?? 0);
if ($withdrawId <= 0 || abs($cash) < 1) {
if ($withdrawId <= 0 || ! self::isWalletDocAmount($cash)) {
continue;
}
@@ -370,6 +378,38 @@ class PargarSyncService
return $queued;
}
/**
* صف‌کردن سند طلا برای حرکت‌هایی که لاگ پرگار ندارند (جایزه ریز و …).
*
* @param iterable<int, object{withdraw_id?:mixed,gold?:mixed,note?:mixed}> $rows
*/
public function queueMissingGoldDocuments(Customer $customer, iterable $rows, string $source = 'auto_missing_gold'): int
{
if (! $this->isSyncEnabled() || ! $this->hasSyncTable()) {
return 0;
}
$queued = 0;
foreach ($rows as $row) {
$withdrawId = (int) ($row->withdraw_id ?? 0);
$gold = (float) ($row->gold ?? 0);
if ($withdrawId <= 0 || ! self::isWalletDocAmount($gold)) {
continue;
}
$log = $this->queueWalletDocument($customer, 'gold', $gold, [
'withdraw_id' => $withdrawId,
'note' => $row->note ?? null,
'source' => $source,
]);
if ($log !== null) {
$queued++;
}
}
return $queued;
}
/**
* @param array{
* payment_kind?: string,
@@ -818,10 +858,10 @@ class PargarSyncService
$amount = null;
$amountUnit = null;
if ($maxGold >= 0.01) {
if ($maxGold >= self::WALLET_DOC_EPSILON) {
$amount = $maxGold;
$amountUnit = 'gold';
} elseif ($maxRial >= 1) {
} elseif ($maxRial >= self::WALLET_DOC_EPSILON) {
$amount = $maxRial;
$amountUnit = 'rial';
}