fix
This commit is contained in:
parent
668db55e6b
commit
da8f88b3e6
|
@ -18,12 +18,15 @@ func (p *FsProductModel) FindOneBySn(ctx context.Context, sn string, fields ...s
|
||||||
err = db.Take(&resp).Error
|
err = db.Take(&resp).Error
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string) (resp []FsProduct, err error) {
|
func (p *FsProductModel) GetProductListByIds(ctx context.Context, productIds []int64, sort string, fields ...string) (resp []FsProduct, err error) {
|
||||||
if len(productIds) == 0 {
|
if len(productIds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
db := p.db.Model(&FsProduct{}).WithContext(ctx).
|
db := p.db.Model(&FsProduct{}).WithContext(ctx).
|
||||||
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
Where("`id` in (?) and `is_del` =? and `is_shelf` = ? and `status` =?", productIds, 0, 1, 1)
|
||||||
|
if len(fields) > 0 {
|
||||||
|
db = db.Select(fields[0])
|
||||||
|
}
|
||||||
switch sort {
|
switch sort {
|
||||||
case "sort-asc":
|
case "sort-asc":
|
||||||
db = db.Order("`sort` ASC")
|
db = db.Order("`sort` ASC")
|
||||||
|
|
|
@ -23,11 +23,11 @@ func (p *FsProductPriceModel) GetSimplePriceListByProductIds(ctx context.Context
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (p *FsProductPriceModel) GetPriceListBySizeIds(ctx context.Context, sizeIds []int64) (resp []FsProductPrice, err error) {
|
func (p *FsProductPriceModel) GetPriceListByProductIdsSizeIds(ctx context.Context, productIds, sizeIds []int64) (resp []FsProductPrice, err error) {
|
||||||
if len(sizeIds) == 0 {
|
if len(sizeIds) == 0 || len(productIds) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `status` = ? ", sizeIds, 1).Find(&resp).Error
|
err = p.db.WithContext(ctx).Model(&FsProductPrice{}).Where("`size_id` in (?) and `product_id` in (?) and `status` = ? ", sizeIds, productIds, 1).Find(&resp).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,14 +74,14 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
||||||
}
|
}
|
||||||
//获取价格列表
|
//获取价格列表
|
||||||
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
productPriceModel := gmodel.NewFsProductPriceModel(l.svcCtx.MysqlConn)
|
||||||
productPriceList, err := productPriceModel.GetPriceListBySizeIds(l.ctx, sizeIds)
|
productPriceList, err := productPriceModel.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product proce list")
|
||||||
}
|
}
|
||||||
mapProductPrice := make(map[int64]gmodel.FsProductPrice)
|
mapProductPrice := make(map[string]gmodel.FsProductPrice)
|
||||||
for _, v := range productPriceList {
|
for _, v := range productPriceList {
|
||||||
mapProductPrice[*v.SizeId] = v
|
mapProductPrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
||||||
}
|
}
|
||||||
//组装返回
|
//组装返回
|
||||||
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
list := make([]types.GetSizeByProductRsp, 0, len(tagsList))
|
||||||
|
@ -103,7 +103,7 @@ func (l *GetSizeByProductLogic) GetSizeByProduct(req *types.Request, userinfo *a
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第一层子层
|
// 第一层子层
|
||||||
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productList []gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenList []types.Children, err error) {
|
||||||
childrenList = make([]types.Children, 0, len(productList))
|
childrenList = make([]types.Children, 0, len(productList))
|
||||||
for _, product := range productList {
|
for _, product := range productList {
|
||||||
if *product.Type != tag.Id {
|
if *product.Type != tag.Id {
|
||||||
|
@ -126,14 +126,14 @@ func (l *GetSizeByProductLogic) GetFirstChildrenList(tag gmodel.FsTags, productL
|
||||||
}
|
}
|
||||||
|
|
||||||
// 第2层子层
|
// 第2层子层
|
||||||
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[int64]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
func (l *GetSizeByProductLogic) GetSecondChildrenList(product gmodel.FsProduct, productSizeList []gmodel.FsProductSize, mapProductPrice map[string]gmodel.FsProductPrice) (childrenObjList []types.ChildrenObj, err error) {
|
||||||
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
childrenObjList = make([]types.ChildrenObj, 0, len(productSizeList))
|
||||||
for _, productSize := range productSizeList {
|
for _, productSize := range productSizeList {
|
||||||
if product.Id != *productSize.ProductId {
|
if product.Id != *productSize.ProductId {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
priceList := make([]types.PriceObj, 0, len(productSizeList))
|
||||||
price, ok := mapProductPrice[productSize.Id]
|
price, ok := mapProductPrice[fmt.Sprintf("%d_%d", *productSize.ProductId, productSize.Id)]
|
||||||
//无对应尺寸价格
|
//无对应尺寸价格
|
||||||
if !ok {
|
if !ok {
|
||||||
priceList = []types.PriceObj{
|
priceList = []types.PriceObj{
|
||||||
|
|
|
@ -69,7 +69,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
mapSize = make(map[int64]gmodel.FsProductSize)
|
mapSize = make(map[int64]gmodel.FsProductSize)
|
||||||
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
mapModel = make(map[int64]gmodel.FsProductModel3d)
|
||||||
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
mapTemplate = make(map[int64]gmodel.FsProductTemplateV2)
|
||||||
mapSizePrice = make(map[int64]gmodel.FsProductPrice)
|
mapSizePrice = make(map[string]gmodel.FsProductPrice)
|
||||||
|
mapProduct = make(map[int64]struct{})
|
||||||
)
|
)
|
||||||
//获取相关信息
|
//获取相关信息
|
||||||
err = l.GetRelationInfo(GetRelationInfoReq{
|
err = l.GetRelationInfo(GetRelationInfoReq{
|
||||||
|
@ -78,6 +79,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
MapModel: mapModel,
|
MapModel: mapModel,
|
||||||
MapTemplate: mapTemplate,
|
MapTemplate: mapTemplate,
|
||||||
MapSizePrice: mapSizePrice,
|
MapSizePrice: mapSizePrice,
|
||||||
|
MapProduct: mapProduct,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||||
|
@ -93,6 +95,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
MapTemplate: mapTemplate,
|
MapTemplate: mapTemplate,
|
||||||
MapCartChange: mapCartChange,
|
MapCartChange: mapCartChange,
|
||||||
MapSnapshot: mapSnapshot,
|
MapSnapshot: mapSnapshot,
|
||||||
|
MapProduct: mapProduct,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
|
logx.Error("VerifyShoppingCartSnapshotDataChange err:", err.Error())
|
||||||
|
@ -102,7 +105,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
list := make([]types.CartItem, 0, len(carts))
|
list := make([]types.CartItem, 0, len(carts))
|
||||||
for _, cart := range carts {
|
for _, cart := range carts {
|
||||||
snapShot := mapSnapshot[cart.Id]
|
snapShot := mapSnapshot[cart.Id]
|
||||||
sizePrice, ok := mapSizePrice[*cart.SizeId]
|
sizePrice, ok := mapSizePrice[fmt.Sprintf("%d_%d", *cart.ProductId, *cart.SizeId)]
|
||||||
if !ok {
|
if !ok {
|
||||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price info is not exists:%d", *cart.SizeId))
|
return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("the size`s price info is not exists:%d", *cart.SizeId))
|
||||||
}
|
}
|
||||||
|
@ -126,15 +129,12 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
//购买箱数
|
//购买箱数
|
||||||
boxQuantity := int(math.Ceil(float64(*cart.PurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
boxQuantity := int(math.Ceil(float64(*cart.PurchaseQuantity) / float64(*sizePrice.EachBoxNum)))
|
||||||
//获取阶梯数量
|
//获取阶梯数量
|
||||||
stepQuantityList := make([]types.StepNumItem, 0, 10)
|
stepQuantityList := make([]int64, 0, 20)
|
||||||
tmpMinBuyNum := *sizePrice.MinBuyNum
|
tmpMinBuyNum := *sizePrice.MinBuyNum
|
||||||
for tmpMinBuyNum < (int64(stepNum[lenStepNum-1]) + 5) {
|
for tmpMinBuyNum < (int64(stepNum[lenStepNum-1]) + 5) {
|
||||||
//阶梯数
|
//阶梯数
|
||||||
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
|
tmpQuantity := tmpMinBuyNum * (*sizePrice.EachBoxNum)
|
||||||
stepQuantityList = append(stepQuantityList, types.StepNumItem{
|
stepQuantityList = append(stepQuantityList, tmpQuantity)
|
||||||
PurchaseQuantity: tmpQuantity,
|
|
||||||
IsSelected: *cart.PurchaseQuantity == tmpQuantity,
|
|
||||||
})
|
|
||||||
tmpMinBuyNum++
|
tmpMinBuyNum++
|
||||||
}
|
}
|
||||||
//根据数量获取阶梯价格中对应的价格
|
//根据数量获取阶梯价格中对应的价格
|
||||||
|
@ -169,6 +169,7 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
Qrcode: snapShot.UserDiyInformation.Qrcode,
|
Qrcode: snapShot.UserDiyInformation.Qrcode,
|
||||||
Slogan: snapShot.UserDiyInformation.Slogan,
|
Slogan: snapShot.UserDiyInformation.Slogan,
|
||||||
},
|
},
|
||||||
|
PurchaseQuantity: *cart.PurchaseQuantity,
|
||||||
StepNum: stepQuantityList,
|
StepNum: stepQuantityList,
|
||||||
IsInvalid: false,
|
IsInvalid: false,
|
||||||
InvalidDescription: "",
|
InvalidDescription: "",
|
||||||
|
@ -197,7 +198,8 @@ type GetRelationInfoReq struct {
|
||||||
MapSize map[int64]gmodel.FsProductSize
|
MapSize map[int64]gmodel.FsProductSize
|
||||||
MapModel map[int64]gmodel.FsProductModel3d
|
MapModel map[int64]gmodel.FsProductModel3d
|
||||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||||
MapSizePrice map[int64]gmodel.FsProductPrice
|
MapSizePrice map[string]gmodel.FsProductPrice
|
||||||
|
MapProduct map[int64]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
||||||
|
@ -205,10 +207,21 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
||||||
templateIds := make([]int64, 0, lenCarts)
|
templateIds := make([]int64, 0, lenCarts)
|
||||||
modelIds := make([]int64, 0, lenCarts) //模型 + 配件
|
modelIds := make([]int64, 0, lenCarts) //模型 + 配件
|
||||||
sizeIds := make([]int64, 0, lenCarts)
|
sizeIds := make([]int64, 0, lenCarts)
|
||||||
|
productIds := make([]int64, 0, lenCarts)
|
||||||
for index := range req.Carts {
|
for index := range req.Carts {
|
||||||
templateIds = append(templateIds, *req.Carts[index].TemplateId)
|
templateIds = append(templateIds, *req.Carts[index].TemplateId)
|
||||||
modelIds = append(modelIds, *req.Carts[index].ModelId, *req.Carts[index].FittingId)
|
modelIds = append(modelIds, *req.Carts[index].ModelId, *req.Carts[index].FittingId)
|
||||||
sizeIds = append(sizeIds, *req.Carts[index].SizeId)
|
sizeIds = append(sizeIds, *req.Carts[index].SizeId)
|
||||||
|
productIds = append(productIds, *req.Carts[index].ProductId)
|
||||||
|
}
|
||||||
|
//获取产品集合
|
||||||
|
productList, err := l.svcCtx.AllModels.FsProduct.GetProductListByIds(l.ctx, productIds, "", "id")
|
||||||
|
if err != nil {
|
||||||
|
logx.Error(err)
|
||||||
|
return errors.New("failed to get product list")
|
||||||
|
}
|
||||||
|
for _, v := range productList {
|
||||||
|
req.MapProduct[v.Id] = struct{}{}
|
||||||
}
|
}
|
||||||
//获取尺寸列表
|
//获取尺寸列表
|
||||||
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")
|
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByIds(l.ctx, sizeIds, "")
|
||||||
|
@ -238,13 +251,13 @@ func (l *GetCartsLogic) GetRelationInfo(req GetRelationInfoReq) error {
|
||||||
req.MapTemplate[v.Id] = v
|
req.MapTemplate[v.Id] = v
|
||||||
}
|
}
|
||||||
//根据sizeid获取价格列表
|
//根据sizeid获取价格列表
|
||||||
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListBySizeIds(l.ctx, sizeIds)
|
priceList, err := l.svcCtx.AllModels.FsProductPrice.GetPriceListByProductIdsSizeIds(l.ctx, productIds, sizeIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
return errors.New("failed to get cart`s product price list")
|
return errors.New("failed to get cart`s product price list")
|
||||||
}
|
}
|
||||||
for _, v := range priceList {
|
for _, v := range priceList {
|
||||||
req.MapSizePrice[*v.SizeId] = v
|
req.MapSizePrice[fmt.Sprintf("%d_%d", *v.ProductId, *v.SizeId)] = v
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,16 +50,12 @@ type CartItem struct {
|
||||||
ItemPrice string `json:"item_price"` //单价
|
ItemPrice string `json:"item_price"` //单价
|
||||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||||
StepNum []StepNumItem `json:"step_num"` //阶梯数量
|
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
}
|
}
|
||||||
|
|
||||||
type StepNumItem struct {
|
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
|
||||||
IsSelected bool `json:"is_selected"` //是否选中
|
|
||||||
}
|
|
||||||
|
|
||||||
type SizeInfo struct {
|
type SizeInfo struct {
|
||||||
SizeId int64 `json:"size_id"` //尺寸id
|
SizeId int64 `json:"size_id"` //尺寸id
|
||||||
Capacity string `json:"capacity"` //尺寸名称
|
Capacity string `json:"capacity"` //尺寸名称
|
||||||
|
|
|
@ -66,14 +66,11 @@ type CartItem {
|
||||||
ItemPrice string `json:"item_price"` //单价
|
ItemPrice string `json:"item_price"` //单价
|
||||||
TotalPrice string `json:"total_price"` //单价X数量=总价
|
TotalPrice string `json:"total_price"` //单价X数量=总价
|
||||||
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
DiyInformation DiyInformation `json:"diy_information"` //diy信息
|
||||||
StepNum []StepNumItem `json:"step_num"` //阶梯数量
|
StepNum []int64 `json:"step_num"` //阶梯数量
|
||||||
|
PurchaseQuantity int64 `json:"purchase_quantity"` //当前购买数量
|
||||||
IsInvalid bool `json:"is_invalid"` //是否无效
|
IsInvalid bool `json:"is_invalid"` //是否无效
|
||||||
InvalidDescription string `json:"invalid_description"` //无效原因
|
InvalidDescription string `json:"invalid_description"` //无效原因
|
||||||
}
|
}
|
||||||
type StepNumItem {
|
|
||||||
PurchaseQuantity int64 `json:"purchase_quantity"` //数量
|
|
||||||
IsSelected bool `json:"is_selected"` //是否选中
|
|
||||||
}
|
|
||||||
type SizeInfo {
|
type SizeInfo {
|
||||||
SizeId int64 `json:"size_id"` //尺寸id
|
SizeId int64 `json:"size_id"` //尺寸id
|
||||||
Capacity string `json:"capacity"` //尺寸名称
|
Capacity string `json:"capacity"` //尺寸名称
|
||||||
|
|
|
@ -15,10 +15,16 @@ type VerifyShoppingCartSnapshotDataChangeReq struct {
|
||||||
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
MapTemplate map[int64]gmodel.FsProductTemplateV2
|
||||||
MapCartChange map[int64]string
|
MapCartChange map[int64]string
|
||||||
MapSnapshot map[int64]CartSnapshot
|
MapSnapshot map[int64]CartSnapshot
|
||||||
|
MapProduct map[int64]struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error {
|
func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChangeReq) error {
|
||||||
for _, cartInfo := range req.Carts {
|
for _, cartInfo := range req.Carts {
|
||||||
|
descrptionBuilder := strings.Builder{}
|
||||||
|
//产品下架/删除
|
||||||
|
if _, ok := req.MapProduct[*cartInfo.ProductId]; !ok {
|
||||||
|
descrptionBuilder.WriteString("<p>the product is off shelf or deleted </p>")
|
||||||
|
}
|
||||||
var snapShotParseInfo CartSnapshot
|
var snapShotParseInfo CartSnapshot
|
||||||
if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil {
|
if err := json.Unmarshal([]byte(*cartInfo.Snapshot), &snapShotParseInfo); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -30,7 +36,6 @@ func VerifyShoppingCartSnapshotDataChange(req VerifyShoppingCartSnapshotDataChan
|
||||||
snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson)
|
snapshotModelJsonHash := hash.JsonHashKey(snapShotParseInfo.ModelInfo.ModelJson)
|
||||||
//快照中配件设计json数据哈希值
|
//快照中配件设计json数据哈希值
|
||||||
snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson)
|
snapshotFittingJsonHash := hash.JsonHashKey(snapShotParseInfo.FittingInfo.FittingJson)
|
||||||
descrptionBuilder := strings.Builder{}
|
|
||||||
//有模板验证模板相关
|
//有模板验证模板相关
|
||||||
if *cartInfo.TemplateId > 0 {
|
if *cartInfo.TemplateId > 0 {
|
||||||
if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok {
|
if curTemplateInfo, ok := req.MapTemplate[*cartInfo.TemplateId]; !ok {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user