new feature on sms and some bugs fixed
This commit is contained in:
@@ -103,6 +103,23 @@ class Controller extends BaseController
|
||||
// }
|
||||
}
|
||||
|
||||
/** آیا این نوع پیامک اعلان روشن است؟ پیشفرض true اگر کلید در settings نباشد. */
|
||||
public static function isSmsNotifEnabled(string $key, bool $default = true): bool
|
||||
{
|
||||
return app(ConfigService::class)->isSmsNotifEnabled($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* خرید/فروش فقط بعد از احراز هویت (is_legal ≠ 0).
|
||||
* جدا از active / auto_active_customer که فقط ورود به اپ را کنترل میکنند.
|
||||
*/
|
||||
public static function assertCustomerIdentityVerified(?Customer $customer): void
|
||||
{
|
||||
if (!$customer || (int) ($customer->is_legal ?? 0) === 0) {
|
||||
throw new UnprocessableEntityHttpException('لطفا ابتدا فرآیند احراز هویت خود را تکمیل کنید');
|
||||
}
|
||||
}
|
||||
|
||||
public static function SendMessage($to, $msg ,$is_send = false,$force_method ='null')
|
||||
{
|
||||
$credentials = [
|
||||
@@ -111,7 +128,6 @@ class Controller extends BaseController
|
||||
],
|
||||
"bale" => [
|
||||
"token" => self::Config('bale_bot_token')
|
||||
// "token" => Setting::where('key', 'bale_bot_token')->where('is_active', true)->first()->value ?? null
|
||||
],
|
||||
"sms" => [
|
||||
'user_name' => 'ysms1362',
|
||||
@@ -120,8 +136,9 @@ class Controller extends BaseController
|
||||
],
|
||||
];
|
||||
$platforms = [];
|
||||
$send_sms = true;
|
||||
$user = User::where('mobile', $to)->first() ?: Customer::where('mobile', $to)->first();
|
||||
|
||||
// بله و پیامک مستقلاند — موفقیت یکی، دیگری را قطع نمیکند
|
||||
if ($user) {
|
||||
$baleToken = trim((string) ($credentials['bale']['token'] ?? ''));
|
||||
$baleChatId = trim((string) ($user->bale ?? ''));
|
||||
@@ -137,44 +154,43 @@ class Controller extends BaseController
|
||||
$balePayload = $baleResponse->json();
|
||||
if ($baleResponse->successful() && ($balePayload['ok'] ?? false) === true) {
|
||||
$platforms[] = "bale:{$baleChatId}";
|
||||
$send_sms = false;
|
||||
} else {
|
||||
$platforms[] = "bale_failed:{$baleChatId}";
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
$platforms[] = "bale_error:{$baleChatId}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//SMS
|
||||
if ($send_sms or $force_method=="sms") {
|
||||
try {
|
||||
$gateway = app(SmsGatewayService::class);
|
||||
try {
|
||||
$gateway = app(SmsGatewayService::class);
|
||||
|
||||
if ($force_method == "sms") {
|
||||
$smsResult = $gateway->sendOrThrow($to, trim($msg), 'notification');
|
||||
} else {
|
||||
$smsResult = $gateway->send($to, trim($msg), 'notification');
|
||||
}
|
||||
|
||||
if ($smsResult->blocked) {
|
||||
$platforms[] = "blocked:{$to}";
|
||||
} elseif ($smsResult->sent && $smsResult->provider) {
|
||||
$platforms[] = "{$smsResult->provider}:{$to}";
|
||||
} else {
|
||||
$platforms[] = "sms_failed:{$to}";
|
||||
}
|
||||
} catch (SmsBlockedException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
$platforms[] = "sms_error:{$to}";
|
||||
if ($force_method == "sms") {
|
||||
$smsResult = $gateway->sendOrThrow($to, trim($msg), 'notification');
|
||||
} else {
|
||||
$smsResult = $gateway->send($to, trim($msg), 'notification');
|
||||
}
|
||||
|
||||
if ($smsResult->blocked) {
|
||||
$platforms[] = "blocked:{$to}";
|
||||
} elseif ($smsResult->sent && $smsResult->provider) {
|
||||
$platforms[] = "{$smsResult->provider}:{$to}";
|
||||
} else {
|
||||
$platforms[] = "sms_failed:{$to}";
|
||||
}
|
||||
} catch (SmsBlockedException $e) {
|
||||
throw $e;
|
||||
} catch (\Throwable $e) {
|
||||
report($e);
|
||||
$platforms[] = "sms_error:{$to}";
|
||||
}
|
||||
|
||||
Message::create([
|
||||
'sms' => $msg,
|
||||
'receiver' => $to,
|
||||
'platforms' => implode(', ', $platforms), // ذخیره لیست سامانهها
|
||||
'platforms' => implode(', ', $platforms),
|
||||
]);
|
||||
}
|
||||
public static function SendTelegram($to , $msg)
|
||||
|
||||
Reference in New Issue
Block a user