1.优化零售订单审核更新非串码商品库存逻辑,增加日志排查库存不符问题;
This commit is contained in:
parent
26bd09bf1d
commit
d5f4e618c4
|
@ -803,6 +803,7 @@ func stringToIntArray(str string) ([]uint32, error) {
|
|||
|
||||
// 更新零售订单商品表的库存商品表主键id字段
|
||||
func updateErpStockCommodityID(gdb *gorm.DB, id uint32, nIdList []uint32) error {
|
||||
fmt.Println("nIdList is:", nIdList)
|
||||
strId := intArrayToString(nIdList)
|
||||
|
||||
// 查找在库的非串码商品
|
||||
|
@ -829,8 +830,8 @@ func updateErpStockCommodityID(gdb *gorm.DB, id uint32, nIdList []uint32) error
|
|||
return nil
|
||||
}
|
||||
|
||||
// 找一个可用的库存商品表主键ID
|
||||
func findRightErpStockCommodityId(idList map[uint32][]uint32, commodityId uint32, stockCommodity []ErpStockCommodity) (uint32, error) {
|
||||
// FindRightErpStockCommodityId 找一个可用的库存商品表主键ID
|
||||
func FindRightErpStockCommodityId(idList map[uint32][]uint32, commodityId uint32, stockCommodity []ErpStockCommodity) (uint32, error) {
|
||||
// 获取给定商品ID对应的ID列表
|
||||
existingIds, ok := idList[commodityId]
|
||||
if !ok || len(existingIds) == 0 {
|
||||
|
@ -967,12 +968,18 @@ func UpdateStock(gdb *gorm.DB, erpOrder ErpOrder, state, auditState int) error {
|
|||
}
|
||||
|
||||
// 找一个可用的库存商品表主键ID,使用零售商品表的主键ID作为key
|
||||
rightId, err := findRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
rightId, err := FindRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
commodities[i].ErpCommodityId, stockCommodity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logger.Info("rightId is:", logger.Field("rightId", rightId))
|
||||
if rightId == 0 {
|
||||
logger.Error("rightId is 0")
|
||||
return errors.New("查询商品库存出错")
|
||||
}
|
||||
|
||||
// 优先出库库存时间最长的数据
|
||||
err = gdb.Table("erp_stock_commodity").Where("id = ?", rightId).
|
||||
Updates(map[string]interface{}{"state": state}).Error // 状态更新为销售锁定中;反审核则更新为在库
|
||||
|
@ -1057,7 +1064,7 @@ func UpdateStock(gdb *gorm.DB, erpOrder ErpOrder, state, auditState int) error {
|
|||
}
|
||||
|
||||
// 找一个可用的库存商品表主键ID
|
||||
rightId, err := findRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
rightId, err := FindRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
commodities[i].ErpCommodityId, stockCommodity)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -818,7 +818,7 @@ func handleInventoryReduce(gdb *gorm.DB, changeOrder ErpInventoryChangeOrder) er
|
|||
}
|
||||
|
||||
// 找一个可用的库存商品表主键ID
|
||||
rightId, err := findRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
rightId, err := FindRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
trimCommodities[i].CommodityId, stockCommodity)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -1008,7 +1008,7 @@ func handleCancelInventoryReduce(gdb *gorm.DB, changeOrder ErpInventoryChangeOrd
|
|||
}
|
||||
|
||||
// 找一个可用的库存商品表主键ID
|
||||
rightId, err := findRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
rightId, err := FindRightErpStockCommodityId(usedStockCommodityIdList,
|
||||
trimCommodities[i].CommodityId, stockCommodity)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -52,6 +52,24 @@ func TestStock(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestFindRightErpStockCommodityId(t *testing.T) {
|
||||
|
||||
usedStockCommodityIdList := make(map[uint32][]uint32)
|
||||
commodityId := 23
|
||||
var stockCommodity []models.ErpStockCommodity
|
||||
//stockCommodity1 := models.ErpStockCommodity{}
|
||||
//stockCommodity1.ID = 4350
|
||||
//
|
||||
//stockCommodity2 := models.ErpStockCommodity{}
|
||||
//stockCommodity2.ID = 4351
|
||||
//
|
||||
//stockCommodity = append(stockCommodity, stockCommodity1)
|
||||
//stockCommodity = append(stockCommodity, stockCommodity2)
|
||||
|
||||
rightId, _ := models.FindRightErpStockCommodityId(usedStockCommodityIdList, uint32(commodityId), stockCommodity)
|
||||
fmt.Println("rightId is:", rightId)
|
||||
}
|
||||
|
||||
func TestSetGameCardStock(t *testing.T) {
|
||||
SetGameCardStock()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user