fix:合并
This commit is contained in:
parent
86450d3c9d
commit
95b826d8a6
@ -7,6 +7,7 @@ import (
|
|||||||
"fusenapi/model/gmodel"
|
"fusenapi/model/gmodel"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
"fusenapi/utils/shopping_cart"
|
"fusenapi/utils/shopping_cart"
|
||||||
|
"fusenapi/utils/step_price"
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
@ -85,13 +86,13 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||||||
// 商品异常
|
// 商品异常
|
||||||
if shoppingCart.ShoppingCartProduct == nil || (shoppingCart.ShoppingCartProduct != nil && *shoppingCart.ShoppingCartProduct.IsShelf == 0) {
|
if shoppingCart.ShoppingCartProduct == nil || (shoppingCart.ShoppingCartProduct != nil && *shoppingCart.ShoppingCartProduct.IsShelf == 0) {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductAbsent
|
errorCode = *basic.CodeErrOrderCreatProductAbsent
|
||||||
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
errorCode.Message = "create order failed, product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
}
|
}
|
||||||
// 商品价格异常
|
// 商品价格异常
|
||||||
if len(shoppingCart.ShoppingCartProductPriceList) == 0 {
|
if len(shoppingCart.ShoppingCartProductPriceList) == 0 {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
} else {
|
} else {
|
||||||
var isProductPrice bool
|
var isProductPrice bool
|
||||||
@ -104,7 +105,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||||||
}
|
}
|
||||||
if !isProductPrice {
|
if !isProductPrice {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
errorCode.Message = "create order failed, price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
}
|
}
|
||||||
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
|
shoppingCart.ShoppingCartProductPriceList = []*gmodel.FsProductPrice{shoppingCartProductPrice}
|
||||||
@ -113,7 +114,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||||||
// 商品模型异常
|
// 商品模型异常
|
||||||
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
|
if len(shoppingCart.ShoppingCartProductModel3dList) == 0 {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
||||||
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
} else {
|
} else {
|
||||||
var isProductModel bool
|
var isProductModel bool
|
||||||
@ -126,7 +127,7 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||||||
}
|
}
|
||||||
if !isProductModel {
|
if !isProductModel {
|
||||||
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
errorCode = *basic.CodeErrOrderCreatProductAccessoryAbsent
|
||||||
errorCode.Message = "create order failed, accessoryof product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent。"
|
errorCode.Message = "create order failed, accessory of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is absent"
|
||||||
return errors.New(errorCode.Message)
|
return errors.New(errorCode.Message)
|
||||||
}
|
}
|
||||||
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
|
shoppingCart.ShoppingCartProductModel3dList = []*gmodel.FsProductModel3d{shoppingCartProductModel3d}
|
||||||
@ -134,7 +135,28 @@ func (d *defaultOrder) Create(ctx context.Context, in *CreateReq) (res *CreateRe
|
|||||||
|
|
||||||
var purchaseQuantity float64 = float64(*shoppingCart.PurchaseQuantity)
|
var purchaseQuantity float64 = float64(*shoppingCart.PurchaseQuantity)
|
||||||
var eachBoxNum float64 = float64(*shoppingCartProductPrice.EachBoxNum)
|
var eachBoxNum float64 = float64(*shoppingCartProductPrice.EachBoxNum)
|
||||||
var boxNum int64 = math.Ceil(purchaseQuantity / eachBoxNum)
|
var boxNum float64 = math.Ceil(purchaseQuantity / eachBoxNum)
|
||||||
|
var stepNum []int
|
||||||
|
var stepPrice []int
|
||||||
|
if *shoppingCartProductPrice.StepNum == "" {
|
||||||
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
|
errorCode.Message = "create order failed, step num of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
||||||
|
return errors.New(errorCode.Message)
|
||||||
|
} else {
|
||||||
|
json.Unmarshal([]byte(*shoppingCartProductPrice.StepNum), &stepNum)
|
||||||
|
}
|
||||||
|
if *shoppingCartProductPrice.StepPrice == "" {
|
||||||
|
errorCode = *basic.CodeErrOrderCreatProductPriceAbsent
|
||||||
|
errorCode.Message = "create order failed, step price of product '" + shoppingCartSnapshot.ProductInfo.ProductName + "'is failed"
|
||||||
|
return errors.New(errorCode.Message)
|
||||||
|
} else {
|
||||||
|
json.Unmarshal([]byte(*shoppingCartProductPrice.StepPrice), &stepPrice)
|
||||||
|
}
|
||||||
|
// 商品单价
|
||||||
|
productPrice := step_price.GetCentStepPrice(int(boxNum), stepNum, stepPrice)
|
||||||
|
|
||||||
|
// 商品总价
|
||||||
|
productTotalPrice := productPrice * *shoppingCart.PurchaseQuantity
|
||||||
|
|
||||||
// 存储订单商品
|
// 存储订单商品
|
||||||
orderProductList = append(orderProductList, &gmodel.OrderProduct{})
|
orderProductList = append(orderProductList, &gmodel.OrderProduct{})
|
||||||
|
@ -1,25 +1,19 @@
|
|||||||
package order
|
package order
|
||||||
|
|
||||||
import (
|
type AmountCurrency struct {
|
||||||
"fusenapi/constants"
|
ExchangeRate float64 `json:"exchange_rate"` // 换算汇率
|
||||||
"fusenapi/model/gmodel"
|
CurrentAmount float64 `json:"current_amount"` // 当前金额
|
||||||
"strconv"
|
OriginalAmount float64 `json:"original_amount"` // 原始金额
|
||||||
)
|
CurrentCurrency string `json:"current_currency"` // 当前货币
|
||||||
|
OriginalCurrency string `json:"original_currency"` // 原始货币
|
||||||
|
}
|
||||||
|
|
||||||
func GetAmountCurrency(req *gmodel.AmountCurrency) (*float64, error) {
|
// 汇率换算
|
||||||
|
func GetAmountCurrency(req *AmountCurrency) error {
|
||||||
if req.CurrentCurrency == req.OriginalCurrency {
|
if req.CurrentCurrency == req.OriginalCurrency {
|
||||||
req.CurrentAmount = req.OriginalAmount
|
req.CurrentAmount = req.OriginalAmount
|
||||||
} else {
|
} else {
|
||||||
f1, err1 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
req.CurrentAmount = req.OriginalAmount * req.ExchangeRate
|
||||||
if err1 != nil {
|
|
||||||
return nil, err1
|
|
||||||
}
|
|
||||||
f2, err2 := strconv.ParseFloat(string(req.OriginalAmount), 64)
|
|
||||||
if err2 != nil {
|
|
||||||
return nil, err2
|
|
||||||
}
|
|
||||||
result := f1 * f2
|
|
||||||
req.CurrentAmount = constants.AmountUnit(strconv.FormatFloat(result, 'f', -1, 64))
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user