Merge branch 'develop' of gitee.com:fusenpack/fusenapi into develop
This commit is contained in:
commit
2efc0af5e0
|
@ -37,7 +37,7 @@ func InitMysql(sourceMysql string) *gorm.DB {
|
||||||
sqlDB.SetMaxIdleConns(4)
|
sqlDB.SetMaxIdleConns(4)
|
||||||
|
|
||||||
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
// SetMaxOpenConns 设置打开数据库连接的最大数量。
|
||||||
sqlDB.SetMaxOpenConns(10)
|
sqlDB.SetMaxOpenConns(25)
|
||||||
|
|
||||||
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
// SetConnMaxLifetime 设置了连接可复用的最大时间。
|
||||||
sqlDB.SetConnMaxLifetime(time.Minute * 20)
|
sqlDB.SetConnMaxLifetime(time.Minute * 20)
|
||||||
|
|
24
model/gmodel/casbin_rule_gen.go
Normal file
24
model/gmodel/casbin_rule_gen.go
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
// casbin_rule
|
||||||
|
type CasbinRule struct {
|
||||||
|
PType *string `gorm:"default:'';" json:"p_type"` //
|
||||||
|
V0 *string `gorm:"default:'';" json:"v0"` //
|
||||||
|
V1 *string `gorm:"default:'';" json:"v1"` //
|
||||||
|
V2 *string `gorm:"default:'';" json:"v2"` //
|
||||||
|
V3 *string `gorm:"default:'';" json:"v3"` //
|
||||||
|
V4 *string `gorm:"default:'';" json:"v4"` //
|
||||||
|
V5 *string `gorm:"default:'';" json:"v5"` //
|
||||||
|
}
|
||||||
|
type CasbinRuleModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCasbinRuleModel(db *gorm.DB) *CasbinRuleModel {
|
||||||
|
return &CasbinRuleModel{db: db, name: "casbin_rule"}
|
||||||
|
}
|
2
model/gmodel/casbin_rule_logic.go
Normal file
2
model/gmodel/casbin_rule_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package gmodel
|
||||||
|
// TODO: 使用model的属性做你想做的
|
33
model/gmodel/fs_admin_auth_role_gen.go
Normal file
33
model/gmodel/fs_admin_auth_role_gen.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fs_admin_auth_role 后台--角色表
|
||||||
|
type FsAdminAuthRole struct {
|
||||||
|
Id int64 `gorm:"primary_key;default:0;" json:"id"` // 序号
|
||||||
|
RolePid *int64 `gorm:"default:0;" json:"role_pid"` // 上级角色
|
||||||
|
RoleName *string `gorm:"default:'';" json:"role_name"` //
|
||||||
|
DataAuthType *int64 `gorm:"default:1;" json:"data_auth_type"` // 数据权限类型
|
||||||
|
DataAuth *string `gorm:"default:'';" json:"data_auth"` //
|
||||||
|
Status *int64 `gorm:"default:2;" json:"status"` // 状态:1=启用,2=停用
|
||||||
|
Remark *string `gorm:"default:'';" json:"remark"` //
|
||||||
|
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
|
||||||
|
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
|
||||||
|
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
|
||||||
|
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
|
||||||
|
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
|
||||||
|
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
|
||||||
|
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||||
|
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||||
|
}
|
||||||
|
type FsAdminAuthRoleModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsAdminAuthRoleModel(db *gorm.DB) *FsAdminAuthRoleModel {
|
||||||
|
return &FsAdminAuthRoleModel{db: db, name: "fs_admin_auth_role"}
|
||||||
|
}
|
2
model/gmodel/fs_admin_auth_role_logic.go
Normal file
2
model/gmodel/fs_admin_auth_role_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package gmodel
|
||||||
|
// TODO: 使用model的属性做你想做的
|
35
model/gmodel/fs_admin_department_gen.go
Normal file
35
model/gmodel/fs_admin_department_gen.go
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fs_admin_department 后台--部门表
|
||||||
|
type FsAdminDepartment struct {
|
||||||
|
Id int64 `gorm:"primary_key;default:0;" json:"id"` // 序号
|
||||||
|
DeptPid *int64 `gorm:"default:0;" json:"dept_pid"` // 上级部门
|
||||||
|
DeptNo *string `gorm:"default:'';" json:"dept_no"` //
|
||||||
|
DeptName *string `gorm:"default:'';" json:"dept_name"` //
|
||||||
|
ShortName *string `gorm:"default:'';" json:"short_name"` //
|
||||||
|
UserId *int64 `gorm:"default:0;" json:"user_id"` // 部门负责人
|
||||||
|
Phone *string `gorm:"default:'';" json:"phone"` //
|
||||||
|
Status *int64 `gorm:"default:2;" json:"status"` // 状态:1=启用,2=停用
|
||||||
|
Remark *string `gorm:"default:'';" json:"remark"` //
|
||||||
|
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
|
||||||
|
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
|
||||||
|
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
|
||||||
|
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
|
||||||
|
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
|
||||||
|
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
|
||||||
|
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||||
|
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||||
|
}
|
||||||
|
type FsAdminDepartmentModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsAdminDepartmentModel(db *gorm.DB) *FsAdminDepartmentModel {
|
||||||
|
return &FsAdminDepartmentModel{db: db, name: "fs_admin_department"}
|
||||||
|
}
|
2
model/gmodel/fs_admin_department_logic.go
Normal file
2
model/gmodel/fs_admin_department_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package gmodel
|
||||||
|
// TODO: 使用model的属性做你想做的
|
33
model/gmodel/fs_admin_menu_gen.go
Normal file
33
model/gmodel/fs_admin_menu_gen.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package gmodel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// fs_admin_menu 后台--菜单表
|
||||||
|
type FsAdminMenu struct {
|
||||||
|
Id int64 `gorm:"primary_key;default:0;auto_increment;" json:"id"` // 序号
|
||||||
|
Pid *int64 `gorm:"default:0;" json:"pid"` // 上级菜单
|
||||||
|
Name *string `gorm:"default:'';" json:"name"` //
|
||||||
|
Path *string `gorm:"default:'';" json:"path"` //
|
||||||
|
Hide *string `gorm:"default:'';" json:"hide"` //
|
||||||
|
Metadata *[]byte `gorm:"default:'';" json:"metadata"` // 元数据,json格式
|
||||||
|
Remark *string `gorm:"default:'';" json:"remark"` //
|
||||||
|
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序权重
|
||||||
|
CreateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"create_time"` //
|
||||||
|
UpdateTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"update_time"` //
|
||||||
|
DeleteTime *time.Time `gorm:"default:'0000-00-00 00:00:00';" json:"delete_time"` //
|
||||||
|
CreateUid *int64 `gorm:"default:0;" json:"create_uid"` // 创建人
|
||||||
|
UpdateUid *int64 `gorm:"default:0;" json:"update_uid"` // 更新人
|
||||||
|
DeleteUid *int64 `gorm:"default:0;" json:"delete_uid"` // 删除人
|
||||||
|
IsDel *int64 `gorm:"default:0;" json:"is_del"` // 是否删除:1=是 0=否
|
||||||
|
}
|
||||||
|
type FsAdminMenuModel struct {
|
||||||
|
db *gorm.DB
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFsAdminMenuModel(db *gorm.DB) *FsAdminMenuModel {
|
||||||
|
return &FsAdminMenuModel{db: db, name: "fs_admin_menu"}
|
||||||
|
}
|
2
model/gmodel/fs_admin_menu_logic.go
Normal file
2
model/gmodel/fs_admin_menu_logic.go
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
package gmodel
|
||||||
|
// TODO: 使用model的属性做你想做的
|
|
@ -12,6 +12,7 @@ type FsMerchantCategory struct {
|
||||||
Icon *string `gorm:"default:'';" json:"icon"` // 图标
|
Icon *string `gorm:"default:'';" json:"icon"` // 图标
|
||||||
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品
|
RecommendProduct *string `gorm:"default:'';" json:"recommend_product"` // 推荐商品
|
||||||
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
Sort *int64 `gorm:"default:0;" json:"sort"` // 排序
|
||||||
|
IsDefault *int64 `gorm:"default:0;" json:"is_default"` // 是否是默认商家类型0非1是
|
||||||
Status *int64 `gorm:"default:0;" json:"status"` // 状态
|
Status *int64 `gorm:"default:0;" json:"status"` // 状态
|
||||||
Ctime *int64 `gorm:"default:0;" json:"ctime"` // 添加时间
|
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
|
err = m.db.WithContext(ctx).Model(&FsMerchantCategory{}).Where("id = ? and status = ?", id, 1).Take(&resp).Error
|
||||||
return resp, err
|
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
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,11 @@ import "gorm.io/gorm"
|
||||||
|
|
||||||
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
|
// AllModelsGen 所有Model集合,修改单行,只要不改字段名,不会根据新的内容修改,需要修改的话手动删除
|
||||||
type AllModelsGen struct {
|
type AllModelsGen struct {
|
||||||
|
CasbinRule *CasbinRuleModel // casbin_rule
|
||||||
FsAddress *FsAddressModel // fs_address 用户地址表
|
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 用户角色和权限信息
|
FsAuthAssignment *FsAuthAssignmentModel // fs_auth_assignment 用户角色和权限信息
|
||||||
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
|
FsAuthItem *FsAuthItemModel // fs_auth_item 用户角色和权限信息
|
||||||
FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表
|
FsAuthItemChild *FsAuthItemChildModel // fs_auth_item_child 角色和权限关系表
|
||||||
|
@ -103,7 +107,11 @@ type AllModelsGen struct {
|
||||||
|
|
||||||
func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
func NewAllModels(gdb *gorm.DB) *AllModelsGen {
|
||||||
models := &AllModelsGen{
|
models := &AllModelsGen{
|
||||||
|
CasbinRule: NewCasbinRuleModel(gdb),
|
||||||
FsAddress: NewFsAddressModel(gdb),
|
FsAddress: NewFsAddressModel(gdb),
|
||||||
|
FsAdminAuthRole: NewFsAdminAuthRoleModel(gdb),
|
||||||
|
FsAdminDepartment: NewFsAdminDepartmentModel(gdb),
|
||||||
|
FsAdminMenu: NewFsAdminMenuModel(gdb),
|
||||||
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
|
FsAuthAssignment: NewFsAuthAssignmentModel(gdb),
|
||||||
FsAuthItem: NewFsAuthItemModel(gdb),
|
FsAuthItem: NewFsAuthItemModel(gdb),
|
||||||
FsAuthItemChild: NewFsAuthItemChildModel(gdb),
|
FsAuthItemChild: NewFsAuthItemChildModel(gdb),
|
||||||
|
|
|
@ -54,16 +54,23 @@ func (l *HomePageRecommendProductListLogic) HomePageRecommendProductList(req *ty
|
||||||
//选了商家类型
|
//选了商家类型
|
||||||
if req.MerchantType > 0 {
|
if req.MerchantType > 0 {
|
||||||
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType)
|
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindOne(l.ctx, req.MerchantType)
|
||||||
} else {
|
if err != nil {
|
||||||
//随机获取一个商家类型
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
merchantInfo, err = l.svcCtx.AllModels.FsMerchantCategory.FindRandOne(l.ctx)
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the merchant category is not exists")
|
||||||
}
|
}
|
||||||
if err != nil {
|
logx.Error(err)
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get merchant category")
|
||||||
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "none of merchant type found")
|
}
|
||||||
|
} 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 == "" {
|
if *merchantInfo.RecommendProduct == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
return resp.SetStatusWithMessage(basic.CodeOK, "success", []interface{}{})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user