This commit is contained in:
laodaming
2023-06-13 12:15:06 +08:00
parent 8d190f0097
commit d455f3b256
24 changed files with 905 additions and 15 deletions

View File

@@ -35,6 +35,9 @@ func (c *FsCanteenProductModel) UpdateById(ctx context.Context, id int64, data *
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` = ? ", id).Updates(&data).Error
}
func (c *FsCanteenProductModel) UpdateByIdArr(ctx context.Context, ids []int64, data *FsCanteenProduct) error {
if len(ids) == 0 {
return nil
}
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
}
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {

88
model/gmodel/fscartmodel.go Executable file
View File

@@ -0,0 +1,88 @@
// Code generated by goctl. DO NOT EDIT.
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
"time"
)
type FsCart struct {
Id int64 `gorm:"primary_key" json:"id"` // id
UserId *int64 `gorm:"default:0" json:"user_id"` // 用户ID
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
TemplateId *int64 `gorm:"default:0" json:"template_id"` // 模板ID
PriceId *int64 `gorm:"default:0" json:"price_id"` // 价格ID
MaterialId *int64 `gorm:"default:0" json:"material_id"` // 材质ID
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
BuyNum *int64 `gorm:"default:0" json:"buy_num"` // 购买数量
Cover *string `gorm:"default:''" json:"cover"` // 截图
DesignId *int64 `gorm:"default:0" json:"design_id"` // 设计ID
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Status *int64 `gorm:"default:1" json:"status"` // 状态位
OptionalId *int64 `gorm:"default:0" json:"optional_id"` // 选项ID
IsCheck *int64 `gorm:"default:0" json:"is_check"` // 是否选中状态0未选中1选中
TsTime *time.Time `gorm:"" json:"ts_time"`
IsEmail *int64 `gorm:"default:0" json:"is_email"` // 是否发送邮件
}
type FsCartModel struct {
db *gorm.DB
}
func NewFsCartModel(db *gorm.DB) *FsCartModel {
return &FsCartModel{db}
}
type FindOneCartByParamsReq struct {
UserId *int64
ProductId *int64
TemplateId *int64
PriceId *int64
DesignId *int64
MaterialId *int64
Status *int64
}
func (c *FsCartModel) FindOne(ctx context.Context, id int64) (resp FsCart, err error) {
err = c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCart{}, err
}
return
}
func (c *FsCartModel) FindOneCartByParams(ctx context.Context, req FindOneCartByParamsReq) (resp FsCart, err error) {
db := c.db.WithContext(ctx).Model(&FsCart{})
if req.UserId != nil {
db = db.Where("`user_id` = ?", req.UserId)
}
if req.ProductId != nil {
db = db.Where("`product_id` = ?", req.ProductId)
}
if req.TemplateId != nil {
db = db.Where("`template_id` = ?", req.TemplateId)
}
if req.PriceId != nil {
db = db.Where("`price_id` = ?", req.ProductId)
}
if req.DesignId != nil {
db = db.Where("`design_id` = ?", req.DesignId)
}
if req.MaterialId != nil {
db = db.Where("`material_id` = ?", req.MaterialId)
}
if req.Status != nil {
db = db.Where("`status` = ?", req.Status)
}
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCart{}, err
}
return
}
func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
return c.db.WithContext(ctx).Model(&FsCart{}).Create(data).Error
}
func (c *FsCartModel) Update(ctx context.Context, id int64, data FsCart) error {
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ?", id).Updates(data).Error
}

View File

@@ -0,0 +1,42 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
"time"
)
type FsProductDesign struct {
Id int64 `gorm:"primary_key" json:"id"`
Sn *string `gorm:"default:''" json:"sn"` // 唯一标识
UserId *int64 `gorm:"default:0" json:"user_id"` // 用户ID
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品ID
TemplateId *int64 `gorm:"default:0" json:"template_id"` // 模型ID
MaterialId *int64 `gorm:"default:0" json:"material_id"` // 材质ID
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸ID
OptionalId *int64 `gorm:"default:0" json:"optional_id"` // 选项ID
Cover *string `gorm:"default:''" json:"cover"` // 封面图
Info *string `gorm:"default:''" json:"info"` // 保留的设计信息
Utime *time.Time `gorm:"" json:"utime"` // 更新时间
Status *int64 `gorm:"default:1" json:"status"` // 状态
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 0未删除 1删除
IsPay *int64 `gorm:"default:0" json:"is_pay"` // 是否已有支付 0 未 1 有
LogoColor *string `gorm:"default:''" json:"logo_color"` // logo图片备选项
PageGuid *string `gorm:"default:''" json:"page_guid"` // 页面识别id
}
type FsProductDesignModel struct {
db *gorm.DB
}
func NewFsProductDesignModel(db *gorm.DB) *FsProductDesignModel {
return &FsProductDesignModel{db}
}
func (d *FsProductDesignModel) FindOneBySn(ctx context.Context, sn string) (resp FsProductDesign, err error) {
err = d.db.WithContext(ctx).Model(&FsProductDesign{}).Where("`sn` = ? and `status` = ?", sn, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductDesign{}, err
}
return
}

View File

@@ -45,6 +45,9 @@ func NewFsProductModel(db *gorm.DB) *FsProductModel {
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
if len(productIds) == 0 {
return
}
db := p.db.Model(&FsProduct{}).
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
switch sort {
@@ -60,6 +63,9 @@ func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []i
}
func (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
if len(productTypes) == 0 {
return
}
db := p.db.WithContext(ctx).Model(&FsProduct{}).Where("`type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productTypes, 0, 1, 1)
switch sort {
case "sort-asc":

View File

@@ -2,6 +2,7 @@ package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
@@ -45,9 +46,39 @@ func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, prod
return
}
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
if len(sizeIds) == 0 {
return
}
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}
type FindOneProductPriceByParamsReq struct {
ProductId *int64
MaterialId *int64
SizeId *int64
Status *int64
}
func (p *FsProductPriceModel) FindOneProductPriceByParams(ctx context.Context, req FindOneProductPriceByParamsReq) (resp FsProductPrice, err error) {
db := p.db.WithContext(ctx).Model(&FsProductPrice{})
if req.ProductId != nil {
db = db.Where("`product_id` = ?", *req.ProductId)
}
if req.MaterialId != nil {
db = db.Where("`material_id` = ?", *req.MaterialId)
}
if req.SizeId != nil {
db = db.Where("`size_id` = ?", *req.SizeId)
}
if req.Status != nil {
db = db.Where("`status` = ?", *req.Status)
}
if err = db.First(&resp).Error; err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsProductPrice{}, err
}
return
}

View File

@@ -26,6 +26,9 @@ func NewFsProductSizeModel(db *gorm.DB) *FsProductSizeModel {
}
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":

View File

@@ -31,6 +31,9 @@ func NewFsProductTemplateV2Model(db *gorm.DB) *FsProductTemplateV2Model {
return &FsProductTemplateV2Model{db}
}
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
if len(productIds) == 0 {
return
}
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
if err != nil {
return nil, err

View File

@@ -34,6 +34,9 @@ func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err e
return
}
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
if len(ids) == 0 {
return
}
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
if err != nil {
return nil, err