Merge branch 'feature/mhw-v1.01' of https://gitee.com/fusenpack/fusenapi into develop

This commit is contained in:
eson 2023-09-18 12:18:02 +08:00
commit 7c3984c4b6
4 changed files with 87 additions and 25 deletions

View File

@ -2,6 +2,7 @@ package logic
import (
"context"
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
@ -9,6 +10,7 @@ import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"fusenapi/utils/format"
"fusenapi/utils/s3url_to_s3id"
"fusenapi/utils/shopping_cart"
"fusenapi/utils/step_price"
"math"
@ -39,6 +41,7 @@ func NewGetCartsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetCarts
// }
func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo) (resp *basic.Response) {
userinfo.UserId = 39
if req.CurrentPage <= 0 {
req.CurrentPage = constants.DEFAULT_PAGE
}
@ -66,20 +69,22 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
})
}
var (
mapSize = make(map[int64]gmodel.FsProductSize)
mapModel = make(map[int64]gmodel.FsProductModel3d)
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
mapSizePrice = make(map[string]gmodel.FsProductPrice)
mapProduct = make(map[int64]struct{})
mapSize = make(map[int64]gmodel.FsProductSize)
mapModel = make(map[int64]gmodel.FsProductModel3d)
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
mapSizePrice = make(map[string]gmodel.FsProductPrice)
mapProduct = make(map[int64]gmodel.FsProduct)
mapResourceMetadata = make(map[string]interface{})
)
//获取相关信息
err = l.GetRelationInfo(GetRelationInfoReq{
Carts: carts,
MapSize: mapSize,
MapModel: mapModel,
MapTemplate: mapTemplate,
MapSizePrice: mapSizePrice,
MapProduct: mapProduct,
Carts: carts,
MapSize: mapSize,
MapModel: mapModel,
MapTemplate: mapTemplate,
MapSizePrice: mapSizePrice,
MapProduct: mapProduct,
MapResourceMetadata: mapResourceMetadata,
})
if err != nil {
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
@ -137,6 +142,10 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
stepQuantityList = append(stepQuantityList, tmpQuantity)
tmpMinBuyNum++
}
sizeCapacity := snapShot.SizeInfo.Capacity
if sizeInfo, ok := mapSize[*cart.SizeId]; ok {
sizeCapacity = *sizeInfo.Capacity
}
//根据数量获取阶梯价格中对应的价格
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
//如果有配件,单价也要加入配件价格
@ -145,12 +154,34 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
itemPrice += *curFittingInfo.Price
}
}
fittingName := snapShot.FittingInfo.FittingName
if fittingInfo, ok := mapModel[*cart.FittingId]; ok {
fittingName = *fittingInfo.Name
}
totalPrice := itemPrice * (*cart.PurchaseQuantity)
productCover := "" //产品封面图
productName := snapShot.ProductInfo.ProductName
productSn := snapShot.ProductInfo.ProductSn
var productCoverMetadata interface{}
if productInfo, ok := mapProduct[*cart.ProductId]; ok {
productCover = *productInfo.Cover
productName = *productInfo.Title
productSn = *productInfo.Sn
if metadata, ok := mapResourceMetadata[*productInfo.Cover]; ok {
productCoverMetadata = metadata
}
}
item := types.CartItem{
ProductId: *cart.ProductId,
ProductInfo: types.ProductInfo{
ProductId: *cart.ProductId,
ProductName: productName,
ProductSn: productSn,
ProductCover: productCover,
ProductCoverMetadata: productCoverMetadata,
},
SizeInfo: types.SizeInfo{
SizeId: *cart.SizeId,
Capacity: snapShot.SizeInfo.Capacity,
Capacity: sizeCapacity,
Title: types.SizeTitle{
Cm: snapShot.SizeInfo.Cm,
Inch: snapShot.SizeInfo.Inch,
@ -158,7 +189,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
},
FittingInfo: types.FittingInfo{
FittingId: *cart.FittingId,
FittingName: snapShot.FittingInfo.FittingName,
FittingName: fittingName,
},
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
@ -194,12 +225,13 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
// 获取相关信息
type GetRelationInfoReq struct {
Carts []gmodel.FsShoppingCart
MapSize map[int64]gmodel.FsProductSize
MapModel map[int64]gmodel.FsProductModel3d
MapTemplate map[int64]gmodel.FsProductTemplateV2
MapSizePrice map[string]gmodel.FsProductPrice
MapProduct map[int64]struct{}
Carts []gmodel.FsShoppingCart
MapSize map[int64]gmodel.FsProductSize
MapModel map[int64]gmodel.FsProductModel3d
MapTemplate map[int64]gmodel.FsProductTemplateV2
MapSizePrice map[string]gmodel.FsProductPrice
MapProduct map[int64]gmodel.FsProduct
MapResourceMetadata map[string]interface{}
}
func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
@ -215,13 +247,28 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
productIds = append(productIds, *req.Carts[index].ProductId)
}
//获取产品集合
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "", "id")
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "")
if err != nil {
logx.Error(err)
return errors.New("failed to get product list")
}
resourceIds := make([]string, 0, len(productList))
for _, v := range productList {
req.MapProduct[v.Id] = struct{}{}
req.MapProduct[v.Id] = v
resourceIds = append(resourceIds, s3url_to_s3id.GetS3ResourceIdFormUrl(*v.Cover))
}
//根据resourceUrls找到对应的元数据
resourceMetadataList, err := l.svcCtx.AllModels.FsResource.FindAllByResourceIds(l.ctx, resourceIds)
if err != nil {
logx.Error(err)
return errors.New("failed to get resource list")
}
for _, v := range resourceMetadataList {
var metadata interface{}
if v.Metadata != nil {
_ = json.Unmarshal(*v.Metadata, &metadata)
}
req.MapResourceMetadata[*v.ResourceUrl] = metadata
}
//获取尺寸列表
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")

View File

@ -44,7 +44,7 @@ type GetCartsRsp struct {
}
type CartItem struct {
ProductId int64 `json:"product_id"` //产品id
ProductInfo ProductInfo `json:"product_info"` //产品信息
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
ItemPrice string `json:"item_price"` //单价
@ -56,6 +56,14 @@ type CartItem struct {
InvalidDescription string `json:"invalid_description"` //无效原因
}
type ProductInfo struct {
ProductId int64 `json:"product_id"` //产品id
ProductName string `json:"product_name"`
ProductSn string `json:"product_sn"`
ProductCover string `json:"product_cover"` //产品图
ProductCoverMetadata interface{} `json:"product_cover_metadata"` //产品图元数据
}
type SizeInfo struct {
SizeId int64 `json:"size_id"` //尺寸id
Capacity string `json:"capacity"` //尺寸名称

View File

@ -63,7 +63,7 @@ type GetCartsRsp {
CartList []CartItem `json:"cart_list"`
}
type CartItem {
ProductId int64 `json:"product_id"` //产品id
ProductInfo ProductInfo `json:"product_info"` //产品信息
SizeInfo SizeInfo `json:"size_info"` //尺寸信息
FittingInfo FittingInfo `json:"fitting_info"` //配件信息
ItemPrice string `json:"item_price"` //单价
@ -74,6 +74,13 @@ type CartItem {
IsInvalid bool `json:"is_invalid"` //是否无效
InvalidDescription string `json:"invalid_description"` //无效原因
}
type ProductInfo {
ProductId int64 `json:"product_id"` //产品id
ProductName string `json:"product_name"`
ProductSn string `json:"product_sn"`
ProductCover string `json:"product_cover"` //产品图
ProductCoverMetadata interface{} `json:"product_cover_metadata"` //产品图元数据
}
type SizeInfo {
SizeId int64 `json:"size_id"` //尺寸id
Capacity string `json:"capacity"` //尺寸名称

View File

@ -15,7 +15,7 @@ type VerifyShoppingCartSnapshotDataChangeReq struct {
MapTemplate map[int64]gmodel.FsProductTemplateV2
MapCartChange map[int64]string
MapSnapshot map[int64]CartSnapshot
MapProduct map[int64]struct{}
MapProduct map[int64]gmodel.FsProduct
}
func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error {