added time working
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Automation;
|
||||
use App\Models\AutomationSend;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Message;
|
||||
use App\Services\ConfigService;
|
||||
use App\Services\CustomerAppNotifyService;
|
||||
use App\Services\SmsBilling\SmsGatewayService;
|
||||
use App\Exceptions\SmsBlockedException;
|
||||
@@ -16,6 +17,7 @@ class AutomationSender
|
||||
public function __construct(
|
||||
private readonly SmsGatewayService $sms,
|
||||
private readonly CustomerAppNotifyService $notify,
|
||||
private readonly ConfigService $config,
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -34,7 +36,7 @@ class AutomationSender
|
||||
if ($mobile === '') {
|
||||
throw new \RuntimeException('موبایل خالی است');
|
||||
}
|
||||
$text = trim($title."\n".$body);
|
||||
$text = $this->ensureAppNameFooter(trim($title."\n".$body));
|
||||
$result = $this->sms->sendOrThrow($mobile, $text, 'automation');
|
||||
if (! $result->sent) {
|
||||
throw new \RuntimeException($result->errorMessage ?: 'ارسال پیامک ناموفق');
|
||||
@@ -105,15 +107,42 @@ class AutomationSender
|
||||
return true;
|
||||
}
|
||||
|
||||
private function ensureAppNameFooter(string $message): string
|
||||
{
|
||||
$appName = trim($this->config->getString('name_fa'));
|
||||
$trimmed = rtrim($message);
|
||||
if ($appName === '') {
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
$lines = preg_split('/\R/u', $trimmed) ?: [];
|
||||
$last = trim((string) end($lines));
|
||||
if ($last === $appName) {
|
||||
return $trimmed;
|
||||
}
|
||||
|
||||
return $trimmed === '' ? $appName : ($trimmed."\n".$appName);
|
||||
}
|
||||
|
||||
private function render(string $text, Customer $customer): string
|
||||
{
|
||||
$name = trim((string) ($customer->name ?: trim(($customer->fname ?? '').' '.($customer->lname ?? ''))));
|
||||
$fname = (string) ($customer->fname ?? '');
|
||||
$mobile = (string) ($customer->mobile ?? '');
|
||||
|
||||
return strtr($text, [
|
||||
// سازگاری با قالب قدیمی {{name}}
|
||||
$out = strtr($text, [
|
||||
'{{name}}' => $name,
|
||||
'{{fname}}' => (string) ($customer->fname ?? ''),
|
||||
'{{mobile}}' => (string) ($customer->mobile ?? ''),
|
||||
'{{fname}}' => $fname,
|
||||
'{{mobile}}' => $mobile,
|
||||
]);
|
||||
|
||||
// الگوی پیامک/تنظیمات: %نام ، ٪نام ، % name ، %name%
|
||||
$out = preg_replace('/[%٪]\s*(?:name|نام)[%٪]?/iu', $name, $out) ?? $out;
|
||||
$out = preg_replace('/[%٪]\s*(?:fname|نام_کوچک|نامکوچک)[%٪]?/iu', $fname, $out) ?? $out;
|
||||
$out = preg_replace('/[%٪]\s*(?:mobile|موبایل)[%٪]?/iu', $mobile, $out) ?? $out;
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
private function log(Automation $auto, Customer $customer, string $channel, string $status, ?string $error = null): void
|
||||
|
||||
Reference in New Issue
Block a user