up
This commit is contained in:
@@ -150,6 +150,48 @@ func GetDlocalPaymentLogs(limit int) ([]DlocalPaymentLog, error) {
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogsPaginated devuelve los logs con paginación y filtro por estado.
|
||||
// El valor especial "APROBADOS" agrupa PAID + AUTHORIZED.
|
||||
func GetDlocalPaymentLogsPaginated(page, limit int, estado string) ([]DlocalPaymentLog, int64, error) {
|
||||
var logs []DlocalPaymentLog
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&DlocalPaymentLog{})
|
||||
switch estado {
|
||||
case "", "TODOS":
|
||||
// sin filtro
|
||||
case "APROBADOS":
|
||||
db = db.Where("estado IN ?", []string{"PAID", "AUTHORIZED"})
|
||||
default:
|
||||
db = db.Where("estado = ?", estado)
|
||||
}
|
||||
db.Count(&total)
|
||||
offset := (page - 1) * limit
|
||||
if err := db.Order("id DESC").Limit(limit).Offset(offset).Find(&logs).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return logs, total, nil
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogByID carga un registro por su PK.
|
||||
func GetDlocalPaymentLogByID(id uint, out *DlocalPaymentLog) error {
|
||||
return app.Http.Database.DB.First(out, id).Error
|
||||
}
|
||||
|
||||
// UpdateDlocalPaymentLogDatos actualiza email y monto de un log existente.
|
||||
func UpdateDlocalPaymentLogDatos(id uint, payerEmail string, monto float64) error {
|
||||
updates := map[string]interface{}{}
|
||||
if payerEmail != "" {
|
||||
updates["payer_email"] = payerEmail
|
||||
}
|
||||
if monto > 0 {
|
||||
updates["monto"] = monto
|
||||
}
|
||||
if len(updates) == 0 {
|
||||
return nil
|
||||
}
|
||||
return app.Http.Database.DB.Model(&DlocalPaymentLog{}).Where("id = ?", id).Updates(updates).Error
|
||||
}
|
||||
|
||||
// GetDlocalPaymentLogsByRef devuelve todos los registros que coinciden con una referencia/order_id.
|
||||
func GetDlocalPaymentLogsByRef(ref string) ([]DlocalPaymentLog, error) {
|
||||
var logs []DlocalPaymentLog
|
||||
|
||||
Reference in New Issue
Block a user