1
This commit is contained in:
parent
3698705975
commit
f9de30a838
|
@ -12,6 +12,7 @@ type FsMerchantCategory struct {
|
|||
Icon *string `gorm:"default:'';" json:"icon"` // 图标
|
||||
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品
|
||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||
IsDefault *int64 `gorm:"default:0;" json:"is_default"` // 是否是默认商家类型0非1是
|
||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态
|
||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
||||
}
|
||||
|
|
|
@ -14,8 +14,10 @@ func (m *FsMerchantCategoryModel) FindOne(ctx context.Context, id int64) (resp *
|
|||
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
func (m *FsMerchantCategoryModel) FindRandOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ?", 1).Order("RAND()").Take(&resp).Error
|
||||
|
||||
// 获取默认那个
|
||||
func (m *FsMerchantCategoryModel) FindDefualtOne(ctx context.Context) (resp *FsMerchantCategory, err error) {
|
||||
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("status = ? and is_default = ?", 1, 1).Take(&resp).Error
|
||||
return resp, err
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,11 @@ import "gorm.io/gorm"
|
|||
|
||||
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
|
||||
type AllModelsGen struct {
|
||||
CasbinRule *CasbinRuleModel // casbin_rule
|
||||
FsAddress *FsAddressModel // fs_address 用户地址表
|
||||
FsAdminAuthRole *FsAdminAuthRoleModel // fs_admin_auth_role 后台--角色表
|
||||
FsAdminDepartment *FsAdminDepartmentModel // fs_admin_department 后台--部门表
|
||||
FsAdminMenu *FsAdminMenuModel // fs_admin_menu 后台--菜单表
|
||||
FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息
|
||||
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
|
||||
FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表
|
||||
|
@ -103,7 +107,11 @@ type AllModelsGen struct {
|
|||
|
||||
func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||
models := &AllModelsGen{
|
||||
CasbinRule: NewCasbinRuleModel(gdb),
|
||||
FsAddress: NewFsAddressModel(gdb),
|
||||
FsAdminAuthRole: NewFsAdminAuthRoleModel(gdb),
|
||||
FsAdminDepartment: NewFsAdminDepartmentModel(gdb),
|
||||
FsAdminMenu: NewFsAdminMenuModel(gdb),
|
||||
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
|
||||
FsAuthItem: NewFsAuthItemModel(gdb),
|
||||
FsAuthItemChild: NewFsAuthItemChildModel(gdb),
|
||||
|
|
|
@ -54,16 +54,23 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
|||
//选了商家类型
|
||||
if req.MerchantType > 0 {
|
||||
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType)
|
||||
} else {
|
||||
//随机获取一个商家类型
|
||||
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx)
|
||||
}
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found")
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the merchant category is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category")
|
||||
}
|
||||
} else {
|
||||
//获取默认的那个
|
||||
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindDefualtOne(l.ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the default merchant category is not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default merchant category")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant type info")
|
||||
}
|
||||
if *merchantInfo.RecommendProduct == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||
|
|
Loading…
Reference in New Issue
Block a user