From 5d99ba9e6496958e524b97b57f66f10563f0a4ab Mon Sep 17 00:00:00 2001 From: chenlin Date: Mon, 2 Sep 2024 17:43:34 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E8=A7=A3=E5=86=B3=E9=87=87=E8=B4=AD?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E9=A1=B5=E9=9D=A2=E5=BA=93=E5=AD=98=E6=95=B0?= =?UTF-8?q?=E9=87=8F=E7=BB=9F=E8=AE=A1=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=EF=BC=8C=E5=88=9D=E5=A7=8B=E5=80=BC=E7=94=B1?= =?UTF-8?q?0=E6=94=B9=E6=88=901=EF=BC=9B=202=E3=80=81=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E8=AF=A6excel=E6=97=B6=E5=A2=9E=E5=8A=A0"?= =?UTF-8?q?=E5=BA=93=E5=AD=98=E6=95=B0=E9=87=8F"=E5=88=97=EF=BC=8C?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E9=BB=98=E8=AE=A4=E4=B8=BA1=EF=BC=8C?= =?UTF-8?q?=E6=96=B9=E4=BE=BF=E9=87=87=E8=B4=AD=E8=BF=9B=E8=A1=8Cexcel?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E9=80=8F=E8=A7=86=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/models/commodity.go | 5 +++-- app/admin/models/purchase.go | 31 ++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/app/admin/models/commodity.go b/app/admin/models/commodity.go index cce1082..1777534 100644 --- a/app/admin/models/commodity.go +++ b/app/admin/models/commodity.go @@ -1573,8 +1573,8 @@ func InventoryDetailListExport(list []ErpStockCommodity, c *gin.Context) (string logger.Info("exportStaffCostPrice is:", logger.Field("exportStaffCostPrice", exportStaffCostPrice)) // 设置标题行 - title := []interface{}{"商品编号", "商品名称", "商品分类", "是否串码", "商品串码", "所属门店", "供应商", "首次入库时间", "首次入库方式", - "首次入库订单编号", "最近入库时间"} + title := []interface{}{"商品编号", "商品名称", "商品分类", "是否串码", "商品串码", "所属门店", "供应商", "库存数量", + "首次入库时间", "首次入库方式", "首次入库订单编号", "最近入库时间"} if exportPurchasePrice { title = append(title, "入库采购价") @@ -1626,6 +1626,7 @@ func InventoryDetailListExport(list []ErpStockCommodity, c *gin.Context) (string list[rowId].IMEI, list[rowId].StoreName, list[rowId].ErpSupplierName, + 1, list[rowId].FirstStockTime, storageType, list[rowId].OriginalSn, diff --git a/app/admin/models/purchase.go b/app/admin/models/purchase.go index 73a32e9..ec966ac 100644 --- a/app/admin/models/purchase.go +++ b/app/admin/models/purchase.go @@ -1937,6 +1937,15 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get } } + commodityIDs := make([]uint32, len(commodities)) + for i, commodity := range commodities { + commodityIDs[i] = commodity.ID + } + + if len(commodityIDs) == 0 { + return resp, nil + } + // 批量查询商品上月销售数量 var soldOutCommodities []ErpStockCommodity firstDay, lastDay := GetLastMonthRange() // 获取上个月的时间范围 @@ -1947,12 +1956,12 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get } if len(storeIdList) > 1 { err = orm.Eloquent.Table("erp_stock_commodity"). - Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id in (?)", - SoldOut, firstDay, lastDay, storeIdList).Find(&soldOutCommodities).Error + Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id in (?) AND erp_commodity_id IN (?)", + SoldOut, firstDay, lastDay, storeIdList, commodityIDs).Find(&soldOutCommodities).Error } else { err = orm.Eloquent.Table("erp_stock_commodity"). - Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id = ?", - SoldOut, firstDay, lastDay, storeIdList[0]).Find(&soldOutCommodities).Error + Where("state = ? AND updated_at BETWEEN ? AND ? AND store_id = ? AND erp_commodity_id IN (?)", + SoldOut, firstDay, lastDay, storeIdList[0], commodityIDs).Find(&soldOutCommodities).Error } if err != nil { return nil, err @@ -1973,12 +1982,12 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get var stockCommodities []ErpStockCommodity if len(storeIdList) > 1 { err = orm.Eloquent.Table("erp_stock_commodity"). - Where("state = ? AND store_id in (?)", - InStock, storeIdList).Find(&stockCommodities).Error + Where("state = ? AND store_id in (?) AND erp_commodity_id IN (?)", + InStock, storeIdList, commodityIDs).Find(&stockCommodities).Error } else { err = orm.Eloquent.Table("erp_stock_commodity"). - Where("state = ? AND store_id = ?", - InStock, storeIdList[0]).Find(&stockCommodities).Error + Where("state = ? AND store_id = ? AND erp_commodity_id IN (?)", + InStock, storeIdList[0], commodityIDs).Find(&stockCommodities).Error } if err != nil { return nil, err @@ -1991,14 +2000,14 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get if exist { // 存在 inStockMap[key] += 1 } else { // 不存在 - inStockMap[key] = 0 + inStockMap[key] = 1 } } // 查询采购需求单信息 var demand []ErpPurchaseDemand demandQs := orm.Eloquent.Table("erp_purchase_demand"). - Where("state = 1").Where("count <> 0") + Where("state = 1").Where("count <> 0").Where("erp_commodity_id IN (?)", commodityIDs) if len(storeIdList) > 0 { if len(storeIdList) == 1 { demandQs = demandQs.Where("store_id = ?", storeIdList[0]) @@ -2016,7 +2025,7 @@ func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq, c *gin.Context) (*Get demandRemarkQs := orm.Eloquent.Table("erp_purchase_demand_remark"). Where("state = 1"). Where("remark IS NOT NULL"). - Where("remark <> ''") + Where("remark <> ''").Where("erp_commodity_id IN (?)", commodityIDs) err = demandRemarkQs.Find(&demandRemarkInfo).Error if err != nil { return nil, err