fusenapi/model/gmodel/fsproductsizemodel.go
laodaming d455f3b256 fix
2023-06-13 12:15:06 +08:00

65 lines
2.2 KiB
Go
Executable File

package gmodel
import (
"context"
"gorm.io/gorm"
)
type FsProductSize struct {
Id int64 `gorm:"primary_key" json:"id"`
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
Title *string `gorm:"default:''" json:"title"` // 标题 10*10*20
Cover *string `gorm:"default:''" json:"cover"` // 封面图
CoverImg *string `gorm:"default:''" json:"cover_img"` // 背景图
Capacity *string `gorm:"default:''" json:"capacity"` // 自己填的尺寸名称
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1显示 0删除
Sort *int64 `gorm:"default:50" json:"sort"` // 排序
Remark *string `gorm:"default:''" json:"remark"` // 备注信息
PartsCanDeleted *int64 `gorm:"default:1" json:"parts_can_deleted"` // 配件是否可移除 1是0否
}
type FsProductSizeModel struct {
db *gorm.DB
}
func NewFsProductSizeModel(db *gorm.DB) *FsProductSizeModel {
return &FsProductSizeModel{db}
}
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {
if len(ids) == 0 {
return
}
db := s.db.Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
switch sort {
case "sort-asc":
db = db.Order("`sort` ASC")
case "sort-desc":
db = db.Order("`sort` DESC")
}
if err = db.Find(&resp).Error; err != nil {
return nil, err
}
return
}
func (s *FsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int64, err error) {
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`status` = ? ", status).Count(&total).Error
if err != nil {
return 0, err
}
return
}
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
switch sort {
case "sort-asc":
db = db.Order("`sort` ASC")
case "sort-desc":
db = db.Order("`sort` DESC")
}
err = db.Find(&resp).Error
if err != nil {
return nil, err
}
return
}