- avoid duplicaated sku name when creating mtps bill.

This commit is contained in:
gazebo
2018-07-29 17:08:42 +08:00
parent 2dab1637fe
commit 58e91a8f5c
2 changed files with 21 additions and 7 deletions

View File

@@ -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