feat:chat modules

This commit is contained in:
amazuecos
2024-09-25 17:42:55 +00:00
parent 2fc9af9db4
commit c651db61ff
16 changed files with 808 additions and 382 deletions

View File

@ -2,7 +2,7 @@
namespace App\Models\Chat;
use App\Models\Usuarios\UserModel;
use CodeIgniter\Model;
use stdClass;
@ -192,5 +192,74 @@ class ChatModel extends Model
->get()->getResultObject();
return $query;
}
public function getClienteChatPedidos(array $pedidos) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.pedido_id as pedidoId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"pedidos.id as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("pedidos","pedidos.id = chats.pedido_id","left")
->join("chat_messages","pedidos.id = chats.pedido_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("pedidos.id",$pedidos)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
public function getClienteChatFacturas(array $facturas) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.factura_id as facturaId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"facturas.numero as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("facturas","facturas.id = chats.factura_id","left")
->join("chat_messages","chats.id = chat_messages.chat_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("facturas.id",$facturas)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
public function getClienteChatPresupuestos(array $presupuestos) : array
{
$results = $this->db->table("chats")
->select([
"chats.id as chatId",
"chats.presupuesto_id as presupuestoId",
"chats.chat_department_id as chatDepartmentId",
"chat_departments.display as chatDisplay",
"presupuestos.titulo as title"
])
->join("chat_departments","chat_departments.id = chats.chat_department_id","left")
->join("presupuestos","presupuestos.id = chats.presupuesto_id","left")
->join("chat_messages","chats.id = chat_messages.chat_id","left")
->whereNotIn("chat_messages.sender_id",[auth()->user()->id])
->whereIn("presupuestos.id",$presupuestos)
->get()->getResultObject();
$chatMessageModel = model(ChatMessageModel::class);
foreach ($results as $row) {
$row->messages = $chatMessageModel->get_chat_messages($row->chatId);
}
return $results;
}
}