master
Rustem 2025-06-14 15:43:08 +05:00
parent 772af756b5
commit 9bf02e2940
5 changed files with 423 additions and 316 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use A7kz\Platform\Models\UniModel;
use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
use App\Http\Notifications\TelegramNotification;
use App\Models\User;
use App\Modules\applications\Enum\ApplicationStatus;
use App\Modules\auto\Enums\AutoStatusEnums;
@ -140,6 +141,17 @@ class MobileApiController extends Controller
'sum' => $sum
]);
$notification = [];
$notification['Адрес получения'] = $data['address_start'];
$notification['Адрес возврата'] = $data['address_end'];
$notification['Дата и время начала'] = $data['started_at'];
$notification['Дата и время возврата'] = $data['ended_at'];
$notification['Телефон'] = $data['phone'] ?? $user?->phone ?? null;
$notification['Имя'] = $data['name'] ?? $user?->name ?? null;
$notification['Почта'] = $data['email'] ?? $user?->email ?? null;
$notification['Сообщение'] = __('Новая заявка');
$this->sendNotification($notification);
return response()->json($response);
} catch (Exception $e) {
return response()->json($e->getMessage());
@ -432,6 +444,10 @@ class MobileApiController extends Controller
$application->status = ApplicationStatus::review->value;
$application->save();
$notification = [];
$notification['ID заявки'] = $application->id;
$notification['Сообщение'] = __('Получена заявка на закрытие');
$this->sendNotification($notification);
return response()->json([
'success' => true,
'message' => __('Фото получены ожидайте закрытия заявки после проверки оператором'),
@ -516,4 +532,12 @@ class MobileApiController extends Controller
return response()->json($text ?? '');
}
private function sendNotification(array $data): void
{
foreach ($data as $key => $value) {
$text[$key] = $key . ': ' . $value;
}
Notification::send([$text], new TelegramNotification($text));
}
}

View File

@ -32,19 +32,26 @@ class TelegramNotification extends Notification
public function toTelegram($notifiable)
{
print_r($notifiable);
return TelegramMessage::create()
->to(env('TELEGRAM_CHAT_ID'))
->content($notifiable['car'])
->line('')
->line($notifiable['base_price'])
->line($notifiable['period'])
->line($notifiable['pickup_location'])
->line($notifiable['return_location'])
->line($notifiable['customer_type'])
->line($notifiable['customer_full_name'])
->line($notifiable['customer_email'])
->line($notifiable['customer_phone']);
$message = TelegramMessage::create()
->to(config('services.telegram-bot-api.id'))
->content($notifiable['message']);
$excludedFields = [
'message',
'id',
'created_at',
'updated_at',
'token'
];
foreach ($notifiable as $field => $value) {
if (in_array($field, $excludedFields) || empty($value)) {
continue;
}
$message->line($value);
}
return $message;
}
/**

View File

@ -12,11 +12,12 @@
"license": "MIT",
"require": {
"php": "^8.1",
"a7kz/platform": "*",
"guzzlehttp/guzzle": "^7.2",
"laravel-notification-channels/telegram": "^5.0",
"laravel/framework": "^10.10",
"laravel/sanctum": "^3.3",
"laravel/tinker": "^2.8",
"a7kz/platform": "*"
"laravel/tinker": "^2.8"
},
"require-dev": {
"fakerphp/faker": "^1.9.1",

672
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,11 @@ return [
|
*/
'telegram-bot-api' => [
'token' => env('TELEGRAM_BOT_TOKEN'),
'id' => env('TELEGRAM_CHAT_ID'),
],
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),