fix
This commit is contained in:
parent
f72a0b9f7d
commit
ee92468392
|
@ -14,17 +14,17 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/shopping-cart/add_to_cart",
|
Path: "/api/shopping-cart/add",
|
||||||
Handler: AddToCartHandler(serverCtx),
|
Handler: AddToCartHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/shopping-cart/delete_cart",
|
Path: "/api/shopping-cart/delete",
|
||||||
Handler: DeleteCartHandler(serverCtx),
|
Handler: DeleteCartHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Path: "/api/shopping-cart/modify_cart_purchase_quantity",
|
Path: "/api/shopping-cart/modify",
|
||||||
Handler: ModifyCartPurchaseQuantityHandler(serverCtx),
|
Handler: ModifyCartPurchaseQuantityHandler(serverCtx),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -169,8 +169,14 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
tmpMinBuyNum++
|
tmpMinBuyNum++
|
||||||
}
|
}
|
||||||
//根据数量获取阶梯价格中对应的价格
|
//根据数量获取阶梯价格中对应的价格
|
||||||
itemPrice := step_price.GetStepPrice(boxQuantity, stepNum, stepPrice)
|
itemPrice := step_price.GetCentStepPrice(boxQuantity, stepNum, stepPrice)
|
||||||
totalPrice := itemPrice * float64(*cart.PurchaseQuantity)
|
//如果有配件,单价也要加入配件价格
|
||||||
|
if *cart.FittingId > 0 {
|
||||||
|
if curFittingInfo, ok := mapModel[*cart.FittingId]; ok {
|
||||||
|
itemPrice += *curFittingInfo.Price
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalPrice := itemPrice * (*cart.PurchaseQuantity)
|
||||||
item := types.CartItem{
|
item := types.CartItem{
|
||||||
ProductId: *cart.ProductId,
|
ProductId: *cart.ProductId,
|
||||||
SizeInfo: types.SizeInfo{
|
SizeInfo: types.SizeInfo{
|
||||||
|
@ -185,8 +191,8 @@ func (l *GetCartsLogic) GetCarts(req *types.GetCartsReq, userinfo *auth.UserInfo
|
||||||
FittingId: *cart.FittingId,
|
FittingId: *cart.FittingId,
|
||||||
FittingName: snapShot.FittingInfo.FittingName,
|
FittingName: snapShot.FittingInfo.FittingName,
|
||||||
},
|
},
|
||||||
ItemPrice: fmt.Sprintf("%.3f", itemPrice),
|
ItemPrice: fmt.Sprintf("%.3f", format.CentitoDollar(itemPrice)),
|
||||||
TotalPrice: fmt.Sprintf("%.3f", totalPrice),
|
TotalPrice: fmt.Sprintf("%.3f", format.CentitoDollar(totalPrice)),
|
||||||
DiyInformation: types.DiyInformation{
|
DiyInformation: types.DiyInformation{
|
||||||
Phone: snapShot.UserDiyInformation.Phone,
|
Phone: snapShot.UserDiyInformation.Phone,
|
||||||
Address: snapShot.UserDiyInformation.Address,
|
Address: snapShot.UserDiyInformation.Address,
|
||||||
|
|
|
@ -11,13 +11,13 @@ import "basic.api"
|
||||||
service shopping-cart {
|
service shopping-cart {
|
||||||
//加入购物车
|
//加入购物车
|
||||||
@handler AddToCartHandler
|
@handler AddToCartHandler
|
||||||
post /api/shopping-cart/add_to_cart(AddToCartReq) returns (response);
|
post /api/shopping-cart/add(AddToCartReq) returns (response);
|
||||||
//删除购物车
|
//删除购物车
|
||||||
@handler DeleteCartHandler
|
@handler DeleteCartHandler
|
||||||
post /api/shopping-cart/delete_cart(DeleteCartReq) returns (response);
|
post /api/shopping-cart/delete(DeleteCartReq) returns (response);
|
||||||
//修改购物车购买数量
|
//修改购物车购买数量
|
||||||
@handler ModifyCartPurchaseQuantityHandler
|
@handler ModifyCartPurchaseQuantityHandler
|
||||||
post /api/shopping-cart/modify_cart_purchase_quantity(ModifyCartPurchaseQuantityReq) returns (response);
|
post /api/shopping-cart/modify(ModifyCartPurchaseQuantityReq) returns (response);
|
||||||
//获取购物车列表
|
//获取购物车列表
|
||||||
@handler GetCartsHandler
|
@handler GetCartsHandler
|
||||||
get /api/shopping-cart/get_carts(GetCartsReq) returns (response);
|
get /api/shopping-cart/get_carts(GetCartsReq) returns (response);
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 美分转美元
|
// 厘转美元
|
||||||
func CentoDollar(price int64) float64 {
|
func CentitoDollar(price int64) float64 {
|
||||||
str := fmt.Sprintf("%.2f", float64(price)/float64(100))
|
str := fmt.Sprintf("%.3f", float64(price)/float64(1000))
|
||||||
dollar, _ := strconv.ParseFloat(str, 64)
|
dollar, _ := strconv.ParseFloat(str, 64)
|
||||||
return dollar
|
return dollar
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,20 +3,20 @@ package step_price
|
||||||
// 返回美元
|
// 返回美元
|
||||||
func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
|
func GetStepPrice(minBuyNum int, stepNum []int, stepPrice []int) float64 {
|
||||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||||
}
|
}
|
||||||
for k, v := range stepNum {
|
for k, v := range stepNum {
|
||||||
if minBuyNum <= v {
|
if minBuyNum <= v {
|
||||||
if k <= (len(stepPrice) - 1) {
|
if k <= (len(stepPrice) - 1) {
|
||||||
return float64(stepPrice[k]) / float64(100)
|
return float64(stepPrice[k]) / float64(1000)
|
||||||
}
|
}
|
||||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return float64(stepPrice[len(stepPrice)-1]) / float64(100)
|
return float64(stepPrice[len(stepPrice)-1]) / float64(1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 返回美分
|
// 返回厘
|
||||||
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
func GetCentStepPrice(minBuyNum int, stepNum []int, stepPrice []int) int64 {
|
||||||
if minBuyNum > stepNum[len(stepNum)-1] {
|
if minBuyNum > stepNum[len(stepNum)-1] {
|
||||||
return int64(stepPrice[len(stepPrice)-1])
|
return int64(stepPrice[len(stepPrice)-1])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user