From 7f939333df6948ccec5e7006e99a9bcb4dc2c1ac Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 11 Jun 2019 23:49:21 +0800 Subject: [PATCH] =?UTF-8?q?!=20GoodsOrder=E4=B8=8EOrderSku=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0VendorPrice=E8=A1=A8=E7=A4=BA=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E4=BB=B7=EF=BC=8C=E8=80=8CSalePrice=E8=A1=A8=E7=A4=BA=E5=8D=95?= =?UTF-8?q?=E5=93=81=E4=BC=98=E6=83=A0=E4=B9=8B=E5=90=8E=E7=9A=84=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 6 +-- business/jxutils/jxutils.go | 2 + business/model/order.go | 8 +-- business/partner/purchase/ebai/order.go | 26 +++++++++- business/partner/purchase/jd/order.go | 1 + business/partner/purchase/mtwm/order.go | 68 ++++++++++++++++--------- 6 files changed, 76 insertions(+), 35 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 29b0cfa9e..3179cc372 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -333,11 +333,7 @@ func (c *OrderManager) updateOrderOtherInfo(order *model.GoodsOrder, db *dao.Dao } order.JxStoreID = storeMap.StoreID if err = c.updateOrderSkuOtherInfo(order, db); err == nil { - if order.Weight == 0 { - for _, v := range order.Skus { - order.Weight += v.Weight - } - } + jxutils.RefreshOrderSkuRelated(order) } return err } diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 24cfc46c8..ba1ca74a3 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -447,11 +447,13 @@ func RefreshOrderSkuRelated(order *model.GoodsOrder) *model.GoodsOrder { order.SkuCount = 0 order.GoodsCount = 0 order.SalePrice = 0 + order.VendorPrice = 0 order.Weight = 0 for _, sku := range order.Skus { order.SkuCount++ order.GoodsCount += sku.Count order.SalePrice += sku.SalePrice * int64(sku.Count) + order.VendorPrice += sku.VendorPrice * int64(sku.Count) order.Weight += sku.Weight * sku.Count } return order diff --git a/business/model/order.go b/business/model/order.go index 9c53fff3b..1921d8d52 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -16,8 +16,9 @@ type GoodsOrder struct { StoreID int `orm:"column(store_id)" json:"storeID"` // 外部系统里记录的 jxstoreid JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid StoreName string `orm:"size(64)" json:"storeName"` - ShopPrice int64 `json:"shopPrice"` // 单位为分 门店标价 - SalePrice int64 `json:"salePrice"` // 单位为分 售卖价 + ShopPrice int64 `json:"shopPrice"` // 京西价 + VendorPrice int64 `json:"vendorPrice"` // 平台价 + SalePrice int64 `json:"salePrice"` // 售卖价 ActualPayPrice int64 `json:"actualPayPrice"` // 单位为分 顾客实际支付 Weight int `json:"weight"` // 单位为克 ConsigneeName string `orm:"size(32)" json:"consigneeName"` @@ -85,7 +86,8 @@ type OrderSku struct { SkuID int `orm:"column(sku_id)" json:"skuID"` // 外部系统里记录的 jxskuid JxSkuID int `orm:"column(jx_sku_id)" json:"jxSkuID"` // 根据VendorSkuID在本地系统里查询出来的 jxskuid SkuName string `orm:"size(255)" json:"skuName"` - ShopPrice int64 `json:"shopPrice"` // 门店标价 + ShopPrice int64 `json:"shopPrice"` // 京西价 + VendorPrice int64 `json:"vendorPrice"` // 平台价 SalePrice int64 `json:"salePrice"` // 售卖价 Weight int `json:"weight"` // 单位为克 SkuType int `json:"skuType"` // 当前如果为gift就为1,否则缺省为0 diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index 622fe7c31..757b03e1f 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -119,7 +119,8 @@ func (p *PurchaseHandler) partRefund2OrderDetailSkuList(orderID string, orderDet VendorSkuID: utils.Interface2String(product[ebaiapi.KeySkuID]), SkuName: skuName, // Weight: int(utils.Interface2Int64WithDefault(product["total_weight"], 0)) / number, // 退单这里的total_weight有BUG,这里的total_weight还是没有退单时的值 - SalePrice: utils.MustInterface2Int64(product["product_price"]), + VendorPrice: utils.MustInterface2Int64(product["product_price"]), + SalePrice: getSkuSalePrice(product), } if sku.Weight == 0 { sku.Weight = jxutils.FormatSkuWeight(specQuality, specUnit) // 订单信息里没有重量,只有名字里尝试找 @@ -204,7 +205,8 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo VendorSkuID: utils.Interface2String(product["baidu_product_id"]), SkuName: skuName, Weight: int(utils.Interface2Int64WithDefault(product["total_weight"], 0)) / productAmount, - SalePrice: utils.MustInterface2Int64(product["product_price"]), + VendorPrice: utils.MustInterface2Int64(product["product_price"]), + SalePrice: getSkuSalePrice(product), // PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), } if sku.Weight == 0 { @@ -219,6 +221,26 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo return order } +func getSkuSalePrice(product map[string]interface{}) (salePrice int64) { + var product2 *ebaiapi.OrderProductInfo + if err := utils.Map2StructByJson(product, &product2, true); err != nil { + return utils.MustInterface2Int64(product["product_price"]) + } + return int64(getSkuSalePrice2(product2)) +} + +func getSkuSalePrice2(product *ebaiapi.OrderProductInfo) (salePrice int) { + salePrice = product.ProductPrice + if product.ProductSubsidy != nil { + for _, v := range product.ProductSubsidy.DiscountDetail { + if v.Type == ebaiapi.OrderSkuDiscountTypeZhe { + salePrice -= v.BaiduRate + v.ShopRate + } + } + } + return salePrice +} + func (p *PurchaseHandler) AcceptOrRefuseOrder(order *model.GoodsOrder, isAcceptIt bool, userName string) (err error) { globals.SugarLogger.Debugf("ebai AcceptOrRefuseOrder orderID:%s, isAcceptIt:%t", order.VendorOrderID, isAcceptIt) if isAcceptIt { diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index a5415fdb3..90bb81281 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -160,6 +160,7 @@ func (c *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo VendorSkuID: utils.Int64ToStr(utils.MustInterface2Int64(product["skuId"])), SkuName: product["skuName"].(string), Weight: jxutils.FloatWeight2Int(float32(utils.MustInterface2Float64(product["skuWeight"]))), + VendorPrice: utils.MustInterface2Int64(product["skuStorePrice"]), SalePrice: utils.MustInterface2Int64(product["skuJdPrice"]), PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), } diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index e81a39b75..8e1d9e03e 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -5,6 +5,7 @@ import ( "fmt" "net/url" "regexp" + "strings" "time" "git.rosy.net.cn/baseapi/platformapi/mtwmapi" @@ -62,6 +63,12 @@ var ( fakeUserUndoApplyCancel: model.OrderStatusUndoApplyCancel, fakeMerchantAgreeApplyCancel: model.OrderStatusCanceled, } + + skuActTypeMap = map[int]int{ + mtwmapi.ExtrasPromotionTypeTeJiaCai: 1, + mtwmapi.ExtrasPromotionTypeZheKouCai: 1, + mtwmapi.ExtrasPromotionTypeSecondHalfPrice: 1, + } ) func (p *PurchaseHandler) GetStatusFromVendorStatus(vendorStatus string) int { @@ -132,34 +139,10 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo if err := utils.UnmarshalUseNumber([]byte(result["detail"].(string)), &detail); err != nil { panic(fmt.Sprintf("mtwm Map2Order vendorID:%s failed with error:%v", vendorOrderID, err)) } - // detail := result["detail"].([]interface{}) - for _, product := range detail { - // product := product2.(map[string]interface{}) - skuName := product["food_name"].(string) - skuID := utils.Interface2String(product["sku_id"]) - sku := &model.OrderSku{ - VendorOrderID: order.VendorOrderID, - VendorID: model.VendorIDMTWM, - Count: int(utils.MustInterface2Float64(product["quantity"])), - SkuID: int(utils.Str2Int64WithDefault(skuID, 0)), - VendorSkuID: skuID, - SkuName: skuName, - Weight: getSkuWeight(product), - SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), - // PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), - } - if sku.Weight == 0 { - sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值 - } - // if product["isGift"].(bool) { - // sku.SkuType = 1 - // } - order.Skus = append(order.Skus, sku) - } // 添加需要赠送的东西 + var extraList []*mtwmapi.OrderExtraInfo if result["extras"] != nil { - var extraList []*mtwmapi.OrderExtraInfo if err := utils.UnmarshalUseNumber([]byte(result["extras"].(string)), &extraList); err != nil { panic(fmt.Sprintf("mtwm Map2Order vendorID:%s failed with error:%v", vendorOrderID, err)) } @@ -180,6 +163,41 @@ func (p *PurchaseHandler) Map2Order(orderData map[string]interface{}) (order *mo } } + ignoreSkuMap := make(map[int]int) + // detail := result["detail"].([]interface{}) + for _, product := range detail { + // product := product2.(map[string]interface{}) + skuName := product["food_name"].(string) + skuID := utils.Interface2String(product["sku_id"]) + sku := &model.OrderSku{ + VendorOrderID: order.VendorOrderID, + VendorID: model.VendorIDMTWM, + Count: int(utils.MustInterface2Float64(product["quantity"])), + SkuID: int(utils.Str2Int64WithDefault(skuID, 0)), + VendorSkuID: skuID, + SkuName: skuName, + Weight: getSkuWeight(product), + VendorPrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), + SalePrice: jxutils.StandardPrice2Int(utils.MustInterface2Float64(product["price"])), + // PromotionType: int(utils.MustInterface2Int64(product["promotionType"])), + } + if sku.Weight == 0 { + sku.Weight = 222 // 如果名字里找不到缺省给半斤左右的一个特别值 + } + if ignoreSkuMap[sku.SkuID] == 0 && sku.Count == 1 { + for _, v := range extraList { + if skuActTypeMap[v.Type] == 1 && strings.Index(v.Remark, skuName) >= 0 { + ignoreSkuMap[sku.SkuID] = 1 + sku.SalePrice -= jxutils.StandardPrice2Int(v.ReduceFee) + } + } + } + // if product["isGift"].(bool) { + // sku.SkuType = 1 + // } + order.Skus = append(order.Skus, sku) + } + jxutils.RefreshOrderSkuRelated(order) return order }