diff --git a/server/shopping-cart/internal/handler/routes.go b/server/shopping-cart/internal/handler/routes.go index 9857154b..3a4188d6 100644 --- a/server/shopping-cart/internal/handler/routes.go +++ b/server/shopping-cart/internal/handler/routes.go @@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { Path: "/api/shopping-cart/get_carts", Handler: GetCartsHandler(serverCtx), }, + { + Method: http.MethodPost, + Path: "/api/shopping-cart/calculate_cart_price", + Handler: CalculateCartPriceHandler(serverCtx), + }, }, ) } diff --git a/server/shopping-cart/internal/types/types.go b/server/shopping-cart/internal/types/types.go index db117d2a..231c717e 100644 --- a/server/shopping-cart/internal/types/types.go +++ b/server/shopping-cart/internal/types/types.go @@ -80,6 +80,25 @@ type DiyInformation struct { Slogan string `json:"slogan"` } +type CalculateCartPriceReq struct { + CalculateList []CalculateItem `json:"calculate_list"` +} + +type CalculateItem struct { + CartId int64 `json:"cart_id"` //购物车id + PurchaseQuantity int64 `json:"purchase_quantity"` //数量 +} + +type CalculateCartPriceRsp struct { + CalculateResultList []CalculateResultItem `json:"calculate_result_list"` +} + +type CalculateResultItem struct { + CartId int64 `json:"cart_id"` //购物车id + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"total_price"` //总价 +} + type Request struct { } diff --git a/server_api/shopping-cart.api b/server_api/shopping-cart.api index 27249f45..5c3da538 100644 --- a/server_api/shopping-cart.api +++ b/server_api/shopping-cart.api @@ -21,6 +21,9 @@ service shopping-cart { //获取购物车列表 @handler GetCartsHandler get /api/shopping-cart/get_carts(GetCartsReq) returns (response); + //计算购物车价格 + @handler CalculateCartPriceHandler + post /api/shopping-cart/calculate_cart_price(CalculateCartPriceReq) returns (response); } //加入购物车 @@ -90,4 +93,21 @@ type DiyInformation { Website string `json:"website"` Qrcode string `json:"qrcode"` Slogan string `json:"slogan"` +} + +//计算购物车价格 +type CalculateCartPriceReq { + CalculateList []CalculateItem `json:"calculate_list"` +} +type CalculateItem { + CartId int64 `json:"cart_id"` //购物车id + PurchaseQuantity int64 `json:"purchase_quantity"` //数量 +} +type CalculateCartPriceRsp { + CalculateResultList []CalculateResultItem `json:"calculate_result_list"` +} +type CalculateResultItem { + CartId int64 `json:"cart_id"` //购物车id + ItemPrice string `json:"item_price"` //单价 + TotalPrice string `json:"total_price"` //总价 } \ No newline at end of file