- avoid duplicaated sku name when creating mtps bill.
This commit is contained in:
@@ -167,16 +167,26 @@ func (c *WaybillController) CreateWaybill(order *model.GoodsOrder) (err error) {
|
||||
goods := &mtpsapi.GoodsDetail{
|
||||
Goods: []*mtpsapi.GoodsItem{},
|
||||
}
|
||||
goodItemMap := map[string]*mtpsapi.GoodsItem{}
|
||||
for _, sku := range order.Skus {
|
||||
goodItem := &mtpsapi.GoodsItem{
|
||||
GoodCount: sku.Count,
|
||||
GoodPrice: jxutils.IntPrice2Standard(sku.SalePrice),
|
||||
}
|
||||
goodItem.GoodName, goodItem.GoodUnit = jxutils.SplitSkuName(sku.SkuName)
|
||||
goods.Goods = append(goods.Goods, goodItem)
|
||||
// 好像SKU名不能重复,否则会报错,尝试处理一下
|
||||
if item, ok := goodItemMap[goodItem.GoodName]; !ok {
|
||||
goods.Goods = append(goods.Goods, goodItem)
|
||||
goodItemMap[goodItem.GoodName] = goodItem
|
||||
} else {
|
||||
item.GoodCount += goodItem.GoodCount
|
||||
}
|
||||
}
|
||||
addParams := utils.Params2Map("note", order.BuyerComment, "goods_detail", string(utils.MustMarshal(goods)))
|
||||
_, err = api.MtpsAPI.CreateOrderByShop(billParams, addParams)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("CreateWaybill, orderID:%s, billParams:%v, addParams:%v", order.VendorOrderID, billParams, addParams)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user