From 2423b49e586da9380a0db539f9e19ab6bd5d391a Mon Sep 17 00:00:00 2001 From: chenlin Date: Thu, 21 Nov 2024 14:39:54 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BC=98=E5=8C=96=E9=9B=B6=E5=94=AE?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E5=AF=BC=E5=85=A5=E5=95=86=E5=93=81=EF=BC=8C?= =?UTF-8?q?=E5=85=A5=E5=8F=82=E5=A2=9E=E5=8A=A0=E9=97=A8=E5=BA=97id?= =?UTF-8?q?=EF=BC=9B=202=E3=80=81=E5=BA=93=E5=AD=98=E8=B0=83=E6=8B=A8?= =?UTF-8?q?=E6=98=8E=E7=BB=86=E5=87=BA=E5=8F=82=E5=A2=9E=E5=8A=A0=E6=80=BB?= =?UTF-8?q?=E8=B0=83=E6=8B=A8=E6=B1=87=E6=80=BB=E9=87=91=E9=A2=9D=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/apis/basic/category.go | 2 +- app/admin/apis/basic/commodity.go | 2 +- app/admin/apis/erpordermanage/erp_order.go | 17 +++++++-- app/admin/apis/inventorymanage/Inventory.go | 2 +- app/admin/models/erp_order.go | 4 +++ app/admin/models/file.go | 15 ++++++-- app/admin/models/inventory_report.go | 38 ++++++++++++++------- 7 files changed, 60 insertions(+), 20 deletions(-) diff --git a/app/admin/apis/basic/category.go b/app/admin/apis/basic/category.go index 53f703d..f8528e5 100644 --- a/app/admin/apis/basic/category.go +++ b/app/admin/apis/basic/category.go @@ -296,7 +296,7 @@ func CategoryImport(c *gin.Context) { } fmt.Println("header:", header.Filename) - _, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 1) + _, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 1, 0) if err != nil { //logger.Error("file excel reader err:", err) app.Error(c, http.StatusInternalServerError, err, err.Error()) diff --git a/app/admin/apis/basic/commodity.go b/app/admin/apis/basic/commodity.go index 1513546..82f6220 100644 --- a/app/admin/apis/basic/commodity.go +++ b/app/admin/apis/basic/commodity.go @@ -463,7 +463,7 @@ func CommodityImport(c *gin.Context) { } fmt.Println("header:", header.Filename) - _, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 2) + _, colsMap, err := models.FileExcelImport([]byte(readAll), nil, 2, 0) if err != nil { //logger.Error("file excel reader err:", err) app.Error(c, http.StatusInternalServerError, err, err.Error()) diff --git a/app/admin/apis/erpordermanage/erp_order.go b/app/admin/apis/erpordermanage/erp_order.go index 5f22cc1..6bbc8ad 100644 --- a/app/admin/apis/erpordermanage/erp_order.go +++ b/app/admin/apis/erpordermanage/erp_order.go @@ -664,10 +664,23 @@ func ErpOrderSaleDetail(c *gin.Context) { // @Tags 零售订单 // @Produce json // @Accept json -// @Param file body string true "上传excel文件" +// @Param file body string true "上传excel文件" models.ErpOrderBatchImportReq // @Success 200 {object} models.ErpOrderBatchImportResp // @Router /api/v1/erp_order/import [post] func ErpOrderBatchImport(c *gin.Context) { + jsonData := c.Request.FormValue("jsonData") // "jsonData" 是键名 + if jsonData == "" { + app.Error(c, http.StatusBadRequest, errors.New("参数错误,门店id为空"), "参数错误,门店id为空") + return + } + + var req = new(model.ErpOrderBatchImportReq) + err := json.Unmarshal([]byte(jsonData), &req) + if err != nil { + app.Error(c, http.StatusBadRequest, err, "参数错误:"+err.Error()) + return + } + file, header, err := c.Request.FormFile("file") if err != nil { logger.Error("form file err:", logger.Field("err", err)) @@ -683,7 +696,7 @@ func ErpOrderBatchImport(c *gin.Context) { } fmt.Println("header:", header.Filename) - _, colsMap, err := model.FileExcelImport(readAll, nil, 4) + _, colsMap, err := model.FileExcelImport(readAll, nil, 4, int(req.StoreId)) if err != nil { logger.Errorf("file excel reader err:", err) app.Error(c, http.StatusInternalServerError, err, err.Error()) diff --git a/app/admin/apis/inventorymanage/Inventory.go b/app/admin/apis/inventorymanage/Inventory.go index 2979d61..a537a9e 100644 --- a/app/admin/apis/inventorymanage/Inventory.go +++ b/app/admin/apis/inventorymanage/Inventory.go @@ -235,7 +235,7 @@ func BatchImport(c *gin.Context) { } fmt.Println("header:", header.Filename) - _, colsMap, err := models.FileExcelImport(readAll, nil, 3) + _, colsMap, err := models.FileExcelImport(readAll, nil, 3, 0) if err != nil { //logger.Error("file excel reader err:", err) app.Error(c, http.StatusInternalServerError, err, err.Error()) diff --git a/app/admin/models/erp_order.go b/app/admin/models/erp_order.go index ca51c02..1f20769 100644 --- a/app/admin/models/erp_order.go +++ b/app/admin/models/erp_order.go @@ -440,6 +440,10 @@ type TableData struct { IMEI string `json:"imei"` // 串码 } +type ErpOrderBatchImportReq struct { + StoreId uint32 `json:"store_id" binding:"required"` // 门店id +} + type ErpOrderBatchImportResp struct { Commodities []ErpOrderCommodity `json:"commodities"` // 零售订单商品信息 } diff --git a/app/admin/models/file.go b/app/admin/models/file.go index 0bfa512..751cf41 100644 --- a/app/admin/models/file.go +++ b/app/admin/models/file.go @@ -161,7 +161,7 @@ func FileExcelReader(d []byte, cols []string) ([]byte, []map[string]interface{}, } // FileExcelImport 导入excel数据(校验必填项) -func FileExcelImport(d []byte, cols []string, nType int) ([]byte, []map[string]interface{}, error) { +func FileExcelImport(d []byte, cols []string, nType, storeId int) ([]byte, []map[string]interface{}, error) { reader, err := excelize.OpenReader(bytes.NewReader(d)) if err != nil { return nil, nil, fmt.Errorf("open reader error: %v", err) @@ -224,7 +224,7 @@ func FileExcelImport(d []byte, cols []string, nType int) ([]byte, []map[string]i if sheetList[0] != "导零售" { return nil, nil, errors.New("格式错误,不是零售模版excel") } - if err := checkOrderExcel(sheetCols); err != nil { + if err := checkOrderExcel(sheetCols, storeId); err != nil { return nil, nil, err } cols = getJSONTagNames(OrderExcel{}) @@ -1533,7 +1533,7 @@ func IsExistingCommodity(commodityId uint32) bool { // return nil //} -func checkOrderExcel(sheetCols [][]string) error { +func checkOrderExcel(sheetCols [][]string, storeId int) error { // 校验列数是否正确 if len(sheetCols) != 8 { return errors.New("模版错误,请检查文件") @@ -1555,6 +1555,15 @@ func checkOrderExcel(sheetCols [][]string) error { return fmt.Errorf("门店名称不同,请检查:[%v]", duplicateName) } + orderStore, err := GetStore(uint32(storeId)) + if err != nil { + return err + } + + if sheetCols[4][1] != orderStore.Name { + return fmt.Errorf("导入数据门店[%s]与订单门店[%s]不同,请检查", sheetCols[4][1], orderStore.Name) + } + // 缓存商品编号、商品名称和门店查询结果 productCodeCache := make(map[string]bool) productNameCache := make(map[string]bool) diff --git a/app/admin/models/inventory_report.go b/app/admin/models/inventory_report.go index c927feb..94b0221 100644 --- a/app/admin/models/inventory_report.go +++ b/app/admin/models/inventory_report.go @@ -128,11 +128,12 @@ type InventoryReportAllotDetailReq struct { // InventoryReportAllotDetailResp 库存调拨明细出参 type InventoryReportAllotDetailResp struct { - Total int64 `json:"total"` // 总条数/记录数 - PageIndex int `json:"pageIndex"` // 页码 - PageSize int `json:"pageSize"` // 页面条数 - ExportUrl string `json:"export_url"` // 导出excel路径 - List []ReportAllotDetailData `json:"list"` // + Total int64 `json:"total"` // 总条数/记录数 + TotalAllotAmount float64 `json:"total_allot_amount"` // 调拨金额 + PageIndex int `json:"pageIndex"` // 页码 + PageSize int `json:"pageSize"` // 页面条数 + ExportUrl string `json:"export_url"` // 导出excel路径 + List []ReportAllotDetailData `json:"list"` // } // ReportAllotDetailData 库存调拨明细数据 @@ -1281,6 +1282,18 @@ func (m *InventoryReportAllotDetailReq) ReportAllotDetailList(c *gin.Context) (* return nil, err } + // Calculate the sum of allot_amount + var totalAllotAmount float64 + err = countQuery.Select("SUM(erp_inventory_allot_commodity.amount) as total_allot_amount"). + Pluck("total_allot_amount", &totalAllotAmount).Error + if err != nil { + logger.Error("Failed to calculate TotalAllotAmount", logger.Field("err", err)) + return nil, err + } + + // Add the calculated TotalAllotAmount to the response + resp.TotalAllotAmount = tools.RoundToTwoDecimalPlaces(totalAllotAmount) + var commodities []ReportAllotDetailData if m.IsExport == 1 { // 导出excel err = qs.Order("audit_time DESC").Find(&commodities).Error @@ -1334,7 +1347,7 @@ func reportAllotDetailExport(req *InventoryReportAllotDetailResp) (string, error fmt.Println("url fileName:", url+fileName) // 组合标题栏数据 - title := []interface{}{"单据编号", "调出门店", "调入门店", "订单审核时间", "调入时间", "调拨状态", "商品名称", + title := []interface{}{"单据编号", "调出门店", "调入门店", "调拨金额", "订单审核时间", "调入时间", "调拨状态", "商品名称", "商品分类", "是否串码", "串码"} for i, _ := range title { cell, _ := excelize.CoordinatesToCellName(1+i, 1) @@ -1375,6 +1388,7 @@ func reportAllotDetailExport(req *InventoryReportAllotDetailResp) (string, error reportData.SerialNumber, // 单据编号 reportData.DeliverStoreName, // 调出门店 reportData.ReceiveStoreName, // 调入门店 + reportData.AllotAmount, // 调拨金额 auditTime, // 订单审核时间 receiveTime, // 调入时间 allotState, // 调拨状态 @@ -1395,7 +1409,7 @@ func reportAllotDetailExport(req *InventoryReportAllotDetailResp) (string, error } totalData := "记录数:" + strconv.FormatInt(int64(req.Total), 10) - end := []interface{}{totalData, "", "", "", "", "", "", "", "", ""} + end := []interface{}{totalData, "", "", req.TotalAllotAmount, "", "", "", "", "", ""} for i, _ := range end { cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+2) err := file.SetCellValue(fSheet, cell, end[i]) @@ -1418,13 +1432,13 @@ func reportAllotDetailExport(req *InventoryReportAllotDetailResp) (string, error file.SetColWidth("Sheet1", "A", "A", 13) file.SetColWidth("Sheet1", "B", "B", 28) file.SetColWidth("Sheet1", "C", "C", 28) - file.SetColWidth("Sheet1", "D", "D", 18) file.SetColWidth("Sheet1", "E", "E", 18) - file.SetColWidth("Sheet1", "G", "G", 23) - file.SetColWidth("Sheet1", "H", "H", 15) - file.SetColWidth("Sheet1", "J", "J", 15) + file.SetColWidth("Sheet1", "F", "F", 18) + file.SetColWidth("Sheet1", "H", "H", 23) + file.SetColWidth("Sheet1", "I", "I", 15) + file.SetColWidth("Sheet1", "K", "K", 15) - endRow := fmt.Sprintf("J"+"%d", nExcelStartRow+2) + endRow := fmt.Sprintf("K"+"%d", nExcelStartRow+2) // 应用样式到整个表格 _ = file.SetCellStyle("Sheet1", "A1", endRow, style)