fix
This commit is contained in:
parent
5f3d6eb120
commit
22d0f6a5b1
|
@ -71,8 +71,15 @@ func (p *FsProductModel) FindAllOnlyByIds(ctx context.Context, ids []int64) (res
|
||||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
err = p.db.WithContext(ctx).Model(&FsProduct{}).Where("`id` IN (?)", ids).Find(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int) (resp []FsProduct, err error) {
|
func (p *FsProductModel) GetRandomProductListInIds(ctx context.Context,ids []int64, limit int,fields ...string) (resp []FsProduct, err error) {
|
||||||
err = p.db.WithContext(ctx).Model(&FsProduct{}).
|
if len(ids) == 0{
|
||||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit).Find(&resp).Error
|
return
|
||||||
|
}
|
||||||
|
db := p.db.WithContext(ctx).Model(&FsProduct{}).
|
||||||
|
Where("`id` in (?) and `is_del` =? and `is_shelf` = ?", ids,0, 1).Order("RAND()").Limit(limit)
|
||||||
|
if len(fields) != 0{
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
return resp,err
|
return resp,err
|
||||||
}
|
}
|
|
@ -72,3 +72,39 @@ func (t *FsProductTemplateV2Model) FindOneByModelId(ctx context.Context, modelId
|
||||||
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` = ? ", modelId).Take(&resp).Error
|
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` = ? ", modelId).Take(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetProductTemplateListByParamsReq struct {
|
||||||
|
ProductIds []int64
|
||||||
|
GroupBy string
|
||||||
|
OrderBy string
|
||||||
|
Fields string
|
||||||
|
SortNeq *int64
|
||||||
|
TitleKeyword string
|
||||||
|
Status *int64
|
||||||
|
}
|
||||||
|
func (t *FsProductTemplateV2Model) GetProductTemplateListByParams(ctx context.Context, req GetProductTemplateListByParamsReq) (resp []FsProductTemplateV2, err error) {
|
||||||
|
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{})
|
||||||
|
if len(req.ProductIds) > 0{
|
||||||
|
db = db.Where("`product_id` in (?)",req.ProductIds)
|
||||||
|
}
|
||||||
|
if req.GroupBy != ""{
|
||||||
|
db = db.Group(req.GroupBy)
|
||||||
|
}
|
||||||
|
if req.OrderBy != ""{
|
||||||
|
db = db.Order(req.OrderBy)
|
||||||
|
}
|
||||||
|
if req.Fields != ""{
|
||||||
|
db = db.Select(req.Fields)
|
||||||
|
}
|
||||||
|
if req.SortNeq != nil{
|
||||||
|
db = db.Where("`sort` != ?",req.SortNeq)
|
||||||
|
}
|
||||||
|
if req.TitleKeyword != ""{
|
||||||
|
db = db.Where("title like ?",`%`+req.TitleKeyword+`%`)
|
||||||
|
}
|
||||||
|
if req.Status != nil{
|
||||||
|
db = db.Where("`status` = ?",req.Status)
|
||||||
|
}
|
||||||
|
err = db.Find(&resp).Error
|
||||||
|
return resp, err
|
||||||
|
}
|
|
@ -1,13 +1,15 @@
|
||||||
package logic
|
package logic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/auth"
|
"fusenapi/utils/auth"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
"fusenapi/utils/format"
|
||||||
"fusenapi/utils/image"
|
"fusenapi/utils/image"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"strings"
|
||||||
"context"
|
|
||||||
|
|
||||||
"fusenapi/server/product/internal/svc"
|
"fusenapi/server/product/internal/svc"
|
||||||
"fusenapi/server/product/internal/types"
|
"fusenapi/server/product/internal/types"
|
||||||
|
@ -33,12 +35,21 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
||||||
if userinfo.GetIdType() != auth.IDTYPE_User {
|
if userinfo.GetIdType() != auth.IDTYPE_User {
|
||||||
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
return resp.SetStatusWithMessage(basic.CodeUnAuth, "please login first")
|
||||||
}
|
}
|
||||||
if req.Num <= 0 {
|
if req.Num <= 0 || req.Num > 100{
|
||||||
req.Num = 4
|
req.Num = 4
|
||||||
}
|
}
|
||||||
if req.Size > 0{
|
if req.Size > 0{
|
||||||
req.Size = image.GetCurrentSize(req.Size)
|
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)
|
tagInfo,err := l.svcCtx.AllModels.FsTags.FindOne(l.ctx,req.Cid)
|
||||||
if err != nil{
|
if err != nil{
|
||||||
if errors.Is(err,gorm.ErrRecordNotFound){
|
if errors.Is(err,gorm.ErrRecordNotFound){
|
||||||
|
@ -53,8 +64,84 @@ func (l *OtherProductListLogic) OtherProductList(req *types.OtherProductListReq,
|
||||||
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
|
if tagInfo.RecommendProduct == nil || *tagInfo.RecommendProduct == "" {
|
||||||
return resp.SetStatusWithMessage(basic.CodeOK,"success")
|
return resp.SetStatusWithMessage(basic.CodeOK,"success")
|
||||||
}
|
}
|
||||||
//获取推荐产品信息
|
pids,err := format.StrSlicToInt64Slice(strings.Split(*tagInfo.RecommendProduct,","))
|
||||||
l.svcCtx.AllModels.FsProduct.GetRandomProductList(l.ctx,)
|
if err != nil{
|
||||||
//TODO 明天再做
|
logx.Error(err)
|
||||||
return resp.SetStatus(basic.CodeOK)
|
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 {
|
type OtherProductListRsp struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
Sn string `json:"sn"`
|
CoverDefault string `json:"cover_default"`
|
||||||
Id int64 `json:"id"`
|
Sn string `json:"sn"`
|
||||||
SkuId int64 `json:"sku_id"`
|
Id int64 `json:"id"`
|
||||||
|
SkuId int64 `json:"sku_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
|
|
@ -233,10 +233,11 @@ type OtherProductListReq {
|
||||||
Size uint32 `json:"size"`
|
Size uint32 `json:"size"`
|
||||||
}
|
}
|
||||||
type OtherProductListRsp {
|
type OtherProductListRsp {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Cover string `json:"cover"`
|
Cover string `json:"cover"`
|
||||||
CoverImg string `json:"cover_img"`
|
CoverImg string `json:"cover_img"`
|
||||||
Sn string `json:"sn"`
|
CoverDefault string `json:"cover_default"`
|
||||||
Id int64 `json:"id"`
|
Sn string `json:"sn"`
|
||||||
SkuId int64 `json:"sku_id"`
|
Id int64 `json:"id"`
|
||||||
|
SkuId int64 `json:"sku_id"`
|
||||||
}
|
}
|
|
@ -45,22 +45,23 @@ type ThousandFaceImageFormatReq struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
func ThousandFaceImageFormat(req *ThousandFaceImageFormatReq) {
|
||||||
if req.Size > 0 {
|
if req.Size <= 0 {
|
||||||
coverSlice := strings.Split(req.Cover, ".")
|
return
|
||||||
coverImgSlice := strings.Split(req.CoverImg, ".")
|
}
|
||||||
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
|
coverSlice := strings.Split(req.Cover, ".")
|
||||||
req.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
coverImgSlice := strings.Split(req.CoverImg, ".")
|
||||||
req.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
|
||||||
}
|
req.Cover = fmt.Sprintf("%s_%d.%s", coverSlice[0], req.Size, coverSlice[1])
|
||||||
if req.IsThousandFace == 0 {
|
req.CoverImg = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
||||||
return
|
}
|
||||||
}
|
if req.IsThousandFace == 0 {
|
||||||
//千人千面处理
|
return
|
||||||
req.Cover = ""
|
}
|
||||||
req.CoverDefault = req.CoverImg
|
//千人千面处理
|
||||||
if req.Size >= 200 && len(coverSlice) >= 2 && len(coverImgSlice) >= 2 {
|
req.Cover = ""
|
||||||
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 = req.CoverImg
|
||||||
req.CoverDefault = fmt.Sprintf("%s_%d.%s", coverImgSlice[0], req.Size, coverImgSlice[1])
|
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