fix pargar bugs
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Customer;
|
||||
use App\Models\PargarSyncLog;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\PargarInboundWalletService;
|
||||
use App\Services\PargarSyncService;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -253,6 +255,36 @@ class PargarController extends Controller
|
||||
return response()->json($result, ($result['ok'] ?? false) ? 200 : 422);
|
||||
}
|
||||
|
||||
public function syncCustomerWallet($customerId)
|
||||
{
|
||||
if (! app(ConfigService::class)->isPargarAccounting()) {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'حسابداری پرگار فعال نیست',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$customer = Customer::findOrFail($customerId);
|
||||
if (trim((string) ($customer->pargar_account_id ?? '')) === '') {
|
||||
return response()->json([
|
||||
'ok' => false,
|
||||
'message' => 'این مشتری کد حساب پرگار ندارد',
|
||||
], 422);
|
||||
}
|
||||
|
||||
$result = app(PargarInboundWalletService::class)->syncWalletFromPargar($customer);
|
||||
$appliedDocs = (int) ($result['documents']['applied'] ?? 0);
|
||||
$appliedMande = (bool) ($result['mande']['applied'] ?? false);
|
||||
|
||||
return response()->json([
|
||||
'ok' => $appliedDocs > 0 || $appliedMande,
|
||||
'message' => $appliedDocs > 0 || $appliedMande
|
||||
? 'مانده از پرگار روی کیف اعمال شد'
|
||||
: ($result['mande']['message'] ?? 'سند قابلاعمالی یافت نشد'),
|
||||
'result' => $result,
|
||||
], $appliedDocs > 0 || $appliedMande ? 200 : 422);
|
||||
}
|
||||
|
||||
private function uniqueReferralId(): string
|
||||
{
|
||||
do {
|
||||
|
||||
Reference in New Issue
Block a user