fix some bugs
This commit is contained in:
@@ -135,6 +135,16 @@ class WalletController extends Controller
|
|||||||
$message = 'کیف پول شما به مبلغ ' . self::formatSmsRialAmount($data['value']) . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') . " شارژ شد " . "\n"
|
$message = 'کیف پول شما به مبلغ ' . self::formatSmsRialAmount($data['value']) . " ریال در تاریخ " . verta()->format('Y/n/j H:i:s') . " شارژ شد " . "\n"
|
||||||
. $this->Config('name_fa');
|
. $this->Config('name_fa');
|
||||||
$this->Send($customer->mobile, $message);
|
$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);
|
return response()->json(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,6 +242,21 @@ class WalletController extends Controller
|
|||||||
. $this->Config('name_fa');
|
. $this->Config('name_fa');
|
||||||
$this->Send($customer->mobile, $message);
|
$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);
|
$this->broadcastCustomerWalletAssets($customer);
|
||||||
|
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
@@ -339,6 +364,19 @@ class WalletController extends Controller
|
|||||||
. $this->Config('name_fa');
|
. $this->Config('name_fa');
|
||||||
$this->Send($customer->mobile, $message);
|
$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);
|
$this->broadcastCustomerWalletAssets($customer);
|
||||||
|
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
@@ -517,6 +555,18 @@ class WalletController extends Controller
|
|||||||
. $this->Config('name_fa');
|
. $this->Config('name_fa');
|
||||||
$this->Send($customer->mobile, $message);
|
$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);
|
$this->broadcastCustomerWalletAssets($customer);
|
||||||
|
|
||||||
return response()->json(true);
|
return response()->json(true);
|
||||||
|
|||||||
@@ -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);
|
return response()->json($Withdraw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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 view('showTransactionReport', compact('Withdraw'));
|
||||||
return redirect('https://app.gholaktala.ir/transactions');
|
return redirect('https://app.gholaktala.ir/transactions');
|
||||||
|
|||||||
@@ -891,6 +891,17 @@ class SingleOrderController extends Controller
|
|||||||
if (self::isSmsNotifEnabled('sms_notif_order_customer')) {
|
if (self::isSmsNotifEnabled('sms_notif_order_customer')) {
|
||||||
$this->send($customer->mobile, $customerMessage);
|
$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
|
private function assertProviderOrderAccepted(array &$data): void
|
||||||
|
|||||||
@@ -219,6 +219,21 @@ class RequestsController extends Controller
|
|||||||
if (self::isSmsNotifEnabled('sms_notif_fund_withdraw_customer')) {
|
if (self::isSmsNotifEnabled('sms_notif_fund_withdraw_customer')) {
|
||||||
$this->send($customer->mobile, $customerMessage);
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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'));
|
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'));
|
return view('showTransactionReport', compact('Withdraw', 'site_url'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Models\AppNotification;
|
||||||
|
use App\Models\AppNotificationRecipient;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* اعلان تراکنشی داخل اپ برای یک مشتری — همان مسیر SSE اعلان ادمین (بدون OTP).
|
||||||
|
*/
|
||||||
|
class CustomerAppNotifyService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly ConfigService $config,
|
||||||
|
private readonly PriceStreamService $stream,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* خرید / فروش / واریز / برداشت — فقط وقتی اعلان داخل اپ روشن است.
|
||||||
|
*/
|
||||||
|
public function notifyCustomer(
|
||||||
|
int $customerId,
|
||||||
|
string $title,
|
||||||
|
string $body,
|
||||||
|
string $severity = 'info'
|
||||||
|
): ?AppNotification {
|
||||||
|
if ($customerId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (! $this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -407,7 +407,10 @@ class PargarInboundWalletService
|
|||||||
$data['wallet_applied_from_mande'] = true;
|
$data['wallet_applied_from_mande'] = true;
|
||||||
unset($data['mande_skip_reason'], $data['mande_skipped_at']);
|
unset($data['mande_skip_reason'], $data['mande_skipped_at']);
|
||||||
$log->data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
$log->data = json_encode($data, JSON_UNESCAPED_UNICODE);
|
||||||
$log->desc = 'دریافت مانده از پرگار — بدون اختلاف';
|
// اگر قبلاً اعمال شده، شرح «اعمال مانده» را با «بدون اختلاف» عوض نکن
|
||||||
|
if (empty($data['applied_at'])) {
|
||||||
|
$log->desc = 'دریافت مانده از پرگار — بدون اختلاف';
|
||||||
|
}
|
||||||
$log->save();
|
$log->save();
|
||||||
|
|
||||||
return ['applied' => false, 'message' => 'مانده با پرگار یکسان است'];
|
return ['applied' => false, 'message' => 'مانده با پرگار یکسان است'];
|
||||||
|
|||||||
Reference in New Issue
Block a user