new feature on sms and some bugs fixed

This commit is contained in:
2026-07-18 22:22:01 +03:30
parent 518334da11
commit fc9de5198c
20 changed files with 489 additions and 95 deletions
@@ -8,6 +8,8 @@ use App\Models\Message;
use App\Models\Order;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\ConfigService;
use App\Services\SmsProfanityFilter;
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
@@ -22,6 +24,9 @@ class MassageController extends Controller
// یافتن مشتریان با شماره‌های داده شده
$customers = Customer::whereIn('mobile', $request->numbers)->get();
$filter = app(SmsProfanityFilter::class);
$filter->assertClean((string) ($request->message ?? ''));
foreach ($customers as $customer) {
// جایگزین کردن نام در پیام
$message = str_replace('%name%', $customer->name, $request->message);
@@ -32,6 +37,59 @@ class MassageController extends Controller
return response()->json(true);
}
/**
* پیامک تکی به یک مشتری — فقط وقتی customer_direct_sms روشن باشد.
*/
public function send_customer_message(Request $request)
{
if (! app(ConfigService::class)->getBool('customer_direct_sms', false)) {
throw new UnprocessableEntityHttpException('ارسال پیامک تکی به مشتری غیرفعال است.');
}
$customerId = (int) ($request->input('customer_id') ?? 0);
$rawMessage = trim((string) ($request->input('message') ?? ''));
if ($customerId <= 0) {
throw new UnprocessableEntityHttpException('مشتری مشخص نشده است.');
}
if ($rawMessage === '') {
throw new UnprocessableEntityHttpException('متن پیامک خالی است.');
}
if (mb_strlen($rawMessage) > 700) {
throw new UnprocessableEntityHttpException('متن پیامک بیش از حد طولانی است.');
}
app(SmsProfanityFilter::class)->assertClean($rawMessage);
$customer = Customer::find($customerId);
if (! $customer || ! $customer->mobile) {
throw new UnprocessableEntityHttpException('مشتری یا شماره موبایل یافت نشد.');
}
$cfg = app(ConfigService::class);
$appName = (string) ($cfg->get('name_fa', '') ?: '');
$appUrl = (string) ($cfg->get('app_url', '') ?: '');
$message = str_replace(
['%name%', '%نام%', '%app_name%', '%نام_اپ%', '%app_url%', '%لینک_اپ%', '%لینک%'],
[
(string) $customer->name,
(string) $customer->name,
$appName,
$appName,
$appUrl,
$appUrl,
$appUrl,
],
$rawMessage
);
$this->send($customer->mobile, $message);
return response()->json(['ok' => true]);
}
public function getFunctionDescriptions()
{