From 68c431bda2932f8ce3d52f0c3bde1534f58d1e50 Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 16 Jun 2023 14:52:45 +0800 Subject: [PATCH] fix --- model/gmodel/fs_address_gen.go | 23 +++++++++++++ ...{fsaddressmodel.go => fs_address_logic.go} | 18 ---------- model/gmodel/fs_canteen_product_gen.go | 24 +++++++++++++ ...ctmodel.go => fs_canteen_product_logic.go} | 20 ----------- model/gmodel/fs_canteen_type_logic.go | 9 ++++- model/gmodel/fs_cart_gen.go | 34 +++++++++++++++++++ .../{fscartmodel.go => fs_cart_logic.go} | 27 --------------- ...plibrarymodel.go => fs_map_library_gen.go} | 9 ----- model/gmodel/fs_map_library_logic.go | 11 ++++++ ...rdlogomodel.go => fs_standard_logo_gen.go} | 8 ----- model/gmodel/fs_standard_logo_logic.go | 13 +++++++ .../gmodel/{fstagsmodel.go => fs_tags_gen.go} | 26 -------------- model/gmodel/fs_tags_logic.go | 32 +++++++++++++++++ .../internal/logic/usergettypelogic.go | 2 +- .../internal/logic/getproductlistlogic.go | 4 +-- .../logic/getsuccessrecommandlogic.go | 4 +-- 16 files changed, 150 insertions(+), 114 deletions(-) create mode 100755 model/gmodel/fs_address_gen.go rename model/gmodel/{fsaddressmodel.go => fs_address_logic.go} (63%) create mode 100755 model/gmodel/fs_canteen_product_gen.go rename model/gmodel/{fscanteenproductmodel.go => fs_canteen_product_logic.go} (54%) create mode 100755 model/gmodel/fs_cart_gen.go rename model/gmodel/{fscartmodel.go => fs_cart_logic.go} (66%) rename model/gmodel/{fsmaplibrarymodel.go => fs_map_library_gen.go} (71%) create mode 100755 model/gmodel/fs_map_library_logic.go rename model/gmodel/{fsstandardlogomodel.go => fs_standard_logo_gen.go} (68%) create mode 100755 model/gmodel/fs_standard_logo_logic.go rename model/gmodel/{fstagsmodel.go => fs_tags_gen.go} (60%) create mode 100755 model/gmodel/fs_tags_logic.go diff --git a/model/gmodel/fs_address_gen.go b/model/gmodel/fs_address_gen.go new file mode 100755 index 00000000..c8bf6600 --- /dev/null +++ b/model/gmodel/fs_address_gen.go @@ -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 +} diff --git a/model/gmodel/fsaddressmodel.go b/model/gmodel/fs_address_logic.go similarity index 63% rename from model/gmodel/fsaddressmodel.go rename to model/gmodel/fs_address_logic.go index 3eb8a1b9..b1931af7 100755 --- a/model/gmodel/fsaddressmodel.go +++ b/model/gmodel/fs_address_logic.go @@ -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 -} diff --git a/model/gmodel/fs_canteen_product_gen.go b/model/gmodel/fs_canteen_product_gen.go new file mode 100755 index 00000000..dbabdcbc --- /dev/null +++ b/model/gmodel/fs_canteen_product_gen.go @@ -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} +} diff --git a/model/gmodel/fscanteenproductmodel.go b/model/gmodel/fs_canteen_product_logic.go similarity index 54% rename from model/gmodel/fscanteenproductmodel.go rename to model/gmodel/fs_canteen_product_logic.go index 5badcf18..6114dd23 100755 --- a/model/gmodel/fscanteenproductmodel.go +++ b/model/gmodel/fs_canteen_product_logic.go @@ -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 { diff --git a/model/gmodel/fs_canteen_type_logic.go b/model/gmodel/fs_canteen_type_logic.go index 4a338b2b..7ea6b846 100644 --- a/model/gmodel/fs_canteen_type_logic.go +++ b/model/gmodel/fs_canteen_type_logic.go @@ -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 } diff --git a/model/gmodel/fs_cart_gen.go b/model/gmodel/fs_cart_gen.go new file mode 100755 index 00000000..c9265ebd --- /dev/null +++ b/model/gmodel/fs_cart_gen.go @@ -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} +} diff --git a/model/gmodel/fscartmodel.go b/model/gmodel/fs_cart_logic.go similarity index 66% rename from model/gmodel/fscartmodel.go rename to model/gmodel/fs_cart_logic.go index 4e613e70..9d0d3b27 100755 --- a/model/gmodel/fscartmodel.go +++ b/model/gmodel/fs_cart_logic.go @@ -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 diff --git a/model/gmodel/fsmaplibrarymodel.go b/model/gmodel/fs_map_library_gen.go similarity index 71% rename from model/gmodel/fsmaplibrarymodel.go rename to model/gmodel/fs_map_library_gen.go index 58c02db6..6bf318a2 100755 --- a/model/gmodel/fsmaplibrarymodel.go +++ b/model/gmodel/fs_map_library_gen.go @@ -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 -} diff --git a/model/gmodel/fs_map_library_logic.go b/model/gmodel/fs_map_library_logic.go new file mode 100755 index 00000000..df7755bd --- /dev/null +++ b/model/gmodel/fs_map_library_logic.go @@ -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 +} diff --git a/model/gmodel/fsstandardlogomodel.go b/model/gmodel/fs_standard_logo_gen.go similarity index 68% rename from model/gmodel/fsstandardlogomodel.go rename to model/gmodel/fs_standard_logo_gen.go index 621f8c4b..d18d9079 100755 --- a/model/gmodel/fsstandardlogomodel.go +++ b/model/gmodel/fs_standard_logo_gen.go @@ -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 -} diff --git a/model/gmodel/fs_standard_logo_logic.go b/model/gmodel/fs_standard_logo_logic.go new file mode 100755 index 00000000..e7f5ea56 --- /dev/null +++ b/model/gmodel/fs_standard_logo_logic.go @@ -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 +} diff --git a/model/gmodel/fstagsmodel.go b/model/gmodel/fs_tags_gen.go similarity index 60% rename from model/gmodel/fstagsmodel.go rename to model/gmodel/fs_tags_gen.go index e723fa68..dcc19b51 100755 --- a/model/gmodel/fstagsmodel.go +++ b/model/gmodel/fs_tags_gen.go @@ -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 -} diff --git a/model/gmodel/fs_tags_logic.go b/model/gmodel/fs_tags_logic.go new file mode 100755 index 00000000..5cdf6c55 --- /dev/null +++ b/model/gmodel/fs_tags_logic.go @@ -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 +} diff --git a/server/home-user-auth/internal/logic/usergettypelogic.go b/server/home-user-auth/internal/logic/usergettypelogic.go index 6a894952..72663f99 100644 --- a/server/home-user-auth/internal/logic/usergettypelogic.go +++ b/server/home-user-auth/internal/logic/usergettypelogic.go @@ -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 diff --git a/server/product/internal/logic/getproductlistlogic.go b/server/product/internal/logic/getproductlistlogic.go index e7fbf8d5..7f3e96df 100644 --- a/server/product/internal/logic/getproductlistlogic.go +++ b/server/product/internal/logic/getproductlistlogic.go @@ -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, diff --git a/server/product/internal/logic/getsuccessrecommandlogic.go b/server/product/internal/logic/getsuccessrecommandlogic.go index 7e833544..7f25afaa 100644 --- a/server/product/internal/logic/getsuccessrecommandlogic.go +++ b/server/product/internal/logic/getsuccessrecommandlogic.go @@ -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,