package models import ( "kefu/types" ) // VirtualProduct 模型对应于虚拟产品表 type VirtualProduct struct { ID uint `gorm:"primary_key" json:"id"` KefuName string `gorm:"type:varchar(500);not null;default:''" json:"kefu_name"` EntId string `gorm:"type:varchar(500);not null;default:''" json:"ent_id"` ProductName string `gorm:"type:varchar(500);not null;default:''" json:"product_name"` Payment string `gorm:"type:varchar(500);not null;default:''" json:"payment"` ProductCategory string `gorm:"type:varchar(100);not null;default:''" json:"product_category"` Description string `gorm:"type:text" json:"description"` Price int `gorm:"type:int;not null;default:0;comment:'金额'" json:"price"` ProductImg string `gorm:"type:varchar(1000);not null;default:''" json:"product_img"` ResourceLink string `gorm:"type:varchar(1000);not null;default:''" json:"resource_link"` IsActive int8 `gorm:"type:tinyint;not null;default:1;comment:'在线状态,1在售,2下架'" json:"is_active"` CreatedAt types.Time `gorm:"type:timestamp;default:current_timestamp" json:"created_at"` UpdatedAt types.Time `gorm:"type:timestamp;default:current_timestamp;update:current_timestamp" json:"updated_at"` } // CountVirtualProducts 返回符合条件的 VirtualProduct 记录数量 func CountVirtualProducts(query interface{}, args ...interface{}) int64 { var count int64 db := DB.Model(&VirtualProduct{}).Where(query, args...) db.Count(&count) return count } // FindVirtualProduct 查询单个 VirtualProduct 记录 func FindVirtualProduct(query interface{}, args ...interface{}) VirtualProduct { var product VirtualProduct db := DB.Model(&VirtualProduct{}).Where(query, args...) db.First(&product) return product } // SaveVirtualProduct 更新 VirtualProduct 记录 func (p *VirtualProduct) SaveVirtualProduct(query interface{}, args ...interface{}) error { db := DB.Model(&VirtualProduct{}).Where(query, args...).Updates(p) return db.Error } // AddVirtualProduct 添加新的 VirtualProduct 记录 func (p *VirtualProduct) AddVirtualProduct() error { return DB.Create(p).Error } // FindVirtualProducts 分页查询 VirtualProduct 记录 func FindVirtualProducts(page, pageSize int, query interface{}, args ...interface{}) []VirtualProduct { var products []VirtualProduct limit := pageSize offset := (page - 1) * pageSize DB.Model(&VirtualProduct{}).Where(query, args...).Order("id desc").Limit(limit).Offset(offset).Find(&products) return products } // DeleteVirtualProduct 删除 VirtualProduct 记录 func DeleteVirtualProduct(query interface{}, args ...interface{}) error { return DB.Where(query, args...).Delete(&VirtualProduct{}).Error }