物料订单增加补足五香粉
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user