2023-06-12 08:47:48 +00:00
|
|
|
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) {
|
2023-06-12 09:47:20 +00:00
|
|
|
db := s.db.Model(&FsProductSize{}).Where("`id` in (?) and `status` = ?", ids, 1)
|
2023-06-12 08:47:48 +00:00
|
|
|
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) {
|
2023-06-12 09:47:20 +00:00
|
|
|
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`status` = ? ", status).Count(&total).Error
|
2023-06-12 08:47:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
func (s *FsProductSizeModel) GetAllByProductIds(ctx context.Context, productIds []int64, sort string) (resp []FsProductSize, err error) {
|
2023-06-12 09:47:20 +00:00
|
|
|
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`product_id` in(?) and `status` = ?", productIds, 1)
|
2023-06-12 08:47:48 +00:00
|
|
|
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
|
|
|
|
}
|