all customer from pargar fixing 2
This commit is contained in:
@@ -111,6 +111,7 @@ class PargarInboundController extends Controller
|
||||
$customer->pargar_account_id = $accountId;
|
||||
$this->applyPargarCustomerName($customer, $fullName);
|
||||
$customer->save();
|
||||
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $customer->id);
|
||||
$messages[] = "کد حسابداری مشتری {$fullName} ویرایش شد";
|
||||
continue;
|
||||
}
|
||||
@@ -129,6 +130,7 @@ class PargarInboundController extends Controller
|
||||
$byAccount->password = $mobile;
|
||||
}
|
||||
$byAccount->save();
|
||||
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $byAccount->id);
|
||||
$messages[] = "مشتری با کد حسابداری {$accountId} بهروزرسانی شد";
|
||||
continue;
|
||||
}
|
||||
@@ -144,6 +146,7 @@ class PargarInboundController extends Controller
|
||||
$customer->referral_id = $this->uniqueReferralId();
|
||||
$customer->save();
|
||||
|
||||
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $customer->id);
|
||||
$messages[] = "مشتری با کد حسابداری {$accountId} ایجاد شد";
|
||||
} catch (\Throwable $e) {
|
||||
$messages[] = "خطا برای {$mobile}: " . (
|
||||
@@ -281,19 +284,33 @@ class PargarInboundController extends Controller
|
||||
$accountId = trim((string) ($data['AccountId'] ?? ''));
|
||||
|
||||
$customer = Customer::where('pargar_account_id', $accountId)->first();
|
||||
if (! $customer) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'مشتری یافت نشد',
|
||||
'data' => null,
|
||||
], 422);
|
||||
}
|
||||
|
||||
// اگر مشتری هنوز وارد نشده، مانده را با 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;
|
||||
|
||||
// فقط مقایسه برای لاگ — اپ source of truth است؛ کیف را از مانده پرگار عوض نکن
|
||||
// اضطراری: هیچوقت از mande کیف را تغییر نده (حتی اگر کد قدیمی جایی مانده باشد)
|
||||
if (! $customer) {
|
||||
PargarSyncLog::create([
|
||||
'customer_id' => null,
|
||||
'desc' => 'مانده پرگار — مشتری هنوز در پنل نیست',
|
||||
'type' => PargarSyncService::TYPE_MANDE,
|
||||
'amount' => $goldInv,
|
||||
'sync_status' => PargarSyncService::STATUS_SUCCESS,
|
||||
'pargar_ref' => $accountId,
|
||||
'data' => json_encode(array_merge($data, [
|
||||
'orphan_mande' => true,
|
||||
'wallet_adjusted' => false,
|
||||
]), JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'مانده ذخیره شد؛ پس از ثبت مشتری اعمال میشود',
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
// فقط مقایسه برای لاگ — اعمال روی کیف فقط با دکمه ادمین / صف auto پس از import-claim
|
||||
$ownerType = (int) ($customer->type ?? 2);
|
||||
$walletInterface = new WalletInterface($customer->id, $ownerType);
|
||||
$wallet = $walletInterface->wallet;
|
||||
@@ -324,6 +341,11 @@ class PargarInboundController extends Controller
|
||||
]), JSON_UNESCAPED_UNICODE),
|
||||
]);
|
||||
|
||||
// اولین مانده برای مشتریِ هنوز واردنشده به اپ — یکبار همتراز کن
|
||||
if ($customer->last_seen_at === null && $hasDiff) {
|
||||
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $customer->id);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'مانده مشتری با موفقیت دریافت شد',
|
||||
@@ -420,6 +442,8 @@ class PargarInboundController extends Controller
|
||||
if ($log) {
|
||||
$this->sync()->markSuccess($log, $normalizedAccountId);
|
||||
}
|
||||
|
||||
app(PargarInboundWalletService::class)->queueWalletSyncAfterResponse((int) $customer->id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user