From 7c68115b396eb03ca11d2d7c4990243b050b3652 Mon Sep 17 00:00:00 2001 From: adonis Date: Mon, 27 Jul 2026 22:09:08 +0330 Subject: [PATCH] fix some bugs --- .../Controllers/Admin/WalletController.php | 50 ++++++++++ .../Controllers/Customer/WalletController.php | 11 +++ .../Controllers/Finance/FinanceController.php | 11 ++- .../Single/SingleOrderController.php | 11 +++ .../Controllers/Site/RequestsController.php | 15 +++ .../Controllers/pay/paypingController.php | 22 +++++ app/Services/CustomerAppNotifyService.php | 97 +++++++++++++++++++ app/Services/PargarInboundWalletService.php | 5 +- 8 files changed, 220 insertions(+), 2 deletions(-) create mode 100644 app/Services/CustomerAppNotifyService.php diff --git a/app/Http/Controllers/Admin/WalletController.php b/app/Http/Controllers/Admin/WalletController.php index ddc76d6..0d081e5 100644 --- a/app/Http/Controllers/Admin/WalletController.php +++ b/app/Http/Controllers/Admin/WalletController.php @@ -135,6 +135,16 @@ class WalletController extends Controller $message = 'کیف پول شما به مبلغ ' . self::formatSmsRialAmount($data['value']) . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') . " شارژ شد " . "\n" . $this->Config('name_fa'); $this->Send($customer->mobile, $message); + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + 'واریز به کیف پول', + 'کیف پول شما به مبلغ ' . self::formatSmsRialAmount($data['value']) . ' ریال شارژ شد.', + 'success' + ); + } catch (\Throwable $e) { + report($e); + } return response()->json(true); } @@ -232,6 +242,21 @@ class WalletController extends Controller . $this->Config('name_fa'); $this->Send($customer->mobile, $message); } + + try { + $isDeposit = (float) $data['value'] > 0; + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + $isDeposit ? 'واریز به کیف پول' : 'برداشت از کیف پول', + 'کیف پول شما به اندازه ' . self::formatSmsRialAmount($data['value']) . ' ریال' + . ($isDeposit ? ' شارژ شد.' : ' کسر شد.') + . (trim((string) ($data['note'] ?? '')) !== '' ? "\n" . $data['note'] : ''), + $isDeposit ? 'success' : 'warning' + ); + } catch (\Throwable $e) { + report($e); + } + $this->broadcastCustomerWalletAssets($customer); return response()->json(true); @@ -339,6 +364,19 @@ class WalletController extends Controller . $this->Config('name_fa'); $this->Send($customer->mobile, $message); } + try { + $isDeposit = (float) $data['value'] > 0; + $weightUnit = self::tradeWeightUnit(); + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + $isDeposit ? 'واریز طلا' : 'برداشت طلا', + 'کیف پول شما به اندازه ' . self::formatSmsGoldWeight($data['value']) . " {$weightUnit}" + . ($isDeposit ? ' شارژ شد.' : ' کسر شد.'), + $isDeposit ? 'success' : 'warning' + ); + } catch (\Throwable $e) { + report($e); + } $this->broadcastCustomerWalletAssets($customer); return response()->json(true); @@ -517,6 +555,18 @@ class WalletController extends Controller . $this->Config('name_fa'); $this->Send($customer->mobile, $message); } + try { + $isDeposit = (bool) $deposit; + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + $isDeposit ? 'واریز محصول' : 'برداشت محصول', + 'کیف پول شما به اندازه ' . $formatted . ' ' . $unitLabel + . ($isDeposit ? ' شارژ شد.' : ' کسر شد.'), + $isDeposit ? 'success' : 'warning' + ); + } catch (\Throwable $e) { + report($e); + } $this->broadcastCustomerWalletAssets($customer); return response()->json(true); diff --git a/app/Http/Controllers/Customer/WalletController.php b/app/Http/Controllers/Customer/WalletController.php index d017bdd..bae1de8 100644 --- a/app/Http/Controllers/Customer/WalletController.php +++ b/app/Http/Controllers/Customer/WalletController.php @@ -453,6 +453,17 @@ class WalletController extends Controller } }); + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + 'درخواست برداشت', + 'درخواست برداشت مبلغ ' . number_format((float) $withdrawAmount) . ' ریال ثبت شد.', + 'info' + ); + } catch (\Throwable $e) { + report($e); + } + return response()->json($Withdraw); } diff --git a/app/Http/Controllers/Finance/FinanceController.php b/app/Http/Controllers/Finance/FinanceController.php index 8c9b49d..a22c6c8 100644 --- a/app/Http/Controllers/Finance/FinanceController.php +++ b/app/Http/Controllers/Finance/FinanceController.php @@ -228,7 +228,16 @@ class FinanceController extends Controller } }); - + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $Withdraw->customer_id, + 'واریز به کیف پول', + 'حساب شما به مقدار ' . number_format((float) $chargedAmount) . ' ریال شارژ شد.', + 'success' + ); + } catch (\Throwable $e) { + report($e); + } return view('showTransactionReport', compact('Withdraw')); return redirect('https://app.gholaktala.ir/transactions'); diff --git a/app/Http/Controllers/Single/SingleOrderController.php b/app/Http/Controllers/Single/SingleOrderController.php index 094955b..83cc986 100644 --- a/app/Http/Controllers/Single/SingleOrderController.php +++ b/app/Http/Controllers/Single/SingleOrderController.php @@ -891,6 +891,17 @@ class SingleOrderController extends Controller if (self::isSmsNotifEnabled('sms_notif_order_customer')) { $this->send($customer->mobile, $customerMessage); } + + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + $transactionType . ' ' . $subjectTitle, + "گرم: {$amount}\nمبلغ کل: " . number_format((float) $totalPrice) . " ریال", + 'success' + ); + } catch (\Throwable $e) { + report($e); + } } private function assertProviderOrderAccepted(array &$data): void diff --git a/app/Http/Controllers/Site/RequestsController.php b/app/Http/Controllers/Site/RequestsController.php index ede7b10..9075ea3 100644 --- a/app/Http/Controllers/Site/RequestsController.php +++ b/app/Http/Controllers/Site/RequestsController.php @@ -219,6 +219,21 @@ class RequestsController extends Controller if (self::isSmsNotifEnabled('sms_notif_fund_withdraw_customer')) { $this->send($customer->mobile, $customerMessage); } + + try { + $title = ($data['method'] ?? '') === 'gold' ? 'برداشت طلایی' : 'برداشت ریالی'; + $body = ($data['method'] ?? '') === 'gold' + ? 'گرم: ' . ($data['amount'] ?? '') . "\nمبلغ کل: " . number_format((float) ($data['total_price'] ?? 0)) . ' ریال' + : 'مبلغ: ' . number_format((float) ($data['amount'] ?? 0)) . ' ریال'; + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $customer->id, + $title, + $body, + 'info' + ); + } catch (\Throwable $e) { + report($e); + } } } diff --git a/app/Http/Controllers/pay/paypingController.php b/app/Http/Controllers/pay/paypingController.php index e13b4f2..c20e7c6 100644 --- a/app/Http/Controllers/pay/paypingController.php +++ b/app/Http/Controllers/pay/paypingController.php @@ -206,6 +206,17 @@ class paypingController extends Controller } }); + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $Withdraw->customer_id, + 'واریز به کیف پول', + 'حساب شما به مقدار ' . number_format((float) $Withdraw->cash) . ' ریال شارژ شد.', + 'success' + ); + } catch (\Throwable $e) { + report($e); + } + return view('showTransactionReport', compact('Withdraw', 'site_url')); } @@ -297,6 +308,17 @@ class paypingController extends Controller } }); + try { + app(\App\Services\CustomerAppNotifyService::class)->notifyCustomer( + (int) $Withdraw->customer_id, + 'واریز به کیف پول', + 'حساب شما به مقدار ' . number_format((float) $Withdraw->cash) . ' ریال شارژ شد.', + 'success' + ); + } catch (\Throwable $e) { + report($e); + } + return view('showTransactionReport', compact('Withdraw', 'site_url')); } diff --git a/app/Services/CustomerAppNotifyService.php b/app/Services/CustomerAppNotifyService.php new file mode 100644 index 0000000..94d038e --- /dev/null +++ b/app/Services/CustomerAppNotifyService.php @@ -0,0 +1,97 @@ +config->getBool('has_page_notification', false)) { + return null; + } + + $title = mb_substr(trim($title), 0, 191); + $body = mb_substr(trim($body), 0, 5000); + if ($title === '' || $body === '') { + return null; + } + + if (! in_array($severity, ['info', 'success', 'warning', 'danger'], true)) { + $severity = 'info'; + } + + try { + $row = DB::transaction(function () use ($customerId, $title, $body, $severity) { + $row = AppNotification::create([ + 'title' => $title, + 'body' => $body, + 'severity' => $severity, + 'is_active' => true, + 'created_by' => null, + 'audience_type' => AppNotificationAudienceService::TYPE_CUSTOMERS, + 'segment_keys' => null, + 'audience_label' => 'سیستمی — مشتری '.$customerId, + 'recipients_count' => 1, + ]); + + AppNotificationRecipient::query()->insert([ + 'notification_id' => $row->id, + 'customer_id' => $customerId, + 'created_at' => now(), + 'updated_at' => now(), + ]); + + return $row; + }); + + $this->broadcastToCustomer($row, $customerId); + + return $row; + } catch (\Throwable $e) { + Log::warning('CustomerAppNotify failed', [ + 'customer_id' => $customerId, + 'error' => $e->getMessage(), + ]); + + return null; + } + } + + private function broadcastToCustomer(AppNotification $row, int $customerId): void + { + $payload = [ + 'id' => $row->id, + 'title' => $row->title, + 'body' => $row->body, + 'severity' => $row->severity, + 'created_at' => optional($row->created_at)?->toIso8601String(), + ]; + + $this->stream->publishForCustomer($customerId, 'app_notification', $payload); + } +} diff --git a/app/Services/PargarInboundWalletService.php b/app/Services/PargarInboundWalletService.php index e4a025b..8a3185b 100644 --- a/app/Services/PargarInboundWalletService.php +++ b/app/Services/PargarInboundWalletService.php @@ -407,7 +407,10 @@ class PargarInboundWalletService $data['wallet_applied_from_mande'] = true; unset($data['mande_skip_reason'], $data['mande_skipped_at']); $log->data = json_encode($data, JSON_UNESCAPED_UNICODE); - $log->desc = 'دریافت مانده از پرگار — بدون اختلاف'; + // اگر قبلاً اعمال شده، شرح «اعمال مانده» را با «بدون اختلاف» عوض نکن + if (empty($data['applied_at'])) { + $log->desc = 'دریافت مانده از پرگار — بدون اختلاف'; + } $log->save(); return ['applied' => false, 'message' => 'مانده با پرگار یکسان است'];