fix
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/image"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"fusenapi/server/product/internal/svc"
|
||||
"fusenapi/server/product/internal/types"
|
||||
@@ -33,12 +35,21 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||
}
|
||||
if req.Num <= 0 {
|
||||
if req.Num <= 0 || req.Num > 100{
|
||||
req.Num = 4
|
||||
}
|
||||
if req.Size > 0{
|
||||
req.Size = image.GetCurrentSize(req.Size)
|
||||
}
|
||||
//获取用户信息
|
||||
user,err := l.svcCtx.AllModels.FsUser.FindUserById(l.ctx,userinfo.UserId)
|
||||
if err != nil {
|
||||
if errors.Is(err,gorm.ErrRecordNotFound){
|
||||
return resp.SetStatusWithMessage(basic.CodeUnAuth,"user not exists")
|
||||
}
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get user info")
|
||||
}
|
||||
tagInfo,err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx,req.Cid)
|
||||
if err != nil{
|
||||
if errors.Is(err,gorm.ErrRecordNotFound){
|
||||
@@ -53,8 +64,84 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
||||
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"success")
|
||||
}
|
||||
//获取推荐产品信息
|
||||
l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx,)
|
||||
//TODO 明天再做
|
||||
return resp.SetStatus(basic.CodeOK)
|
||||
pids,err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct,","))
|
||||
if err != nil{
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr,"failed to parse recommend product")
|
||||
}
|
||||
list,err := l.getRandom(pids,int(req.Num))
|
||||
if err != nil{
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeDbSqlErr,"failed to get random list")
|
||||
}
|
||||
if req.Size <= 0{
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"success,",list)
|
||||
}
|
||||
//千人前面处理
|
||||
for _,v := range list{
|
||||
r := &image.ThousandFaceImageFormatReq{
|
||||
Size: int(req.Size),
|
||||
IsThousandFace: int(*user.IsThousandFace),
|
||||
Cover: v.Cover,
|
||||
CoverImg: v.CoverImg,
|
||||
CoverDefault: "",
|
||||
ProductId: v.Id,
|
||||
UserInfo: user,
|
||||
}
|
||||
image.ThousandFaceImageFormat(r)
|
||||
v.Cover = r.Cover
|
||||
v.CoverImg = r.CoverImg
|
||||
v.CoverDefault = r.CoverDefault
|
||||
}
|
||||
return resp.SetStatusWithMessage(basic.CodeOK,"success,",list)
|
||||
}
|
||||
func (l *OtherProductListLogic) getRandom(productIds []int64,limit int)(result []types.OtherProductListRsp,err error){
|
||||
if len(productIds) == 0{
|
||||
return
|
||||
}
|
||||
//获取推荐产品信息
|
||||
recommendProductList,err := l.svcCtx.AllModels.FsProduct.GetRandomProductListInIds(l.ctx,productIds,limit)
|
||||
if err != nil{
|
||||
return nil, err
|
||||
}
|
||||
if len(recommendProductList) == 0{
|
||||
return
|
||||
}
|
||||
mapProduct := make(map[int64]int)
|
||||
newProductIds := make([]int64,0,len(recommendProductList))
|
||||
for k,v := range recommendProductList{
|
||||
newProductIds = append(newProductIds,v.Id)
|
||||
mapProduct[v.Id] = k
|
||||
}
|
||||
//查询最新的sku
|
||||
sortNeq := int64(0)
|
||||
reqStatus := int64(1)
|
||||
productTemplateIds,err := l.svcCtx.AllModels.FsProductTemplateV2.GetProductTemplateListByParams(l.ctx,gmodel.GetProductTemplateListByParamsReq{
|
||||
ProductIds: newProductIds,
|
||||
GroupBy: "product_id",
|
||||
OrderBy: "id DESC,sort DESC",
|
||||
Fields: "product_id,max(id) as id",
|
||||
SortNeq: &sortNeq,
|
||||
TitleKeyword: "A007",
|
||||
Status: &reqStatus,
|
||||
})
|
||||
if err != nil{
|
||||
return nil,err
|
||||
}
|
||||
for _,v := range productTemplateIds{
|
||||
productIndex,ok := mapProduct[*v.ProductId]
|
||||
if !ok{
|
||||
continue
|
||||
}
|
||||
productInfo := recommendProductList[productIndex]
|
||||
result = append(result,types.OtherProductListRsp{
|
||||
Title: *productInfo.Title,
|
||||
Cover: *productInfo.Cover,
|
||||
CoverImg: *productInfo.CoverImg,
|
||||
Sn: *productInfo.Sn,
|
||||
Id: *v.ProductId,
|
||||
SkuId: v.Id,
|
||||
})
|
||||
}
|
||||
return result,nil
|
||||
}
|
||||
@@ -222,12 +222,13 @@ type OtherProductListReq struct {
|
||||
}
|
||||
|
||||
type OtherProductListRsp struct {
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
CoverImg string `json:"cover_img"`
|
||||
Sn string `json:"sn"`
|
||||
Id int64 `json:"id"`
|
||||
SkuId int64 `json:"sku_id"`
|
||||
Title string `json:"title"`
|
||||
Cover string `json:"cover"`
|
||||
CoverImg string `json:"cover_img"`
|
||||
CoverDefault string `json:"cover_default"`
|
||||
Sn string `json:"sn"`
|
||||
Id int64 `json:"id"`
|
||||
SkuId int64 `json:"sku_id"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
|
||||
Reference in New Issue
Block a user