1、优化零售批量导入商品,入参增加门店id;
2、库存调拨明细出参增加总调拨汇总金额字段;
This commit is contained in:
parent
429c5a203a
commit
2423b49e58
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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"` // 零售订单商品信息
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -129,6 +129,7 @@ type InventoryReportAllotDetailReq struct {
|
|||
// InventoryReportAllotDetailResp 库存调拨明细出参
|
||||
type InventoryReportAllotDetailResp struct {
|
||||
Total int64 `json:"total"` // 总条数/记录数
|
||||
TotalAllotAmount float64 `json:"total_allot_amount"` // 调拨金额
|
||||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 页面条数
|
||||
ExportUrl string `json:"export_url"` // 导出excel路径
|
||||
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user