fix
This commit is contained in:
parent
56a8b32d90
commit
86a2deacfb
|
@ -31,9 +31,11 @@ func (t *FsTagsModel) GetAllByLevel(ctx context.Context, level int) (resp []FsTa
|
||||||
}
|
}
|
||||||
|
|
||||||
type GetAllTagByParamsReq struct {
|
type GetAllTagByParamsReq struct {
|
||||||
Ids []int64
|
Ids []int64
|
||||||
Status *int64
|
Status *int64
|
||||||
OrderBy string
|
OrderBy string
|
||||||
|
LevelPrefixLeftLike string //右模糊
|
||||||
|
WithChild bool //是否包含子层级
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *FsTagsModel) GetAllTagByParams(ctx context.Context, req GetAllTagByParamsReq) (resp []FsTags, err error) {
|
func (t *FsTagsModel) GetAllTagByParams(ctx context.Context, req GetAllTagByParamsReq) (resp []FsTags, err error) {
|
||||||
|
@ -44,6 +46,14 @@ func (t *FsTagsModel) GetAllTagByParams(ctx context.Context, req GetAllTagByPara
|
||||||
if req.Status != nil {
|
if req.Status != nil {
|
||||||
db = db.Where("`status` = ?", *req.Status)
|
db = db.Where("`status` = ?", *req.Status)
|
||||||
}
|
}
|
||||||
|
if req.LevelPrefixLeftLike != "" {
|
||||||
|
//查询子集
|
||||||
|
if req.WithChild {
|
||||||
|
db = db.Where("`level_prefix` like ?", req.LevelPrefixLeftLike+`%`)
|
||||||
|
} else {
|
||||||
|
db = db.Where("`level_prefix` = ?", req.LevelPrefixLeftLike+`%`)
|
||||||
|
}
|
||||||
|
}
|
||||||
switch req.OrderBy {
|
switch req.OrderBy {
|
||||||
case "":
|
case "":
|
||||||
db = db.Order("`id` DESC")
|
db = db.Order("`id` DESC")
|
||||||
|
|
|
@ -17,41 +17,41 @@ import (
|
||||||
|
|
||||||
func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
/*
|
|
||||||
var (
|
var (
|
||||||
// 定义错误变量
|
// 定义错误变量
|
||||||
err error
|
err error
|
||||||
// 定义用户信息变量
|
// 定义用户信息变量
|
||||||
userinfo *auth.UserInfo
|
userinfo *auth.UserInfo
|
||||||
)
|
)
|
||||||
// 解析JWT token,并对空用户进行判断
|
// 解析JWT token,并对空用户进行判断
|
||||||
claims, err := svcCtx.ParseJwtToken(r)
|
claims, err := svcCtx.ParseJwtToken(r)
|
||||||
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
// 如果解析JWT token出错,则返回未授权的JSON响应并记录错误消息
|
||||||
|
if err != nil {
|
||||||
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
|
Code: 401, // 返回401状态码,表示未授权
|
||||||
|
Message: "unauthorized", // 返回未授权信息
|
||||||
|
})
|
||||||
|
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
// 从token中获取对应的用户信息
|
||||||
|
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
||||||
|
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
||||||
Code: 401, // 返回401状态码,表示未授权
|
Code: 401,
|
||||||
Message: "unauthorized", // 返回未授权信息
|
Message: "unauthorized",
|
||||||
})
|
})
|
||||||
logx.Info("unauthorized:", err.Error()) // 记录错误日志
|
logx.Info("unauthorized:", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if claims != nil {
|
// 如果claims为nil,则认为用户身份为白板用户
|
||||||
// 从token中获取对应的用户信息
|
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
||||||
userinfo, err = auth.GetUserInfoFormMapClaims(claims)
|
}
|
||||||
// 如果获取用户信息出错,则返回未授权的JSON响应并记录错误消息
|
|
||||||
if err != nil {
|
|
||||||
httpx.OkJsonCtx(r.Context(), w, &basic.Response{
|
|
||||||
Code: 401,
|
|
||||||
Message: "unauthorized",
|
|
||||||
})
|
|
||||||
logx.Info("unauthorized:", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果claims为nil,则认为用户身份为白板用户
|
|
||||||
userinfo = &auth.UserInfo{UserId: 0, GuestId: 0}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
var req types.GetTagProductListReq
|
var req types.GetTagProductListReq
|
||||||
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
// 如果端点有请求结构体,则使用httpx.Parse方法从HTTP请求体中解析请求数据
|
||||||
|
@ -65,7 +65,7 @@ func GetTagProductListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
// 创建一个业务逻辑层实例
|
// 创建一个业务逻辑层实例
|
||||||
l := logic.NewGetTagProductListLogic(r.Context(), svcCtx)
|
l := logic.NewGetTagProductListLogic(r.Context(), svcCtx)
|
||||||
resp := l.GetTagProductList(&req, &auth.UserInfo{39, 0})
|
resp := l.GetTagProductList(&req, userinfo)
|
||||||
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
// 如果响应不为nil,则使用httpx.OkJsonCtx方法返回JSON响应;
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/format"
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
|
"gorm.io/gorm"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -37,20 +39,28 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
req.Size = image.GetCurrentSize(req.Size)
|
||||||
}
|
}
|
||||||
//查询用户信息(不用判断存在)
|
//查询用户信息(不用判断存在)
|
||||||
/*user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
user, err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx, userinfo.UserId)
|
||||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "get user info err")
|
||||||
}*/
|
}
|
||||||
//查询分类列表
|
//查询分类列表
|
||||||
tStatus := int64(1)
|
tStatus := int64(1)
|
||||||
tReq := gmodel.GetAllTagByParamsReq{
|
tReq := gmodel.GetAllTagByParamsReq{
|
||||||
Status: &tStatus,
|
Status: &tStatus,
|
||||||
OrderBy: "`sort` DESC",
|
OrderBy: "`sort` DESC",
|
||||||
|
WithChild: true, //需要子集
|
||||||
}
|
}
|
||||||
//传入分类id
|
//传入分类id
|
||||||
if req.Cid > 0 {
|
if req.Cid > 0 {
|
||||||
tReq.Ids = []int64{req.Cid}
|
//获取该类行的levelprefix
|
||||||
|
tagData, err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx, req.Cid)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "param cid is invalid:record not found")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tReq.LevelPrefixLeftLike = *tagData.LevelPrefix
|
||||||
}
|
}
|
||||||
tagList, err := l.svcCtx.AllModels.FsTags.GetAllTagByParams(l.ctx, tReq)
|
tagList, err := l.svcCtx.AllModels.FsTags.GetAllTagByParams(l.ctx, tReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -81,12 +91,8 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product list")
|
||||||
}
|
}
|
||||||
productLen := len(productList)
|
|
||||||
if productLen == 0 {
|
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK, "success")
|
|
||||||
}
|
|
||||||
//提取产品ids
|
//提取产品ids
|
||||||
productIds := make([]int64, 0, productLen)
|
productIds := make([]int64, 0, len(productList))
|
||||||
for _, v := range productList {
|
for _, v := range productList {
|
||||||
productIds = append(productIds, v.Id)
|
productIds = append(productIds, v.Id)
|
||||||
}
|
}
|
||||||
|
@ -140,7 +146,7 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
minLevel = *tagInfo.Level
|
minLevel = *tagInfo.Level
|
||||||
}
|
}
|
||||||
//获取分类产品列表
|
//获取分类产品列表
|
||||||
/*productListRsp := l.getTagProducts(getTagProductsReq{
|
productListRsp := l.getTagProducts(getTagProductsReq{
|
||||||
TagId: tagInfo.Id,
|
TagId: tagInfo.Id,
|
||||||
ProductList: productList,
|
ProductList: productList,
|
||||||
MapProductMinPrice: mapProductMinPrice,
|
MapProductMinPrice: mapProductMinPrice,
|
||||||
|
@ -148,18 +154,18 @@ func (l *GetTagProductListLogic) GetTagProductList(req *types.GetTagProductListR
|
||||||
MapProductSizeCount: mapProductSizeCount,
|
MapProductSizeCount: mapProductSizeCount,
|
||||||
Size: req.Size,
|
Size: req.Size,
|
||||||
User: user,
|
User: user,
|
||||||
})*/
|
})
|
||||||
//加入分类
|
//加入分类
|
||||||
tagTem := types.TagItem{
|
tagTem := types.TagItem{
|
||||||
//TagProductList: productListRsp,
|
TagProductList: productListRsp,
|
||||||
TypeName: *tagInfo.Title,
|
TypeName: *tagInfo.Title,
|
||||||
TypeId: tagInfo.Id,
|
TypeId: tagInfo.Id,
|
||||||
Level: *tagInfo.Level,
|
Level: *tagInfo.Level,
|
||||||
LevelPrefix: *tagInfo.LevelPrefix,
|
LevelPrefix: *tagInfo.LevelPrefix,
|
||||||
Icon: *tagInfo.Icon,
|
Icon: *tagInfo.Icon,
|
||||||
Sort: *tagInfo.Sort,
|
Sort: *tagInfo.Sort,
|
||||||
Description: *tagInfo.Description,
|
Description: *tagInfo.Description,
|
||||||
ChildTagList: make([]*types.TagItem, 0, 100),
|
ChildTagList: make([]*types.TagItem, 0, 100),
|
||||||
}
|
}
|
||||||
//当前tag保存入map
|
//当前tag保存入map
|
||||||
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
mapTagLevel[*tagInfo.LevelPrefix] = &tagTem
|
||||||
|
|
Loading…
Reference in New Issue
Block a user