Merge branch 'feature/mhw-v1.01' of https://gitee.com/fusenpack/fusenapi into develop
This commit is contained in:
commit
20932677ad
|
@ -108,19 +108,35 @@ type OrderStatus struct {
|
|||
|
||||
// 订单商品
|
||||
type OrderProduct struct {
|
||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||
ProductID int64 `json:"product_id"` // 商品ID
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照
|
||||
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
||||
DiyInformation *UserDiyInformation `json:"diy_information"`
|
||||
FittingInfo *FittingInfo `json:"fitting_info"`
|
||||
ProductCover string `json:"product_cover"` // 商品封面
|
||||
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
||||
ProductSn string `json:"product_sn"` // 商品编码
|
||||
SizeInfo *SizeInfo `json:"size_info"`
|
||||
StepNum []int `json:"step_num"` // 阶梯数量
|
||||
TotalPrice AmountInfo `json:"amount"` // 商品总价
|
||||
ExpectedDeliveryTime time.Time `json:"expected_delivery_time"` // 预计到货时间
|
||||
PurchaseQuantity int64 `json:"purchase_quantity"` // 购买数量
|
||||
ProductID int64 `json:"product_id"` // 商品ID
|
||||
ProductName string `json:"product_name"` // 商品名称
|
||||
ItemPrice AmountInfo `json:"product_price"` // 商品单价
|
||||
ProductSnapshot map[string]interface{} `json:"product_snapshot"` // 商品快照
|
||||
ShoppingCartSnapshot *FsShoppingCart `json:"shopping_cart_snapshot"` // 购物车快照
|
||||
ProductCover string `json:"product_cover"` // 商品封面
|
||||
ProductCoverMetadata map[string]interface{} `json:"product_cover_metadata"` // 商品封面
|
||||
ProductSn string `json:"product_sn"` // 商品编码
|
||||
DiyInformation *UserDiyInformation `json:"diy_information"`
|
||||
SizeInfo *OrderProductSizeInfo `json:"size_info"`
|
||||
FittingInfo *OrderProductFittingInfo `json:"fitting_info"`
|
||||
StepNum []int `json:"step_num"` // 阶梯数量
|
||||
}
|
||||
|
||||
type OrderProductSizeInfo struct {
|
||||
SizeID int64 `json:"size_id"`
|
||||
Capacity string `json:"capacity"`
|
||||
Title OrderProductSizeInfoTitle `json:"title"`
|
||||
}
|
||||
|
||||
type OrderProductSizeInfoTitle struct {
|
||||
Inch string `json:"inch"`
|
||||
Cm string `json:"cm"`
|
||||
}
|
||||
|
||||
type OrderProductFittingInfo struct {
|
||||
FittingID int64 `json:"fitting_id"` //配件ID
|
||||
FittingName string `json:"fitting_name"` //配件名称
|
||||
}
|
||||
|
|
|
@ -4,15 +4,10 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"fusenapi/constants"
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/basic"
|
||||
"fusenapi/utils/format"
|
||||
"fusenapi/utils/order"
|
||||
"fusenapi/utils/step_price"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
|
@ -209,43 +204,12 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
}
|
||||
|
||||
/* 计算价格 */
|
||||
|
||||
//阶梯数量切片
|
||||
stepNum, err := format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepNum, ","))
|
||||
productPrice, productTotalPrice, stepNum, stepPrice, err := NewShoppingCart(tx, nil, nil).CaculateCartPrice(*shoppingCart.PurchaseQuantity, shoppingCartProductPrice, *shoppingCart.ShoppingCartProductModel3dFitting.Price)
|
||||
if err != nil {
|
||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||
errorCode.Message = fmt.Sprintf("failed to parse step number:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
|
||||
return errors.New(errorCode.Message)
|
||||
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
||||
return err
|
||||
}
|
||||
lenStepNum := len(stepNum)
|
||||
//阶梯价格切片
|
||||
stepPrice, err = format.StrSlicToIntSlice(strings.Split(*shoppingCartProductPrice.StepPrice, ","))
|
||||
if err != nil {
|
||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||
errorCode.Message = fmt.Sprintf("failed to parse step price:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
lenStepPrice := len(stepPrice)
|
||||
if lenStepPrice == 0 || lenStepNum == 0 {
|
||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||
errorCode.Message = fmt.Sprintf("step price or step number is not set:%d_%d", *shoppingCart.ProductId, *shoppingCart.SizeId)
|
||||
return errors.New(errorCode.Message)
|
||||
}
|
||||
// 购买数量
|
||||
reqPurchaseQuantity := *shoppingCart.PurchaseQuantity
|
||||
// 购买箱数
|
||||
boxQuantity := int(math.Ceil(float64(reqPurchaseQuantity) / float64(*shoppingCartProductPrice.EachBoxNum)))
|
||||
// 根据数量获取阶梯价格中对应的价格
|
||||
productPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||
// 如果有配件,单价也要加入配件价格
|
||||
if *shoppingCart.FittingId > 0 {
|
||||
if shoppingCart.ShoppingCartProductModel3dFitting != nil {
|
||||
productPrice = productPrice + *shoppingCart.ShoppingCartProductModel3dFitting.Price
|
||||
}
|
||||
}
|
||||
// 单个购物车总价(厘)
|
||||
productTotalPrice := productPrice * reqPurchaseQuantity
|
||||
|
||||
/* 计算价格 */
|
||||
|
||||
// 订单商品总价(厘)
|
||||
|
@ -283,9 +247,19 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||
ShoppingCartSnapshot: &shoppingCart.FsShoppingCart,
|
||||
ProductSn: *shoppingCart.ShoppingCartProduct.Sn,
|
||||
DiyInformation: &shoppingCartSnapshot.UserDiyInformation,
|
||||
FittingInfo: &shoppingCartSnapshot.FittingInfo,
|
||||
SizeInfo: &shoppingCartSnapshot.SizeInfo,
|
||||
StepNum: stepNum,
|
||||
FittingInfo: &gmodel.OrderProductFittingInfo{
|
||||
FittingID: *shoppingCart.FittingId,
|
||||
FittingName: shoppingCartSnapshot.FittingInfo.FittingName,
|
||||
},
|
||||
SizeInfo: &gmodel.OrderProductSizeInfo{
|
||||
SizeID: *shoppingCart.SizeId,
|
||||
Capacity: shoppingCartSnapshot.SizeInfo.Capacity,
|
||||
Title: gmodel.OrderProductSizeInfoTitle{
|
||||
Inch: shoppingCartSnapshot.SizeInfo.Inch,
|
||||
Cm: shoppingCartSnapshot.SizeInfo.Cm,
|
||||
},
|
||||
},
|
||||
StepNum: stepNum,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user