This commit is contained in:
laodaming
2023-06-12 16:47:48 +08:00
parent ff05e127bd
commit b1393950f2
32 changed files with 729 additions and 196 deletions

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsAddress struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -16,3 +18,11 @@ type FsAddress struct {
Status *int64 `gorm:"default:1" json:"status"` // 1正常 0异常
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 1默认地址0非默认地址
}
type FsAddressModel struct {
db *gorm.DB
}
func NewFsAddressModel(db *gorm.DB) *FsAddressModel {
return &FsAddressModel{db}
}

View File

@@ -0,0 +1,42 @@
package gmodel
import (
"context"
"gorm.io/gorm"
)
type FsCanteenProduct struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
}
type FsCanteenProductModel struct {
db *gorm.DB
}
func NewFsCanteenProductModel(db *gorm.DB) *FsCanteenProductModel {
return &FsCanteenProductModel{db}
}
func (c *FsCanteenProductModel) GetAllByCanteenTypeId(ctx context.Context, typeId int64) (resp []FsCanteenProduct, err error) {
err = c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`canteen_type` = ? and `status` = ?", typeId, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return nil, err
}
func (c *FsCanteenProductModel) UpdateById(ctx context.Context, id int64, data *FsCanteenProduct) error {
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 {
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Where("`id` in (?) ", ids).Updates(&data).Error
}
func (c *FsCanteenProductModel) Create(ctx context.Context, data *FsCanteenProduct) error {
return c.db.WithContext(ctx).Model(&FsCanteenProduct{}).Create(data).Error
}

View File

@@ -0,0 +1,30 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
type FsCanteenType struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
Name *string `gorm:"default:''" json:"name"` // 餐厅名字
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
}
type FsCanteenTypeModel struct {
db *gorm.DB
}
func NewFsCanteenTypeModel(db *gorm.DB) *FsCanteenTypeModel {
return &FsCanteenTypeModel{db}
}
func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCanteenType, err error) {
err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Where("`id` = ? and `status` = ? ", id, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsCanteenType{}, err
}
return
}

View File

@@ -1,6 +1,9 @@
package gorm
package gmodel
import "database/sql"
import (
"database/sql"
"gorm.io/gorm"
)
type FsFaq struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -12,3 +15,10 @@ type FsFaq struct {
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Ctime *sql.NullInt64 `gorm:"default:0" json:"ctime"` // 添加时间
}
type FsFaqModel struct {
db *gorm.DB
}
func NewFsFaqModel(db *gorm.DB) *FsFaqModel {
return &FsFaqModel{db}
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsFont struct {
Id int64 `gorm:"primary_key" json:"id"` // id
@@ -7,3 +9,10 @@ type FsFont struct {
FilePath *string `gorm:"default:''" json:"file_path"` // 字体文件路径
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
}
type FsFontModel struct {
db *gorm.DB
}
func NewFsFontModel(db *gorm.DB) *FsFontModel {
return &FsFontModel{db}
}

View File

@@ -1,4 +1,9 @@
package gorm
package gmodel
import (
"context"
"gorm.io/gorm"
)
type FsProduct struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -31,3 +36,48 @@ type FsProduct struct {
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
SceneIds *string `gorm:"default:''" json:"scene_ids"` // 关联的场景id
}
type FsProductModel struct {
db *gorm.DB
}
func NewFsProductModel(db *gorm.DB) *FsProductModel {
return &FsProductModel{db}
}
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
db := p.db.Model(&FsProduct{}).
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 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 (p *FsProductModel) GetProductListByTypeIds(ctx context.Context, productTypes []int64, sort string) (resp []FsProduct, err error) {
db := p.db.WithContext(ctx).Model(&FsProductModel{}).Where("`type` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productTypes, 0, 1, 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
}
func (p *FsProductModel) GetRandomProductList(ctx context.Context, limit int) (resp []FsProduct, err error) {
err = p.db.WithContext(ctx).Model(&FsProductModel{}).
Where("`is_del` =? and `is_shelf` = ?", 0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsProductModel3dLight struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -7,3 +9,10 @@ type FsProductModel3dLight struct {
Status *int64 `gorm:"default:1" json:"status"` // 状态值1显示0删除
Ctime *int64 `gorm:"default:0" json:"ctime"` // 创建时间
}
type FsProductModel3dLightModel struct {
db *gorm.DB
}
func NewFsProductModel3dLightModel(db *gorm.DB) *FsProductModel3dLightModel {
return &FsProductModel3dLightModel{db}
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsProductModel3d struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -20,3 +22,10 @@ type FsProductModel3d struct {
Price *int64 `gorm:"default:0" json:"price"` // 仅配件用,配件的价格, 单位:美分
Sku *string `gorm:"default:''" json:"sku"` // sku
}
type FsProductModel3dModel struct {
db *gorm.DB
}
func NewFsProductModel3dModel(db *gorm.DB) *FsProductModel3dModel {
return &FsProductModel3dModel{db}
}

View File

@@ -1,4 +1,9 @@
package gorm
package gmodel
import (
"context"
"gorm.io/gorm"
)
type FsProductPrice struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -15,3 +20,34 @@ type FsProductPrice struct {
Status *int64 `gorm:"default:1" json:"status"` // 是否可用
IsDefault *int64 `gorm:"default:0" json:"is_default"` // 是否默认
}
type FsProductPriceModel struct {
db *gorm.DB
}
func NewFsProductPriceModel(db *gorm.DB) *FsProductPriceModel {
return &FsProductPriceModel{db}
}
type GetPriceListByProductIdsRsp struct {
ProductId int64 `json:"product_id"`
Price string `json:"price"`
}
func (p *FsProductPriceModel) GetPriceListByProductIds(ctx context.Context, productIds []int64) (resp []GetPriceListByProductIdsRsp, err error) {
if len(productIds) == 0 {
return nil, nil
}
db := p.db.WithContext(ctx).Model(&FsProductPriceModel{}).Select("product_id,group_concat(step_price) as price").
Where("`product_id` in (?) and `status` = ? group by product_id", productIds, 1)
if err = db.Find(&resp).Error; err != nil {
return nil, err
}
return
}
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
err = p.db.WithContext(ctx).Model(&FsProductPriceModel{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@@ -0,0 +1,61 @@
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) {
db := s.db.Model(&FsProductSizeModel{}).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(&FsProductSizeModel{}).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(&FsProductSizeModel{}).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
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsProductTemplateTags struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
@@ -6,3 +8,10 @@ type FsProductTemplateTags struct {
Status *int64 `gorm:"default:1" json:"status"` // 状态 1可用 0不可用
CreateAt *int64 `gorm:"default:0" json:"create_at"` // 创建时间
}
type FsProductTemplateTagsModel struct {
db *gorm.DB
}
func NewFsProductTemplateTagsModel(db *gorm.DB) *FsProductTemplateTagsModel {
return &FsProductTemplateTagsModel{db}
}

View File

@@ -1,4 +1,9 @@
package gorm
package gmodel
import (
"context"
"gorm.io/gorm"
)
type FsProductTemplateV2 struct {
Id int64 `gorm:"primary_key" json:"id"`
@@ -18,3 +23,17 @@ type FsProductTemplateV2 struct {
Tag *string `gorm:"default:''" json:"tag"` // 标签(用户自填)
IsDel *int64 `gorm:"default:0" json:"is_del"` // 是否删除 1删除
}
type FsProductTemplateV2Model struct {
db *gorm.DB
}
func NewFsProductTemplateV2Model(db *gorm.DB) *FsProductTemplateV2Model {
return &FsProductTemplateV2Model{db}
}
func (t *FsProductTemplateV2Model) FindAllByProductIds(ctx context.Context, productIds []int64) (resp []FsProductTemplateV2, err error) {
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2Model{}).Where("`id` in (?) and `is_del` = ? and `status` = ?", productIds, 0, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsQrcodeSet struct {
Id int64 `gorm:"primary_key" json:"id"` // id
@@ -14,3 +16,10 @@ type FsQrcodeSet struct {
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Utime *int64 `gorm:"default:0" json:"utime"` // 更新时间
}
type FsQrcodeSetModel struct {
db *gorm.DB
}
func NewFsQrcodeSetModel(db *gorm.DB) *FsQrcodeSetModel {
return &FsQrcodeSetModel{db}
}

View File

@@ -1,4 +1,6 @@
package gorm
package gmodel
import "gorm.io/gorm"
type FsStandardLogo struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
@@ -7,3 +9,10 @@ type FsStandardLogo struct {
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Status *int64 `gorm:"default:1" json:"status"` // 状态 1正常 0删除
}
type FsStandardLogoModel struct {
db *gorm.DB
}
func NewFsStandardLogoModel(db *gorm.DB) *FsStandardLogoModel {
return &FsStandardLogoModel{db}
}

View File

@@ -1,4 +1,10 @@
package gorm
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
type FsTags struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
@@ -13,3 +19,31 @@ type FsTags struct {
RecommendProduct *string `gorm:"default:''" json:"recommend_product"` // 推荐产品id例如: 1,3,4,5
RecommendProductSort *string `gorm:"default:''" json:"recommend_product_sort"` // 推荐排序例如:1324
}
type FsTagsModel struct {
db *gorm.DB
}
func NewFsTagsModel(db *gorm.DB) *FsTagsModel {
return &FsTagsModel{db}
}
func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err error) {
err = t.db.WithContext(ctx).Model(&FsTagsModel{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsTags{}, err
}
return
}
func (t *FsTagsModel) GetAllByIds(ctx context.Context, ids []int64) (resp []FsTags, err error) {
err = t.db.WithContext(ctx).Model(&FsTagsModel{}).Where("`id` in(?) and `status` = ?", ids, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}
func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
err = t.db.Model(&FsTagsModel{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@@ -1,4 +1,10 @@
package gorm
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
type FsUser struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
@@ -28,3 +34,18 @@ type FsUser struct {
IsLowRendering int64 `gorm:"default:0" json:"is_low_rendering"` // 是否开启低渲染模型渲染
IsRemoveBg int64 `gorm:"default:1" json:"is_remove_bg"` // 用户上传logo是否去除背景
}
type FsUserModel struct {
db *gorm.DB
}
func NewFsUserModel(db *gorm.DB) *FsUserModel {
return &FsUserModel{db}
}
func (u *FsUserModel) FindOne(ctx context.Context, id int64) (resp FsUser, err error) {
err = u.db.WithContext(ctx).Model(&FsUserModel{}).Where("`id` = ? and is_del = ?", id, 0).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsUser{}, err
}
return
}

View File

@@ -1,12 +0,0 @@
package gorm
type FsCanteenProduct struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
CanteenType *int64 `gorm:"default:0" json:"canteen_type"` // 餐厅类别id
ProductId *int64 `gorm:"default:0" json:"product_id"` // 产品id
SizeId *int64 `gorm:"default:0" json:"size_id"` // 尺寸id
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
Sid *string `gorm:"default:''" json:"sid"` // 前端带入的id
}

View File

@@ -1,9 +0,0 @@
package gorm
type FsCanteenType struct {
Id int64 `gorm:"primary_key" json:"id"` // ID
Name *string `gorm:"default:''" json:"name"` // 餐厅名字
Sort *int64 `gorm:"default:0" json:"sort"` // 排序
Status *int64 `gorm:"default:1" json:"status"` // 状态位 1启用0停用
Ctime *int64 `gorm:"default:0" json:"ctime"` // 添加时间
}

View File

@@ -1,14 +0,0 @@
package 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否
}