master
parent
772af756b5
commit
9bf02e2940
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||||
use A7kz\Platform\Models\UniModel;
|
use A7kz\Platform\Models\UniModel;
|
||||||
use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
|
use A7kz\Platform\Modules\Platform\Acl\Facades\Acl;
|
||||||
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
use A7kz\Platform\Modules\Platform\Segment\Facades\Segment;
|
||||||
|
use App\Http\Notifications\TelegramNotification;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Modules\applications\Enum\ApplicationStatus;
|
use App\Modules\applications\Enum\ApplicationStatus;
|
||||||
use App\Modules\auto\Enums\AutoStatusEnums;
|
use App\Modules\auto\Enums\AutoStatusEnums;
|
||||||
|
|
@ -140,6 +141,17 @@ class MobileApiController extends Controller
|
||||||
'sum' => $sum
|
'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);
|
return response()->json($response);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return response()->json($e->getMessage());
|
return response()->json($e->getMessage());
|
||||||
|
|
@ -432,6 +444,10 @@ class MobileApiController extends Controller
|
||||||
$application->status = ApplicationStatus::review->value;
|
$application->status = ApplicationStatus::review->value;
|
||||||
$application->save();
|
$application->save();
|
||||||
|
|
||||||
|
$notification = [];
|
||||||
|
$notification['ID заявки'] = $application->id;
|
||||||
|
$notification['Сообщение'] = __('Получена заявка на закрытие');
|
||||||
|
$this->sendNotification($notification);
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'message' => __('Фото получены ожидайте закрытия заявки после проверки оператором'),
|
'message' => __('Фото получены ожидайте закрытия заявки после проверки оператором'),
|
||||||
|
|
@ -516,4 +532,12 @@ class MobileApiController extends Controller
|
||||||
|
|
||||||
return response()->json($text ?? '');
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,19 +32,26 @@ class TelegramNotification extends Notification
|
||||||
|
|
||||||
public function toTelegram($notifiable)
|
public function toTelegram($notifiable)
|
||||||
{
|
{
|
||||||
print_r($notifiable);
|
$message = TelegramMessage::create()
|
||||||
return TelegramMessage::create()
|
->to(config('services.telegram-bot-api.id'))
|
||||||
->to(env('TELEGRAM_CHAT_ID'))
|
->content($notifiable['message']);
|
||||||
->content($notifiable['car'])
|
|
||||||
->line('')
|
$excludedFields = [
|
||||||
->line($notifiable['base_price'])
|
'message',
|
||||||
->line($notifiable['period'])
|
'id',
|
||||||
->line($notifiable['pickup_location'])
|
'created_at',
|
||||||
->line($notifiable['return_location'])
|
'updated_at',
|
||||||
->line($notifiable['customer_type'])
|
'token'
|
||||||
->line($notifiable['customer_full_name'])
|
];
|
||||||
->line($notifiable['customer_email'])
|
|
||||||
->line($notifiable['customer_phone']);
|
foreach ($notifiable as $field => $value) {
|
||||||
|
if (in_array($field, $excludedFields) || empty($value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$message->line($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,12 @@
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
|
"a7kz/platform": "*",
|
||||||
"guzzlehttp/guzzle": "^7.2",
|
"guzzlehttp/guzzle": "^7.2",
|
||||||
|
"laravel-notification-channels/telegram": "^5.0",
|
||||||
"laravel/framework": "^10.10",
|
"laravel/framework": "^10.10",
|
||||||
"laravel/sanctum": "^3.3",
|
"laravel/sanctum": "^3.3",
|
||||||
"laravel/tinker": "^2.8",
|
"laravel/tinker": "^2.8"
|
||||||
"a7kz/platform": "*"
|
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.9.1",
|
"fakerphp/faker": "^1.9.1",
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -14,6 +14,11 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
'telegram-bot-api' => [
|
||||||
|
'token' => env('TELEGRAM_BOT_TOKEN'),
|
||||||
|
'id' => env('TELEGRAM_CHAT_ID'),
|
||||||
|
],
|
||||||
|
|
||||||
'mailgun' => [
|
'mailgun' => [
|
||||||
'domain' => env('MAILGUN_DOMAIN'),
|
'domain' => env('MAILGUN_DOMAIN'),
|
||||||
'secret' => env('MAILGUN_SECRET'),
|
'secret' => env('MAILGUN_SECRET'),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue