fusenapi/model/gmodel/fscartmodel.go

92 lines
3.2 KiB
Go
Raw Normal View History

2023-06-13 04:15:06 +00:00
// 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
}
2023-06-13 05:07:09 +00:00
return resp, nil
2023-06-13 04:15:06 +00:00
}
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 {
2023-06-13 05:07:09 +00:00
db = db.Where("`price_id` = ?", req.PriceId)
2023-06-13 04:15:06 +00:00
}
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
}
2023-06-13 05:07:09 +00:00
return resp, nil
2023-06-13 04:15:06 +00:00
}
func (c *FsCartModel) Create(ctx context.Context, data FsCart) error {
2023-06-13 05:07:09 +00:00
return c.db.WithContext(ctx).Model(&FsCart{}).Create(&data).Error
2023-06-13 04:15:06 +00:00
}
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
}
2023-06-13 06:13:40 +00:00
func (c *FsCartModel) UpdateByIdUserId(ctx context.Context, id int64, userId int64, data FsCart) error {
return c.db.WithContext(ctx).Model(&FsCart{}).Where("`id` = ? and `user_id` = ?", id, userId).Updates(data).Error
}