From 2cc07d6bde99504d8cd4b70fb1bf756e608e8b5e Mon Sep 17 00:00:00 2001 From: kanade Date: Fri, 19 Aug 2022 16:27:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=93=E5=AD=98=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/mobile/order_preview/normal_create.go | 37 +++++++++++++++++++ internal/v2/lib/supply/api.go | 1 + internal/v2/lib/supply/order.go | 34 +++++++++++++++++ internal/v2/lib/supply/sku.go | 3 ++ 4 files changed, 75 insertions(+) create mode 100644 internal/v2/lib/supply/order.go diff --git a/internal/api/mobile/order_preview/normal_create.go b/internal/api/mobile/order_preview/normal_create.go index e02c7a0..9ae4a4b 100755 --- a/internal/api/mobile/order_preview/normal_create.go +++ b/internal/api/mobile/order_preview/normal_create.go @@ -20,6 +20,7 @@ import ( "recook/internal/model/vend" "recook/internal/v2/lib/jcook" "recook/internal/v2/lib/shama" + "recook/internal/v2/lib/supply" "recook/internal/v2/model/flashsale" goods2 "recook/internal/v2/model/recook/goods" "recook/tools" @@ -295,6 +296,42 @@ func CreatePreviewNormalOrder(c *gin.Context) { } expressFee = resp2.Fee preOrderAddr.IsDeliveryArea = 1 + case 5: // 供应链接口 + if len(p.Address) == 0 { + p.Address = defaultAddr.GetAddress() + } + id, _ := strconv.Atoi(sku.ThirdPartySkuId) + stock, err := supply.Api.Sku.Stock(p.Address, []supply.SkuStockItem{{ + SkuId: uint(id), + Quantity: 1, + }}) + if err != nil { + back.Err(c, err.Error()) + return + } + for _, skuStock := range stock { + if skuStock.State == supply.SkuStateOut { + back.Err(c, "该地区该商品无货") + return + } + } + freightFees, err := supply.Api.Order.FreightFee(p.Address, []supply.OrderFreightFeeItem{{ + SkuId: uint(id), + Quantity: 1, + Price: sku.PurchasePrice, + }}) + if err != nil { + back.Err(c, err.Error()) + return + } + for _, freightFee := range freightFees { + if freightFee.ErrCode == supply.ReplyOrderFreightFeeErrCodeErr { + back.Err(c, freightFee.ErrMsg) + return + } + expressFee = expressFee.Add(freightFee.FreightFee) + } + preOrderAddr.IsDeliveryArea = 1 } } else if defaultAddr.ID > 0 { diff --git a/internal/v2/lib/supply/api.go b/internal/v2/lib/supply/api.go index 2f27445..e7d9f37 100644 --- a/internal/v2/lib/supply/api.go +++ b/internal/v2/lib/supply/api.go @@ -17,6 +17,7 @@ var Api = &api{} type api struct { Config Config Sku sku + Order order Mq mq } type Config struct { diff --git a/internal/v2/lib/supply/order.go b/internal/v2/lib/supply/order.go new file mode 100644 index 0000000..4658962 --- /dev/null +++ b/internal/v2/lib/supply/order.go @@ -0,0 +1,34 @@ +package supply + +import "github.com/shopspring/decimal" + +const ( + orderFreightFee = "/order/freight_fee" // 获取运费 + + ReplyOrderFreightFeeErrCodeNone = 0 // 无错误 + ReplyOrderFreightFeeErrCodeErr = 1 // 有错误 +) + +type order struct { +} + +type OrderFreightFeeItem struct { + SkuId uint `binding:"required" label:"skuId"` + Quantity uint `binding:"required" label:"数量"` + Price decimal.Decimal `binding:"required" label:"价格"` +} +type ReplyOrderFreightFee struct { + SkuIds []uint `json:"skuIds"` + FreightFee decimal.Decimal `json:"freightFee"` + ErrCode uint `json:"errCode"` + ErrMsg string `json:"errMsg"` +} + +// FreightFee @Title 获取运费 +func (o *order) FreightFee(address string, skus []OrderFreightFeeItem) (result []ReplyOrderFreightFee, err error) { + err = exec(orderFreightFee, map[string]interface{}{ + "address": address, + "skus": skus, + }, &result) + return +} diff --git a/internal/v2/lib/supply/sku.go b/internal/v2/lib/supply/sku.go index 4d559a9..f4ba471 100644 --- a/internal/v2/lib/supply/sku.go +++ b/internal/v2/lib/supply/sku.go @@ -6,6 +6,9 @@ const ( skuPrices = "/sku/prices" // 商品价格 skuGroups = "/sku/groups" // 商品分组信息 skuStock = "/sku/stock" // 商品库存 + + SkuStateIn = 1 // 有货 + SkuStateOut = 2 // 无货 ) type sku struct {