From a04c1595bc9bdd2ebd966fcda369dc53504497ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 4 Jun 2020 09:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E6=96=99=E8=AE=A2=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=A1=A5=E8=B6=B3=E4=BA=94=E9=A6=99=E7=B2=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 48 +++++++++++++++---- business/partner/purchase/jx/localjx/order.go | 26 +++++++++- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index eea2c4007..74d031328 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -1104,7 +1104,8 @@ func result2Orders(ctx *jxcontext.Context, result *jdshopapi.AllOrdersResult) (o func TransferJdsOrder(ctx *jxcontext.Context, vendorOrderID string, storeID int) (err error) { globals.SugarLogger.Debugf("jds TransferJdsOrder vendorOrderID: %v, storeID : %v", vendorOrderID, storeID) var ( - db = dao.GetDB() + db = dao.GetDB() + waybill *model.Waybill ) order, err := dao.GetSimpleOrder(db, vendorOrderID) if err != nil || order == nil { @@ -1113,22 +1114,51 @@ func TransferJdsOrder(ctx *jxcontext.Context, vendorOrderID string, storeID int) if order.Status == model.OrderStatusFinished { return fmt.Errorf("暂不支持已完成的订单进行转移!") } - if len(order.VendorOrderID) > 12 { - suffix := utils.Str2Int(order.VendorOrderID[12:len(order.VendorOrderID)]) - suffix++ - order.VendorOrderID = order.VendorOrderID2 + utils.Int2Str(suffix) + if order.VendorID != model.VendorIDJDShop { + return fmt.Errorf("暂不支持非京狗的订单进行转移!") } skus, err := dao.GetSimpleOrderSkus(db, vendorOrderID) if err != nil || order == nil { return fmt.Errorf("未查询到该订单商品!订单号:[%v]", vendorOrderID) } + //将订单和运单取消 + if order.Status == model.OrderStatusDelivering { + waybills, err := dao.GetWaybills(db, vendorOrderID) + if err != nil || len(waybills) == 0 { + return fmt.Errorf("未查询到该订单对应的运单信息!订单号:[%v]", vendorOrderID) + } + for _, v := range waybills { + if v.Status != model.WaybillStatusCanceled { + waybill = v + } + } + handler := partner.DeliveryPlatformHandlers[waybill.WaybillVendorID] + err = handler.Handler.CancelWaybill(waybill, 0, "订单转移被取消") + if err != nil { + return err + } + } + err = jdshop.ChangeOrderStatus(vendorOrderID, model.OrderStatusCanceled, "订单转移被取消") + if err != nil { + return err + } + //重新构建order的数据 + storeMaps, err := dao.GetStoresMapList(db, []int{order.VendorID}, []int{order.StoreID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "") + if len(storeMaps) > 0 { + order.StoreID = storeID + order.StoreName = storeMaps[0].StoreName + } else { + return fmt.Errorf("未查询到该门店对应的平台信息!门店:[%v]", order.StoreID) + } + if len(order.VendorOrderID) > 12 { + suffix := utils.Str2Int(order.VendorOrderID[12:len(order.VendorOrderID)]) + suffix++ + order.VendorOrderID = order.VendorOrderID2 + utils.Int2Str(suffix) + } for _, sku := range skus { sku.VendorOrderID = order.VendorOrderID order.Skus = append(order.Skus, sku) } - err = jdshop.ChangeOrderStatus(vendorOrderID, model.OrderStatusCanceled, "订单转移被取消") - if order.Status == model.OrderStatusDelivering { - - } + err = partner.CurOrderManager.OnOrderNew(order, model.Order2Status(order)) return err } diff --git a/business/partner/purchase/jx/localjx/order.go b/business/partner/purchase/jx/localjx/order.go index 4613a34fd..7614f9449 100644 --- a/business/partner/purchase/jx/localjx/order.go +++ b/business/partner/purchase/jx/localjx/order.go @@ -49,7 +49,8 @@ const ( autoCancelOrderReason = "支付超时,系统自动取消!" cancelMatterOrderReason = "失败重发!" - splitMatterOrderMinWeight = 4500 //物料订单分包最少要4.5kg + splitMatterOrderMinWeight = 4500 //物料订单分包最少要4.5kg + jxwxfMatterEclpID = "EMG4418113943423" //京西五香粉物料编码 ) type JxSkuInfo struct { @@ -876,6 +877,7 @@ func orderSolutionForWuLiao(order *model.GoodsOrder) (err error) { goodsNos []string prices []string quantities []string + countSum int ) for _, v := range orderSkus { skus, err := dao.GetSkus(db, []int{v.SkuID}, nil, nil, nil, nil) @@ -885,6 +887,28 @@ func orderSolutionForWuLiao(order *model.GoodsOrder) (err error) { goodsNos = append(goodsNos, skus[0].EclpID) prices = append(prices, "0") quantities = append(quantities, utils.Int2Str(v.Count)) + countSum += v.Count + } + //总订单不足3kg && 商品数量不足3个 && 五香粉有库存,要送五香粉,补足3个 + stockResult, err := api.JdEclpAPI.QueryStock(jxwxfMatterEclpID) + if err == nil && len(stockResult) > 0 && stockResult[0].UsableNum > 0 { + if order.Weight < 3000 && countSum < 3 { + //要判断他本身买没买五香粉EMG4418113943423 + var index = 9999 + for k, v := range goodsNos { + if v == jxwxfMatterEclpID { + index = k + } + } + //说明他买了五香粉 + if index != 9999 { + quantities[index] = utils.Int2Str(utils.Str2Int(quantities[index]) + 3 - countSum) + } else { + goodsNos = append(goodsNos, jxwxfMatterEclpID) + prices = append(prices, "0") + quantities = append(quantities, utils.Int2Str(3-countSum)) + } + } } result, err := api.JdEclpAPI.AddOrder(&jdeclpapi.AddOrderParam{ IsvUUID: order.VendorOrderID,