This commit is contained in:
laodaming
2023-06-06 19:21:07 +08:00
parent 21b22a3409
commit 0915e98700
3 changed files with 72 additions and 46 deletions

View File

@@ -12,12 +12,10 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/format"
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"sort"
"strings"
"time"
"github.com/zeromicro/go-zero/core/logx"
)
type GetProductListLogic struct {
@@ -37,6 +35,7 @@ func NewGetProductListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Ge
// 获取产品列表
func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, loginInfo auth.UserInfo) (resp *types.Response) {
resp = &types.Response{}
loginInfo.UserId = 83
//校验前台登录情况
if loginInfo.UserId == 0 {
resp.Set(constants.CODE_UNAUTH, "please sign in")
@@ -160,31 +159,26 @@ func (l *GetProductListLogic) GetProductList(req *types.GetProductListReq, login
Id: v.Id,
Sn: v.Sn,
Title: v.Title,
Cover: v.Cover,
Intro: v.Intro.String,
CoverImg: v.CoverImg,
IsEnv: v.IsProtection,
IsMicro: v.IsMicrowave,
SizeNum: uint32(productSizeCount),
MiniPrice: format.CentoDollar(minPrice),
}
if req.Size > 0 {
coverSlice := strings.Split(v.Cover, ".")
coverImgSlice := strings.Split(v.CoverImg, ".")
if req.Size >= 200 {
item.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
item.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
//千人千面处理
if userInfo.IsThousandFace == 1 {
v.Cover = ""
item.CoverDefault = item.CoverImg
if req.Size >= 200 {
item.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, userInfo.Id, userInfo.Id, v.Id, time.Now().Unix())
item.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
}
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(userInfo.IsThousandFace),
Cover: v.Cover,
CoverImg: v.CoverImg,
CoverDefault: v.CoverImg,
ProductId: v.Id,
UserInfo: *userInfo,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
item.Cover = thousandFaceImageFormatReq.Cover
item.CoverImg = thousandFaceImageFormatReq.CoverImg
item.CoverDefault = thousandFaceImageFormatReq.CoverDefault
itemList = append(itemList, item)
}
resp.SetWithData(constants.CODE_OK, "success", types.GetProductListRsp{

View File

@@ -3,7 +3,6 @@ package logic
import (
"context"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model"
"fusenapi/product/internal/svc"
@@ -12,8 +11,6 @@ import (
"fusenapi/utils/image"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
"time"
)
type GetSuccessRecommandLogic struct {
@@ -73,30 +70,25 @@ func (l *GetSuccessRecommandLogic) GetSuccessRecommand(req *types.GetSuccessReco
list := make([]types.GetSuccessRecommandRsp, 0, len(productList))
for _, v := range productList {
data := types.GetSuccessRecommandRsp{
Title: v.Title,
Cover: v.Cover,
CoverImg: v.CoverImg,
Sn: v.Sn,
Id: v.Id,
SkuId: 0, //???????
CoverDefault: v.CoverImg,
Title: v.Title,
Sn: v.Sn,
Id: v.Id,
SkuId: 0, //???????
}
if req.Size > 0 {
coverImgSlice := strings.Split(v.CoverImg, ".")
coverSlice := strings.Split(v.Cover, ".")
if req.Size > 200 {
data.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
data.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
//千人千面
if userInfo.IsThousandFace == 1 {
data.Cover = ""
data.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, userInfo.Id, userInfo.Id, v.Id, time.Now().Unix())
if req.Size > 200 {
data.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
}
}
//千人千面处理
thousandFaceImageFormatReq := image.ThousandFaceImageFormatReq{
Size: int(req.Size),
IsThousandFace: int(userInfo.IsThousandFace),
Cover: v.Cover,
CoverImg: v.CoverImg,
CoverDefault: v.CoverImg,
ProductId: v.Id,
UserInfo: *userInfo,
}
image.ThousandFaceImageFormat(&thousandFaceImageFormatReq)
data.Cover = thousandFaceImageFormatReq.Cover
data.CoverImg = thousandFaceImageFormatReq.CoverImg
data.CoverDefault = thousandFaceImageFormatReq.CoverDefault
list = append(list, data)
}
resp.SetWithData(constants.CODE_OK, "success", list)