message service

This commit is contained in:
amazuecos
2025-02-15 17:54:53 +01:00
parent eea415fb47
commit 4364bc3c07
4 changed files with 66 additions and 2 deletions

View File

@ -4,6 +4,7 @@ namespace Config;
use App\Services\FTPService;
use App\Services\MaquinaService;
use App\Services\MessageService;
use App\Services\PapelImpresionService;
use CodeIgniter\Config\BaseService;
use App\Services\ProductionService;
@ -48,4 +49,8 @@ class Services extends BaseService
{
return new MaquinaService();
}
public static function messages()
{
return new MessageService();
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Services;
use App\Controllers\Configuracion\ConfigVariables;
use App\Models\Chat\ChatDeparmentModel;
use App\Models\Chat\ChatMessageModel;
use App\Models\Chat\ChatModel;
use App\Models\ChatNotification;
use App\Models\ChatUser;
use App\Models\Configuracion\ConfigVariableModel;
use App\Models\Presupuestos\PresupuestoModel;
use CodeIgniter\Config\BaseService;
class MessageService extends BaseService
{
protected ChatModel $chatModel;
protected ChatMessageModel $chatMessageModel;
protected ChatUser $chatUserModel;
protected ChatNotification $chatNotificationModel;
protected PresupuestoModel $presupuestoModel;
protected ChatDeparmentModel $chatDepartmentModel;
protected ConfigVariableModel $configVariables;
public function __construct()
{
$this->chatModel = model(ChatModel::class);
$this->chatMessageModel = model(ChatMessageModel::class);
$this->chatNotificationModel = model(ChatNotification::class);
$this->chatUserModel = model(ChatUser::class);
$this->presupuestoModel = model(PresupuestoModel::class);
$this->chatDepartmentModel = model(ChatDeparmentModel::class);
$this->configVariables = model(ConfigVariableModel::class);
}
public function createErrorMessagePresupuesto(string $error, int $presupuesto_id)
{
$chat_department_name = $this->configVariables->getVariable('send_error_to_chat_department_name');
$chat_department_id = $this->chatDepartmentModel->where('name', $chat_department_name)->first()?->id;
if ($chat_department_id) {
$existChat = $this->chatModel->existChatPresupuesto($chat_department_id, $presupuesto_id);
if ($existChat == false) {
$chatId = $this->chatModel->createChatPresupuesto($chat_department_id, $presupuesto_id);
} else {
$chat = $this->chatModel->getChatPresupuesto($chat_department_id, $presupuesto_id);
$chatId = $chat->id;
}
$chat_message_id = $this->chatMessageModel->insert(["chat_id" => $chatId, "sender_id" => auth()->user()->id, "message" => $error]);
$dataResponse = $this->chatMessageModel->find($chat_message_id);
$chatDepartmentUsers = $this->chatDepartmentModel->getChatDepartmentUsers($chat_department_id);
foreach ($chatDepartmentUsers as $user) {
if ($user->id != auth()->user()->id) {
$this->chatNotificationModel->insert(["chat_message_id" => $chat_message_id, "user_id" => $user->id]);
}
}
}
}
}

View File

@ -1,6 +1,6 @@
<?= $this->include("themes/_commonPartialsBs/select2bs5") ?>
<?= $this->include("themes/_commonPartialsBs/sweetalert") ?>
<?= $this->extend('themes/vuexy/main/defaultlayout') ?>
<?= $this->extend('themes/vuexy/main/defaultlayout')?>
<?= $this->section("content") ?>
<div class="row">
<div class="col-12">

View File

@ -1,6 +1,6 @@
<?=$this->include('themes/_commonPartialsBs/datatables') ?>
<?=$this->extend('themes/vuexy/main/defaultlayout') ?>
<?=$this->section('content'); ?>
<?=$this->section('content')?>
<div class="row">
<div class="col-md-12">