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

@ -98,4 +98,26 @@ class ChatDeparmentModel extends Model
}
return $departments;
}
public function getChatDepartmentUsers(int $chat_deparment_id)
{
$result = $this->db->table('chat_departments')
->select(
[
"users.*"
]
)
->join(
"chat_department_users",
"chat_department_users.chat_department_id = chat_departments.id",
'left'
)
->join(
"users",
"chat_department_users.user_id = users.id",
'left'
)->where("chat_departments.id",$chat_deparment_id)
->get()->getResultObject();
return $result;
}
}

View File

@ -47,4 +47,12 @@ class ChatDeparmentUserModel extends Model
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
public function getChatDepartmentUser(int $user_id)
{
return $this->db->table($this->table." t1")
->select("chat_departments.*")
->join("chat_departments","t1.chat_department_id = chat_departments.id","left")
->where("t1.user_id",$user_id)->get()->getResultObject();
}
}

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;
}
}