61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
|
package models
|
||
|
|
||
|
import "kefu/types"
|
||
|
|
||
|
type ProductOrder struct {
|
||
|
ID uint `json:"id"`
|
||
|
KefuName string `json:"kefu_name"`
|
||
|
OrderSn string `json:"order_sn"`
|
||
|
UserId string `json:"user_id"`
|
||
|
EntID string `json:"ent_id"`
|
||
|
OrderStatus string `json:"order_status"`
|
||
|
OrderDesc string `json:"order_desc"`
|
||
|
TotalAmount int64 `json:"total_amount"`
|
||
|
PaymentMethod string `json:"payment_method"`
|
||
|
PaymentStatus string `json:"payment_status"`
|
||
|
ShippingAddress string `json:"shipping_address"`
|
||
|
Email string `json:"email"`
|
||
|
Contact string `json:"contact"`
|
||
|
Tel string `json:"tel"`
|
||
|
CreatedAt types.Time `json:"created_at"`
|
||
|
UpdatedAt types.Time `json:"updated_at"`
|
||
|
}
|
||
|
|
||
|
// CountProductOrders 返回符合条件的 ProductOrder 记录数量
|
||
|
func CountProductOrders(query interface{}, args ...interface{}) uint {
|
||
|
var v uint
|
||
|
DB.Table("product_order").Where(query, args...).Count(&v)
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// FindProductOrder 查询单个 ProductOrder 记录
|
||
|
func FindProductOrder(query interface{}, args ...interface{}) ProductOrder {
|
||
|
var v ProductOrder
|
||
|
DB.Table("product_order").Where(query, args...).First(&v)
|
||
|
return v
|
||
|
}
|
||
|
|
||
|
// SaveProductOrder 更新 ProductOrder 记录
|
||
|
func (p *ProductOrder) SaveProductOrder(query interface{}, args ...interface{}) error {
|
||
|
db := DB.Table("product_order").Where(query, args...).Updates(p)
|
||
|
return db.Error
|
||
|
}
|
||
|
|
||
|
// AddProductOrder 添加新的 ProductOrder 记录
|
||
|
func (p *ProductOrder) AddProductOrder() error {
|
||
|
return DB.Create(p).Error
|
||
|
}
|
||
|
|
||
|
// FindProductOrders 分页查询 ProductOrder 记录
|
||
|
func FindProductOrders(page, pageSize int, query interface{}, args ...interface{}) []ProductOrder {
|
||
|
offset := (page - 1) * pageSize
|
||
|
var res []ProductOrder
|
||
|
DB.Table("product_order").Where(query, args...).Order("id desc").Offset(offset).Limit(pageSize).Find(&res)
|
||
|
return res
|
||
|
}
|
||
|
|
||
|
// DelProductOrder 删除 ProductOrder 记录
|
||
|
func DelProductOrder(query interface{}, args ...interface{}) error {
|
||
|
return DB.Where(query, args...).Delete(&ProductOrder{}).Error
|
||
|
}
|