58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type KillaraCustomerHoldModel struct {
|
|
// fields ...
|
|
db *gorm.DB
|
|
TableName string // 表名
|
|
}
|
|
|
|
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
|
|
}
|