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