up
This commit is contained in:
@@ -40,11 +40,37 @@ func DispatchTicketRespuestaAdmin(ticket *models.ProyectoTicket, contenido strin
|
||||
log.Printf("[Notif] PortalUser %d no encontrado: %v", ticket.PortalUserID, err)
|
||||
return
|
||||
}
|
||||
if portalUser.Email == "" {
|
||||
|
||||
cfg := models.GetNotifConfig("ticket_respuesta_admin", "portal_user")
|
||||
if cfg == nil {
|
||||
return
|
||||
}
|
||||
// TODO: enviar email al portal user cuando mail_service implemente SendTicketRespuestaPortalUser
|
||||
_ = fmt.Sprintf("/portal/dashboard")
|
||||
|
||||
portalURL := "/portal/dashboard"
|
||||
titulo := fmt.Sprintf("Respuesta en tu ticket: %s", ticket.Titulo)
|
||||
cuerpo := fmt.Sprintf("El equipo respondió: %s", contenido)
|
||||
|
||||
if cfg.CanalSistema {
|
||||
_ = models.CreateSistemaNotif(&models.SistemaNotificacion{
|
||||
TipoUsuario: "portal_user",
|
||||
UsuarioID: portalUser.ID,
|
||||
Titulo: titulo,
|
||||
Cuerpo: cuerpo,
|
||||
Url: portalURL,
|
||||
Icono: "💬",
|
||||
})
|
||||
}
|
||||
if cfg.CanalEmail && portalUser.Email != "" {
|
||||
go SendTicketRespuestaPortalUser(portalUser.Email, portalUser.Nombre, proyectoNombre, ticket.Titulo, contenido, portalURL)
|
||||
}
|
||||
if cfg.CanalTelegram && portalUser.TelegramChatID != "" {
|
||||
ts := NewTelegramService()
|
||||
msg := fmt.Sprintf("💬 <b>El equipo respondió tu ticket</b>\nProyecto: <b>%s</b>\nTicket: <b>%s</b>\n\n%s",
|
||||
proyectoNombre, ticket.Titulo, contenido)
|
||||
if err := ts.SendMessageWithToken(portalUser.TelegramChatID, msg, getAdminBotToken()); err != nil {
|
||||
log.Printf("[Notif] Error telegram portal_user %d: %v", portalUser.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ─── DispatchFacturaSubida ────────────────────────────────────────────────────
|
||||
@@ -53,12 +79,49 @@ func DispatchFacturaSubida(factura *models.Factura) {
|
||||
if factura == nil || factura.ClienteID == 0 {
|
||||
return
|
||||
}
|
||||
cfg := models.GetNotifConfig("factura_subida", "portal_user")
|
||||
if cfg == nil {
|
||||
return
|
||||
}
|
||||
portalUsers, err := models.GetPortalUsersByClienteID(factura.ClienteID)
|
||||
if err != nil || len(portalUsers) == 0 {
|
||||
return
|
||||
}
|
||||
log.Printf("[Notif] DispatchFacturaSubida factura=%d portal_users=%d (pendiente de implementar)",
|
||||
factura.ID, len(portalUsers))
|
||||
|
||||
clienteNombre := factura.Cliente.Empresa
|
||||
if clienteNombre == "" {
|
||||
clienteNombre = factura.Cliente.Nombre
|
||||
}
|
||||
|
||||
for _, u := range portalUsers {
|
||||
u := u
|
||||
portalURL := "/portal/dashboard"
|
||||
titulo := fmt.Sprintf("Nueva factura disponible: %s", factura.Numero)
|
||||
cuerpo := fmt.Sprintf("Factura %s por %s %.2f", factura.Numero, factura.Moneda, factura.Monto)
|
||||
|
||||
if cfg.CanalSistema {
|
||||
_ = models.CreateSistemaNotif(&models.SistemaNotificacion{
|
||||
TipoUsuario: "portal_user",
|
||||
UsuarioID: u.ID,
|
||||
Titulo: titulo,
|
||||
Cuerpo: cuerpo,
|
||||
Url: portalURL,
|
||||
Icono: "🧾",
|
||||
})
|
||||
}
|
||||
if cfg.CanalEmail && u.Email != "" {
|
||||
go SendFacturaSubidaPortalUser(u.Email, u.Nombre, clienteNombre, factura.Numero, factura.Monto, factura.Moneda, portalURL)
|
||||
}
|
||||
if cfg.CanalTelegram && u.TelegramChatID != "" {
|
||||
ts := NewTelegramService()
|
||||
msg := fmt.Sprintf("🧾 <b>Nueva factura disponible</b>\nNúmero: <b>%s</b>\nMonto: %s %.2f",
|
||||
factura.Numero, factura.Moneda, factura.Monto)
|
||||
if err := ts.SendMessageWithToken(u.TelegramChatID, msg, getAdminBotToken()); err != nil {
|
||||
log.Printf("[Notif] Error telegram portal_user %d: %v", u.ID, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Printf("[Notif] DispatchFacturaSubida factura=%d clientes notificados=%d", factura.ID, len(portalUsers))
|
||||
}
|
||||
|
||||
// ─── helpers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user