fix pargar bugs
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Customer;
|
||||
use App\Models\Order;
|
||||
use App\Models\PargarSyncLog;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\PargarInboundWalletService;
|
||||
use App\Services\PargarSyncService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@@ -224,28 +225,52 @@ class PargarInboundController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
protected function inboundWallet(): PargarInboundWalletService
|
||||
{
|
||||
return app(PargarInboundWalletService::class);
|
||||
}
|
||||
|
||||
public function storeDocuments(Request $request)
|
||||
{
|
||||
$data = $this->pargarPayload($request);
|
||||
$accountId = trim((string) ($data['accountId'] ?? ''));
|
||||
$transactions = $data['transactions'] ?? [];
|
||||
|
||||
$customer = $accountId !== ''
|
||||
? Customer::where('pargar_account_id', $accountId)->first()
|
||||
: 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([
|
||||
'customer_id' => $customer?->id,
|
||||
'desc' => 'دریافت اسناد از پرگار',
|
||||
'customer_id' => null,
|
||||
'amount' => $summary['amount'],
|
||||
'desc' => 'دریافت اسناد از پرگار — مشتری یافت نشد',
|
||||
'type' => PargarSyncService::TYPE_DOCUMENT,
|
||||
'sync_status' => PargarSyncService::STATUS_SUCCESS,
|
||||
'pargar_ref' => $accountId,
|
||||
'data' => json_encode($data, JSON_UNESCAPED_UNICODE),
|
||||
'pargar_ref' => $accountId !== '' ? $accountId : null,
|
||||
'data' => json_encode(array_merge($data, [
|
||||
'_summary' => $summary,
|
||||
'wallet_applied' => false,
|
||||
]), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'اسناد مشتری با موفقیت دریافت شد',
|
||||
'message' => 'اسناد دریافت شد ولی مشتری با این کد حساب یافت نشد',
|
||||
'data' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user