2024-04-07 16:03:37 +00:00
|
|
|
package model
|
|
|
|
|
2024-04-08 10:13:01 +00:00
|
|
|
import (
|
2024-04-10 06:58:19 +00:00
|
|
|
"gorm.io/gorm"
|
2024-04-08 10:13:01 +00:00
|
|
|
)
|
|
|
|
|
2024-04-07 16:03:37 +00:00
|
|
|
type KillaraCustomerHoldModel struct {
|
|
|
|
// fields ...
|
2024-04-10 06:58:19 +00:00
|
|
|
db *gorm.DB
|
2024-04-08 10:13:01 +00:00
|
|
|
TableName string // 表名
|
2024-04-07 16:03:37 +00:00
|
|
|
}
|
2024-04-16 10:00:05 +00:00
|
|
|
|
|
|
|
func (m *KillaraCustomerHoldModel) GetHoldsForFrontEnd(tx *gorm.DB, data map[string]interface{}) ([]*KillaraCustomerHold, error) {
|
|
|
|
var db *gorm.DB
|
|
|
|
if tx != nil {
|
|
|
|
db = tx
|
|
|
|
} else {
|
|
|
|
db = m.db
|
|
|
|
}
|
|
|
|
|
|
|
|
var holds []*KillaraCustomerHold
|
|
|
|
query := db.Model(&KillaraCustomerHold{})
|
|
|
|
|
|
|
|
if customerID, ok := data["customer_id"].(uint64); ok && customerID > 0 {
|
|
|
|
query = query.Where("customer_id = ?", customerID)
|
|
|
|
}
|
|
|
|
|
|
|
|
if market, ok := data["market"].(string); ok && market != "" {
|
|
|
|
query = query.Where("market = ?", market)
|
|
|
|
}
|
|
|
|
|
|
|
|
if holdType, ok := data["type"].(uint64); ok && holdType > 0 {
|
|
|
|
query = query.Where("type = ?", holdType)
|
|
|
|
}
|
|
|
|
|
|
|
|
if status, ok := data["status"].(uint64); ok && status > 0 {
|
|
|
|
query = query.Where("status = ?", status)
|
|
|
|
}
|
|
|
|
|
|
|
|
query = query.Order("customer_hold_id DESC")
|
|
|
|
|
|
|
|
if start, ok := data["start"].(int); ok && start > 0 {
|
|
|
|
query = query.Offset(start)
|
|
|
|
}
|
|
|
|
|
|
|
|
if limit, ok := data["limit"].(int); ok && limit > 0 {
|
|
|
|
query = query.Limit(limit)
|
|
|
|
} else {
|
|
|
|
query = query.Limit(10)
|
|
|
|
}
|
|
|
|
|
|
|
|
err := query.Find(&holds).Error
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return holds, err
|
|
|
|
}
|