This commit is contained in:
laodaming 2023-06-16 14:52:45 +08:00
parent 3d7eef18d0
commit 68c431bda2
16 changed files with 150 additions and 114 deletions

23
model/gmodel/fs_address_gen.go Executable file
View File

@ -0,0 +1,23 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (resp FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`id` = ? and `user_id` = ? and `status` = ? ", id, userId, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsAddress{}, err
}
return resp, nil
}
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`id` DESC").Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -1,9 +1,6 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
@ -31,18 +28,3 @@ type FsAddressModel struct {
func NewFsAddressModel(db *gorm.DB) *FsAddressModel {
return &FsAddressModel{db}
}
func (a *FsAddressModel) GetOne(ctx context.Context, id int64, userId int64) (resp FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`id` = ? and `user_id` = ? and `status` = ? ", id, userId, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsAddress{}, err
}
return resp, nil
}
func (a *FsAddressModel) GetUserAllAddress(ctx context.Context, userId int64) (resp []FsAddress, err error) {
err = a.db.WithContext(ctx).Model(&FsAddress{}).Where("`user_id` = ? and `status` = ?", userId, 1).Order("`id` DESC").Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,24 @@
package gmodel
import (
"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}
}

View File

@ -2,28 +2,8 @@ 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 {

View File

@ -15,8 +15,15 @@ type FsGetTypeCanteenType struct {
// TODO: 使用model的属性做你想做的
func (c *FsCanteenTypeModel) FindAllGetType(ctx context.Context, id int64) (resp []*FsGetTypeCanteenType, err error) {
func (c *FsCanteenTypeModel) FindAllGetType(ctx context.Context) (resp []*FsGetTypeCanteenType, err error) {
err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Select("id,name").Order("sort desc").Where("`status` = ?", 1).Find(&resp).Error
if err != nil {
return resp, err
}
return resp, nil
}
func (c *FsCanteenTypeModel) FindOne(ctx context.Context, id int64) (resp FsCanteenType, err error) {
err = c.db.WithContext(ctx).Model(&FsCanteenType{}).Where("`id` = ?", id).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return resp, err
}

34
model/gmodel/fs_cart_gen.go Executable file
View File

@ -0,0 +1,34 @@
// Code generated by goctl. DO NOT EDIT.
package gmodel
import (
"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}
}

View File

@ -6,35 +6,8 @@ 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

View File

@ -1,7 +1,6 @@
package gmodel
import (
"context"
"gorm.io/gorm"
)
@ -21,11 +20,3 @@ type FsMapLibraryModel struct {
func NewFsMapLibraryModel(db *gorm.DB) *FsMapLibraryModel {
return &FsMapLibraryModel{db}
}
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context) (resp []FsMapLibrary, err error) {
err = ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 0).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,11 @@
package gmodel
import "context"
func (ml *FsMapLibraryModel) GetAllEnabledList(ctx context.Context) (resp []FsMapLibrary, err error) {
err = ml.db.WithContext(ctx).Model(&FsMapLibrary{}).Where("`status` = ?", 0).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -1,7 +1,6 @@
package gmodel
import (
"context"
"gorm.io/gorm"
)
@ -19,10 +18,3 @@ type FsStandardLogoModel struct {
func NewFsStandardLogoModel(db *gorm.DB) *FsStandardLogoModel {
return &FsStandardLogoModel{db}
}
func (l *FsStandardLogoModel) GetAll(ctx context.Context) (resp []FsStandardLogo, err error) {
err = l.db.WithContext(ctx).Model(&FsStandardLogo{}).Where("`status` = ? ", 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -0,0 +1,13 @@
package gmodel
import (
"context"
)
func (l *FsStandardLogoModel) GetAll(ctx context.Context) (resp []FsStandardLogo, err error) {
err = l.db.WithContext(ctx).Model(&FsStandardLogo{}).Where("`status` = ? ", 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -1,8 +1,6 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
@ -26,27 +24,3 @@ type FsTagsModel struct {
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(&FsTags{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsTags{}, err
}
return resp, nil
}
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
}
return
}
func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
err = t.db.Model(&FsTags{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

32
model/gmodel/fs_tags_logic.go Executable file
View File

@ -0,0 +1,32 @@
package gmodel
import (
"context"
"errors"
"gorm.io/gorm"
)
func (t *FsTagsModel) FindOne(ctx context.Context, id int64) (resp FsTags, err error) {
err = t.db.WithContext(ctx).Model(&FsTags{}).Where("`id` = ? and `status` = ?", id, 1).First(&resp).Error
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
return FsTags{}, err
}
return resp, nil
}
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
}
return
}
func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTags, err error) {
err = t.db.Model(&FsTags{}).Where("`level` = ? and `status` = ?", level, 1).Find(&resp).Error
if err != nil {
return nil, err
}
return
}

View File

@ -33,7 +33,7 @@ func (l *UserGetTypeLogic) UserGetType(req *types.Request, userinfo *auth.UserIn
}
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindAllGetType(l.ctx, userinfo.UserId)
data, err := gmodel.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindAllGetType(l.ctx)
if err != nil {
logx.Error(err)
return

View File

@ -55,7 +55,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
}
//查询用户信息
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
userInfo, err := userModel.FindOne(l.ctx, userinfo.UserId)
userInfo, err := userModel.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
@ -150,7 +150,7 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, useri
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(userInfo.IsThousandFace),
IsThousandFace: int(*userInfo.IsThousandFace),
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,

View File

@ -32,7 +32,7 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
}
//获取用户信息
userModel := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := userModel.FindOne(l.ctx, userInfo.UserId)
user, err := userModel.FindUserById(l.ctx, userInfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get user info")
@ -68,7 +68,7 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(user.IsThousandFace),
IsThousandFace: int(*user.IsThousandFace),
Cover: *v.Cover,
CoverImg: *v.CoverImg,
CoverDefault: *v.CoverImg,