Commit 9b37f144 by mushishixian

fix bug

parent 44b4402a
The file could not be displayed because it is too large.
...@@ -15,16 +15,16 @@ type RecvPro struct { ...@@ -15,16 +15,16 @@ type RecvPro struct {
} }
func init() { func init() {
queueExchange := rabbitmq.QueueExchange{ //queueExchange := rabbitmq.QueueExchange{
"bom_match", // "bom_match",
"bom_match", // "bom_match",
"bom", // "bom",
"direct", // "direct",
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/", // "amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
} //}
//
str := `{"bom_id":195,"delivery_type":1,"sort":1}` //str := `{"bom_id":48,"delivery_type":1,"sort":1}`
rabbitmq.Send(queueExchange, str) //rabbitmq.Send(queueExchange, str)
} }
func (t *RecvPro) Consumer(dataByte []byte) (err error) { func (t *RecvPro) Consumer(dataByte []byte) (err error) {
......
...@@ -26,7 +26,7 @@ func GetBomItem(bomId, bomItemId int) (bomItem model.BomItem) { ...@@ -26,7 +26,7 @@ func GetBomItem(bomId, bomItemId int) (bomItem model.BomItem) {
} }
//更新没有匹配的到bom详情 //更新没有匹配的到bom详情
func UpdateNoMatchBomItem(bomItems []model.BomItem,isCancelMatch bool) (err error) { func UpdateNoMatchBomItem(bomItems []model.BomItem, isCancelMatch bool) (err error) {
if len(bomItems) == 0 { if len(bomItems) == 0 {
return nil return nil
} }
...@@ -90,7 +90,7 @@ func UpdateBomItem(bomId, bomItemId int) (err error) { ...@@ -90,7 +90,7 @@ func UpdateBomItem(bomId, bomItemId int) (err error) {
return return
} }
if len(goodsMapList) == 0 { if len(goodsMapList) == 0 {
err = UpdateNoMatchBomItem(bomItems,true) err = UpdateNoMatchBomItem(bomItems, true)
if err != nil { if err != nil {
return return
} }
......
...@@ -33,10 +33,10 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -33,10 +33,10 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
tableEnd := string(bomIdStr[len(bomIdStr)-1]) tableEnd := string(bomIdStr[len(bomIdStr)-1])
tableName := "lie_bom_item_matching_" + tableEnd tableName := "lie_bom_item_matching_" + tableEnd
//批量更新每一条记录之前,要去批量更新item表的item_status //批量更新每一条记录之前,要去批量更新item表的item_status
for k, matching := range matchingList { for _, matching := range matchingList {
if k == 1 || k == 2 || k == 3 { //if k == 1 || k == 2 || k == 3 {
time.Sleep(2 * time.Second) // time.Sleep(2 * time.Second)
} //}
//先去数据库查询是否存在该记录,有的话修改,没有就新增 //先去数据库查询是否存在该记录,有的话修改,没有就新增
var match model.BomItemMatching var match model.BomItemMatching
model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match) model.Db.Table(tableName).Where("bom_item_id = ?", matching.BomItemID).First(&match)
...@@ -70,25 +70,13 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er ...@@ -70,25 +70,13 @@ func BatchSaveMatchings(bomId int, matchingList []model.BomItemMatching) (err er
return nil return nil
} }
func batchUpdateItemStatus(tableEnd string, matchingList []model.BomItemMatching) (err error) { func batchUpdateItemStatus(bomId int, bomItemIds []int) (err error) {
//先找出不同购买状态的bom_id列表,还要去修改bom_item表的item_status
var isBuyBomItemIdList, noBuyBomItemIdList []int
for _, matching := range matchingList {
if matching.IsBuy == 1 {
isBuyBomItemIdList = append(isBuyBomItemIdList, matching.BomItemID)
} else {
noBuyBomItemIdList = append(noBuyBomItemIdList, matching.BomItemID)
}
}
now := time.Now().Unix() now := time.Now().Unix()
bomIdStr := strconv.Itoa(bomId)
tableEnd := string(bomIdStr[len(bomIdStr)-1])
//分别去更新 //分别去更新
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", isBuyBomItemIdList). err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", bomItemIds).
Updates(map[string]interface{}{"item_status": 2, "update_time": now}).Error Updates(map[string]interface{}{"item_status": 4, "update_time": now}).Error
if err != nil {
return
}
err = model.Db.Table("lie_bom_item_"+tableEnd).Where("bom_item_id IN (?)", noBuyBomItemIdList).
Updates(map[string]interface{}{"item_status": 3, "update_time": now}).Error
if err != nil { if err != nil {
return return
} }
......
...@@ -29,14 +29,18 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -29,14 +29,18 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
goodsIds = append(goodsIds, goodsMap.GoodsId) goodsIds = append(goodsIds, goodsMap.GoodsId)
} }
goodsIdsStr := strings.Join(goodsIds, ",") goodsIdsStr := strings.Join(goodsIds, ",")
goodList, err := GetGoodsInfo(goodsIdsStr) goodsList, err := GetGoodsInfo(goodsIdsStr)
if err != nil { if err != nil {
return return
} }
//这是匹配到的数据 //这是匹配到的数据
var bomMatchingList []model.BomItemMatching var bomMatchingList []model.BomItemMatching
var noGoodsInfoItemIdList []int
for _, goodsMap := range goodsMapList { for _, goodsMap := range goodsMapList {
for _, goods := range goodList { if !CheckInGoodsList(goodsMap, goodsList) {
noGoodsInfoItemIdList = append(noGoodsInfoItemIdList, goodsMap.BomItemId)
}
for _, goods := range goodsList {
if goodsMap.GoodsId == goods.GoodsID { if goodsMap.GoodsId == goods.GoodsID {
bomId = goodsMap.BomId bomId = goodsMap.BomId
//组装需要去更新的商品信息 //组装需要去更新的商品信息
...@@ -52,9 +56,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) { ...@@ -52,9 +56,23 @@ func UpdateGoodsData(goodsMapList []GoodsMap) (err error) {
if err != nil { if err != nil {
return return
} }
//还要找出没有匹配到商品的进行批量修改状态
err = batchUpdateItemStatus(bomId, noGoodsInfoItemIdList)
if err != nil {
return
}
return return
} }
func CheckInGoodsList(goodsMap GoodsMap, goodsList []model.ApiGoods) bool {
for _, goods := range goodsList {
if goods.GoodsID == goodsMap.GoodsId {
return true
}
}
return false
}
func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
goodsServerUrl := configs.ApiSetting.Goods goodsServerUrl := configs.ApiSetting.Goods
params := req.Param{ params := req.Param{
...@@ -82,10 +100,12 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) { ...@@ -82,10 +100,12 @@ func GetGoodsInfo(goodsIdsStr string) (goodsList []model.ApiGoods, err error) {
goods.HkDeliveryTime = data.Get("hk_delivery_time").String() goods.HkDeliveryTime = data.Get("hk_delivery_time").String()
goods.CnDeliveryTime = data.Get("cn_delivery_time").String() goods.CnDeliveryTime = data.Get("cn_delivery_time").String()
goods.IsBuy = int(data.Get("is_buy").Int()) goods.IsBuy = int(data.Get("is_buy").Int())
goods.Mpl = int(data.Get("mpl").Int())
goods.Encap = data.Get("encap").String() goods.Encap = data.Get("encap").String()
goods.SupplierID = int(data.Get("supplier_id").Int()) goods.SupplierID = int(data.Get("supplier_id").Int())
goods.Status = int(data.Get("status").Int()) goods.Status = int(data.Get("status").Int())
goods.GoodsType = int(data.Get("goods_type").Int()) goods.GoodsType = int(data.Get("goods_type").Int())
goods.AcType = int(data.Get("ac_type").Int())
var ladderPrice []model.LadderPrice var ladderPrice []model.LadderPrice
for _, price := range data.Get("ladder_price").Array() { for _, price := range data.Get("ladder_price").Array() {
var ladder model.LadderPrice var ladder model.LadderPrice
...@@ -161,6 +181,7 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model. ...@@ -161,6 +181,7 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
Stock: goods.Stock, Stock: goods.Stock,
IsBuy: goods.IsBuy, IsBuy: goods.IsBuy,
Moq: goods.Moq, Moq: goods.Moq,
Mpl: goods.Mpl,
Mpq: goods.Mpq, Mpq: goods.Mpq,
Encap: goods.Encap, Encap: goods.Encap,
Status: goods.Status, Status: goods.Status,
...@@ -174,11 +195,19 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model. ...@@ -174,11 +195,19 @@ func MatchGoodsInfo(goods model.ApiGoods, goodsMap GoodsMap) (bomMatching model.
if goodsMap.Number < goods.Moq { if goodsMap.Number < goods.Moq {
bomMatching.Number = goods.Moq bomMatching.Number = goods.Moq
} else { } else {
if goods.Mpl != 0 {
//不满足倍数规则,则要去帮它按倍数取 //不满足倍数规则,则要去帮它按倍数取
if (goodsMap.Number % goods.Mpq) != 0 { if (goodsMap.Number % goods.Mpl) != 0 {
bomMatching.Number = ((goodsMap.Number / goods.Mpq) + 1) * goods.Mpq bomMatching.Number = ((goodsMap.Number / goods.Mpl) + 1) * goods.Mpl
}
} }
if goods.GoodsType != 0 || goods.AcType == 6 {
if bomMatching.Number > goods.Stock {
bomMatching.Number = goods.Stock
} }
}
}
//阶梯价处理 //阶梯价处理
if len(goods.LadderPrice) > 0 { if len(goods.LadderPrice) > 0 {
ladderPriceStr, err := json.Marshal(goods.LadderPrice) ladderPriceStr, err := json.Marshal(goods.LadderPrice)
......
...@@ -30,6 +30,7 @@ type BomItemMatching struct { ...@@ -30,6 +30,7 @@ type BomItemMatching struct {
Moq int `json:"moq"` Moq int `json:"moq"`
// Mpq 包装量 // Mpq 包装量
Mpq int `json:"mpq"` Mpq int `json:"mpq"`
Mpl int `json:"mpl" gorm:"-"`
// Encap 封装 // Encap 封装
Encap string `json:"encap"` Encap string `json:"encap"`
// Status 1:正常 2:取消匹配(被替换) // Status 1:正常 2:取消匹配(被替换)
......
...@@ -59,9 +59,11 @@ type ApiGoods struct { ...@@ -59,9 +59,11 @@ type ApiGoods struct {
SupplierName string `json:"supplier_name"` SupplierName string `json:"supplier_name"`
BrandID int `json:"brand_id"` BrandID int `json:"brand_id"`
IsBuy int `json:"is_buy"` IsBuy int `json:"is_buy"`
Mpl int `json:"mpl"`
Status int `json:"status"` Status int `json:"status"`
Pdf string `json:"pdf"` Pdf string `json:"pdf"`
Encap string `json:"encap"` Encap string `json:"encap"`
AcType int `json:"ac_type"`
//ErpTax bool `json:"erp_tax"` //ErpTax bool `json:"erp_tax"`
} }
......
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