fix
This commit is contained in:
parent
21b22a3409
commit
0915e98700
|
@ -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{
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
package image
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 定义尺寸规则
|
||||
var sizeArray = []uint32{1200, 1000, 750, 500, 128}
|
||||
|
||||
// 裁剪尺寸阶梯
|
||||
var newSizeArray = []uint32{200, 400, 600, 800}
|
||||
|
||||
// 获取合适尺寸
|
||||
func GetCurrentSize(clientSize uint32) uint32 {
|
||||
lenNewSize := len(newSizeArray)
|
||||
//大于最大尺寸则返回规则最大尺寸
|
||||
|
@ -23,3 +32,34 @@ func GetCurrentSize(clientSize uint32) uint32 {
|
|||
}
|
||||
return clientSize
|
||||
}
|
||||
|
||||
// 千人前面图像拼接
|
||||
type ThousandFaceImageFormatReq struct {
|
||||
Size int
|
||||
IsThousandFace int
|
||||
Cover string
|
||||
CoverImg string
|
||||
CoverDefault string
|
||||
ProductId int64
|
||||
UserInfo model.FsUser
|
||||
}
|
||||
|
||||
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
||||
if req.Size > 0 {
|
||||
coverSlice := strings.Split(req.Cover, ".")
|
||||
coverImgSlice := strings.Split(req.CoverImg, ".")
|
||||
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
|
||||
req.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
||||
req.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
||||
}
|
||||
//千人千面处理
|
||||
if req.IsThousandFace == 1 {
|
||||
req.Cover = ""
|
||||
req.CoverDefault = req.CoverImg
|
||||
if req.Size >= 200 && len(coverSlice) == 2 && len(coverImgSlice) == 2 {
|
||||
req.CoverImg = fmt.Sprintf("%s/test/%d/%d_%d.png?%d", constants.DOMAIN_RENDER_IMG_NAME, req.UserInfo.Id, req.UserInfo.Id, req.ProductId, time.Now().Unix())
|
||||
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user