Commit 2b937f1c by mushishixian

相同型号的数据获取问题

parent 8cc30883
......@@ -35,11 +35,12 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
//批量更新每一条记录之前,要去批量更新item表的item_status
for _, matching := range matchingList {
//先去数据库查询是否存在该记录,有的话修改,没有就新增
updateData := getUpdateData(matching)
var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
if match.BomItemID != 0 {
matching.UpdateTime = int(time.Now().Unix())
if err = model.Db.Table(tableName).Model(&match).Updates(matching).Error; err != nil {
if err = model.Db.Table(tableName).Model(&match).Updates(updateData).Error; err != nil {
return
}
} else {
......@@ -145,43 +146,25 @@ func RefreshBomMatchingGoods(bomId int) (err error) {
return
}
//刷新bom匹配的商品信息
func RefreshBomMatchingGoodsAbandon(bomId int) (err error) {
//先找出bom相关信息
var goodsIds []string
bomMatchings := GetBomMatchings(bomId)
for _, matching := range bomMatchings {
goodsIds = append(goodsIds, matching.GoodsID)
}
goodsIdsStr := strings.Join(goodsIds, ",")
//去请求商品服务
goodsList, err := GetGoodsInfo(goodsIdsStr)
if err != nil {
return
}
var bomMatchingList []model.BomItemMatching
for _, matching := range bomMatchings {
for _, goods := range goodsList {
if matching.GoodsID == goods.GoodsID {
var goodsMap GoodsMap
goodsMap.Number = matching.Number
goodsMap.GoodsName = matching.GoodsName
goodsMap.DeliveryType = matching.DeliveryType
goodsMap.BomId = matching.BomID
goodsMap.BomItemId = matching.BomItemID
goodsMap.GoodsId = matching.GoodsID
//组装需要去更新的商品信息
bomMatching, err := MatchGoodsInfo(goods, goodsMap)
if err != nil {
return err
}
bomMatchingList = append(bomMatchingList, bomMatching)
}
}
func getUpdateData(matching model.BomItemMatching) map[string]interface{} {
return map[string]interface{}{
"goods_id": matching.GoodsID,
"goods_name": matching.GoodsName,
"brand_id": matching.BrandId,
"brand_name": matching.BrandName,
"goods_type": matching.GoodsType,
"supplier_id": matching.SupplierID,
"supplier_name": matching.SupplierName,
"delivery": matching.Delivery,
"price": matching.Price,
"stock": matching.Stock,
"moq": matching.Moq,
"mpq": matching.Mpq,
"pdf": matching.Pdf,
"encap": matching.Encap,
"status": matching.Status,
"update_time": time.Now().Unix(),
"ladder_price": matching.LadderPrice,
"delivery_type": matching.DeliveryType,
}
err = BatchSaveMatchings(bomId, bomMatchingList)
if err != nil {
return
}
return
}
......@@ -133,6 +133,7 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.BomItemMatching, err error) {
//组装需要去更新的商品信息
var delivery string
if goodsMap.DeliveryType == 1 {
delivery = goods.CnDeliveryTime
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment