fix pargar bugs 5
This commit is contained in:
@@ -234,43 +234,34 @@ class PargarInboundController extends Controller
|
|||||||
{
|
{
|
||||||
$data = $this->pargarPayload($request);
|
$data = $this->pargarPayload($request);
|
||||||
$accountId = trim((string) ($data['accountId'] ?? ''));
|
$accountId = trim((string) ($data['accountId'] ?? ''));
|
||||||
|
$summary = $this->sync()->summarizeInboundDocument($data);
|
||||||
|
|
||||||
$customer = $accountId !== ''
|
$customer = $accountId !== ''
|
||||||
? Customer::where('pargar_account_id', $accountId)->first()
|
? Customer::where('pargar_account_id', $accountId)->first()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
if ($customer) {
|
// فقط لاگ — اعمال خودکار روی کیف خاموش است (جلوگیری از شارژ چندباره وقتی پرگار مکرر میفرستد)
|
||||||
$applyResult = $this->inboundWallet()->applyDocuments($customer, $data);
|
|
||||||
|
|
||||||
return response()->json([
|
|
||||||
'success' => true,
|
|
||||||
'message' => sprintf(
|
|
||||||
'اسناد مشتری دریافت شد — اعمال: %d، رد شده: %d',
|
|
||||||
$applyResult['applied'],
|
|
||||||
$applyResult['skipped']
|
|
||||||
),
|
|
||||||
'data' => $applyResult,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// مشتری ناشناس — فقط لاگ برای بررسی ادمین
|
|
||||||
$summary = $this->sync()->summarizeInboundDocument($data);
|
|
||||||
PargarSyncLog::create([
|
PargarSyncLog::create([
|
||||||
'customer_id' => null,
|
'customer_id' => $customer?->id,
|
||||||
'amount' => $summary['amount'],
|
'amount' => $summary['amount'],
|
||||||
'desc' => 'دریافت اسناد از پرگار — مشتری یافت نشد',
|
'desc' => $customer
|
||||||
|
? ($summary['desc'] !== '' ? $summary['desc'] : 'دریافت اسناد از پرگار')
|
||||||
|
: 'دریافت اسناد از پرگار — مشتری یافت نشد',
|
||||||
'type' => PargarSyncService::TYPE_DOCUMENT,
|
'type' => PargarSyncService::TYPE_DOCUMENT,
|
||||||
'sync_status' => PargarSyncService::STATUS_SUCCESS,
|
'sync_status' => PargarSyncService::STATUS_SUCCESS,
|
||||||
'pargar_ref' => $accountId !== '' ? $accountId : null,
|
'pargar_ref' => $accountId !== '' ? $accountId : null,
|
||||||
'data' => json_encode(array_merge($data, [
|
'data' => json_encode(array_merge($data, [
|
||||||
'_summary' => $summary,
|
'_summary' => $summary,
|
||||||
'wallet_applied' => false,
|
'wallet_applied' => false,
|
||||||
|
'auto_apply_disabled' => true,
|
||||||
]), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
]), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => 'اسناد دریافت شد ولی مشتری با این کد حساب یافت نشد',
|
'message' => $customer
|
||||||
|
? 'اسناد مشتری دریافت و ثبت شد (بدون تغییر کیف)'
|
||||||
|
: 'اسناد دریافت شد ولی مشتری با این کد حساب یافت نشد',
|
||||||
'data' => null,
|
'data' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user