1.添加采购需求导出excel功能;
This commit is contained in:
parent
ed3d037a6e
commit
9bc9b6f129
|
@ -260,15 +260,45 @@ func ErpPurchaseAudit(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
err = orm.Eloquent.Table("erp_purchase_order").Where("id = ?", erpPurchaseOrder.ID).Updates(map[string]interface{}{
|
||||
begin := orm.Eloquent.Begin()
|
||||
err = begin.Table("erp_purchase_order").Where("id = ?", erpPurchaseOrder.ID).Updates(map[string]interface{}{
|
||||
"state": orderState,
|
||||
}).Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Error("update erp_purchase_order err:", logger.Field("err", err))
|
||||
app.Error(c, http.StatusInternalServerError, err, "审核失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// 同步更新指导零售价,商品资料表、库存表
|
||||
if orderState == model.ErpPurchaseOrderWaitInventory {
|
||||
var purchaseCommodities []model.ErpPurchaseCommodity
|
||||
err = orm.Eloquent.Table("erp_purchase_commodity").Where("erp_purchase_order_id=?", erpPurchaseOrder.ID).
|
||||
Find(&purchaseCommodities).Error
|
||||
if err != nil {
|
||||
logger.Error("purchase commodities err:", logger.Field("err", err))
|
||||
app.Error(c, http.StatusBadRequest, err, "审核失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
for _, v := range purchaseCommodities {
|
||||
err = model.UpdateRetailPrice(begin, v.ErpCommodityId, v.RetailPrice)
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
app.Error(c, http.StatusBadRequest, err, "审核失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = begin.Commit().Error
|
||||
if err != nil {
|
||||
begin.Rollback()
|
||||
logger.Errorf("commit err:", err)
|
||||
app.Error(c, http.StatusInternalServerError, err, "审核失败")
|
||||
return
|
||||
}
|
||||
|
||||
app.OK(c, nil, "操作成功")
|
||||
return
|
||||
}
|
||||
|
@ -426,7 +456,8 @@ func ErpPurchaseTerminate(c *gin.Context) {
|
|||
}
|
||||
|
||||
err = orm.Eloquent.Table("erp_purchase_order").Where("id = ?", erpPurchaseOrder.ID).Updates(map[string]interface{}{
|
||||
"state": orderState,
|
||||
"state": orderState,
|
||||
"remark": req.Remark,
|
||||
}).Error
|
||||
if err != nil {
|
||||
logger.Error("update erp_purchase_order err:", logger.Field("err", err))
|
||||
|
|
|
@ -3,10 +3,13 @@ package models
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
orm "go-admin/common/global"
|
||||
"go-admin/logger"
|
||||
"go-admin/tools/config"
|
||||
"gorm.io/gorm"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -52,6 +55,8 @@ type ErpPurchaseOrder struct {
|
|||
OpeningBank string `json:"opening_bank"` // 开户行
|
||||
BankAccount string `json:"bank_account"` // 银行卡号
|
||||
DeliveryTime string `json:"delivery_time"` // 交货日期,如:2024-02-23
|
||||
DeliveryAddress string `json:"delivery_address"` // 交货地址
|
||||
Remark string `json:"remark"` // 备注
|
||||
Commodities []ErpPurchaseCommodity `json:"commodities" gorm:"-"`
|
||||
}
|
||||
|
||||
|
@ -171,6 +176,7 @@ type ErpPurchaseAuditReq struct {
|
|||
// ErpPurchaseTerminateReq 终止采购入参
|
||||
type ErpPurchaseTerminateReq struct {
|
||||
SerialNumber string `json:"serial_number" binding:"required"` // 单据编号
|
||||
Remark string `json:"remark" binding:"required"` // 备注
|
||||
}
|
||||
|
||||
// ErpPurchaseExecuteResp 执行(入库/退货)出参
|
||||
|
@ -217,11 +223,13 @@ type ErpPurchaseDemandRecord struct {
|
|||
}
|
||||
|
||||
type GetErpPurchaseDemandReq struct {
|
||||
ErpCategoryId uint32 `json:"erp_category_id" binding:"required"` // 商品分类id
|
||||
HideFlag string `json:"hide_flag"` // 隐藏标记(默认关闭):ON-开启,隐藏无采购需求的商品,OFF-关闭,展示所有
|
||||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 每页展示数据条数
|
||||
IsExport uint32 `json:"is_export"` // 1-导出
|
||||
ErpCategoryId uint32 `json:"erp_category_id"` // 商品分类id
|
||||
ErpCommoditySerialNumber string `json:"erp_commodity_serial_number"` // 商品编号
|
||||
ErpCommodityName string `json:"erp_commodity_name"` // 商品名称
|
||||
HideFlag string `json:"hide_flag"` // 隐藏标记(默认关闭):ON-开启,隐藏无采购需求的商品,OFF-关闭,展示所有
|
||||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 每页展示数据条数
|
||||
IsExport uint32 `json:"is_export"` // 1-导出
|
||||
}
|
||||
|
||||
type DemandData struct {
|
||||
|
@ -234,6 +242,7 @@ type DemandData struct {
|
|||
LastWholesalePrice float64 `json:"last_wholesale_price"` // 最近采购价
|
||||
TotalCount uint32 `json:"total_count"` // 需采购总数量
|
||||
TotalAmount float64 `json:"total_amount"` // 需采购总金额
|
||||
Remark string `json:"remark"` // 备注
|
||||
StoreList []struct {
|
||||
StoreID uint32 `json:"store_id"` // 门店id
|
||||
StoreName string `json:"store_name"` // 门店名称
|
||||
|
@ -450,21 +459,23 @@ func CreateErpPurchaseOrder(req *ErpPurchaseCreateReq, sysUser *SysUser) (*ErpPu
|
|||
purchaseOrder := &ErpPurchaseOrder{}
|
||||
if req.PurchaseType == ErpProcureOrder { // 采购入库订单
|
||||
purchaseOrder = &ErpPurchaseOrder{
|
||||
SerialNumber: "cgr" + NewErpPurchaseSn(),
|
||||
PurchaseType: req.PurchaseType,
|
||||
StoreId: req.StoreId,
|
||||
ErpSupplierId: req.ErpSupplierId,
|
||||
MakerTime: nowTime,
|
||||
HandlerId: req.HandlerId,
|
||||
HandlerName: req.HandlerName,
|
||||
MakerId: uint32(sysUser.UserId),
|
||||
MakerName: sysUser.NickName,
|
||||
State: ErpPurchaseOrderUnAudit, // 1-待审核
|
||||
ErpCashierId: req.ErpCashierId,
|
||||
AccountHolder: req.AccountHolder,
|
||||
OpeningBank: req.OpeningBank,
|
||||
BankAccount: req.BankAccount,
|
||||
DeliveryTime: req.DeliveryTime,
|
||||
SerialNumber: "cgr" + NewErpPurchaseSn(),
|
||||
PurchaseType: req.PurchaseType,
|
||||
StoreId: req.StoreId,
|
||||
ErpSupplierId: req.ErpSupplierId,
|
||||
MakerTime: nowTime,
|
||||
HandlerId: req.HandlerId,
|
||||
HandlerName: req.HandlerName,
|
||||
MakerId: uint32(sysUser.UserId),
|
||||
MakerName: sysUser.NickName,
|
||||
State: ErpPurchaseOrderUnAudit, // 1-待审核
|
||||
ErpCashierId: req.ErpCashierId,
|
||||
AccountHolder: req.AccountHolder,
|
||||
OpeningBank: req.OpeningBank,
|
||||
BankAccount: req.BankAccount,
|
||||
DeliveryTime: req.DeliveryTime,
|
||||
DeliveryAddress: req.DeliveryAddress,
|
||||
Remark: req.Remark,
|
||||
}
|
||||
err = purchaseOrder.IdInit()
|
||||
} else if req.PurchaseType == ErpRejectOrder { // 采购退货订单
|
||||
|
@ -490,6 +501,7 @@ func CreateErpPurchaseOrder(req *ErpPurchaseCreateReq, sysUser *SysUser) (*ErpPu
|
|||
MakerName: sysUser.NickName,
|
||||
State: ErpPurchaseOrderUnAudit, // 1-待审核
|
||||
ErpCashierId: req.ErpCashierId,
|
||||
Remark: req.Remark,
|
||||
}
|
||||
err = purchaseOrder.IdInit()
|
||||
} else {
|
||||
|
@ -560,6 +572,8 @@ func EditErpPurchaseOrder(req *ErpPurchaseEditReq, sysUser *SysUser) (*ErpPurcha
|
|||
purchaseOrder.OpeningBank = req.OpeningBank
|
||||
purchaseOrder.BankAccount = req.BankAccount
|
||||
purchaseOrder.DeliveryTime = req.DeliveryTime
|
||||
purchaseOrder.DeliveryAddress = req.DeliveryAddress
|
||||
purchaseOrder.Remark = req.Remark
|
||||
err = purchaseOrder.IdInit()
|
||||
if err != nil {
|
||||
logger.Error("purchase IdInit err:", logger.Field("err", err))
|
||||
|
@ -1686,6 +1700,22 @@ func FinishErpPurchaseDemand(req *FinishErpPurchaseDemandReq, sysUser *SysUser)
|
|||
|
||||
// GetErpPurchaseDemand 获取采购需求
|
||||
func GetErpPurchaseDemand(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandResp, error) {
|
||||
var err error
|
||||
resp := new(GetErpPurchaseDemandResp)
|
||||
if req.HideFlag == "ON" { // 隐藏无采购需求的商品
|
||||
resp, err = getErpPurchaseDemandHide(req)
|
||||
} else { // 展示所有
|
||||
resp, err = getErpPurchaseDemandAll(req)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 展示所有采购需求
|
||||
func getErpPurchaseDemandAll(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandResp, error) {
|
||||
page := req.PageIndex - 1
|
||||
if page < 0 {
|
||||
page = 0
|
||||
|
@ -1703,6 +1733,12 @@ func GetErpPurchaseDemand(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandRe
|
|||
if req.ErpCategoryId != 0 {
|
||||
qs = qs.Where("erp_category_id=?", req.ErpCategoryId)
|
||||
}
|
||||
if req.ErpCommoditySerialNumber != "" {
|
||||
qs = qs.Where("serial_number=?", req.ErpCommoditySerialNumber)
|
||||
}
|
||||
if req.ErpCommodityName != "" {
|
||||
qs = qs.Where("name=?", req.ErpCommodityName)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := qs.Count(&count).Error; err != nil {
|
||||
|
@ -1711,9 +1747,16 @@ func GetErpPurchaseDemand(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandRe
|
|||
}
|
||||
|
||||
var commodities []ErpCommodity
|
||||
err := qs.Order("id DESC").Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
return resp, err
|
||||
if req.IsExport == 1 { // 导出excel
|
||||
err := qs.Order("id DESC").Find(&commodities).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
return resp, err
|
||||
}
|
||||
} else {
|
||||
err := qs.Order("id DESC").Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
// 批量查询门店信息
|
||||
|
@ -1741,8 +1784,138 @@ func GetErpPurchaseDemand(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandRe
|
|||
|
||||
wg.Wait()
|
||||
|
||||
resp.List = demandDataList
|
||||
resp.Total = count
|
||||
if req.IsExport == 1 { // 导出excel
|
||||
if len(demandDataList) == 0 {
|
||||
return nil, errors.New("未查询到数据")
|
||||
}
|
||||
resp.ExportUrl, err = demandDataExport(demandDataList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
resp.List = demandDataList
|
||||
resp.Total = count
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// 隐藏无采购需求的商品
|
||||
func getErpPurchaseDemandHide(req *GetErpPurchaseDemandReq) (*GetErpPurchaseDemandResp, error) {
|
||||
page := req.PageIndex - 1
|
||||
if page < 0 {
|
||||
page = 0
|
||||
}
|
||||
if req.PageSize == 0 {
|
||||
req.PageSize = 10
|
||||
}
|
||||
|
||||
resp := &GetErpPurchaseDemandResp{
|
||||
PageIndex: page + 1,
|
||||
PageSize: req.PageSize,
|
||||
}
|
||||
|
||||
// 查询采购需求单信息,筛选出有采购需求的商品id
|
||||
var demand []ErpPurchaseDemand
|
||||
err := orm.Eloquent.Table("erp_purchase_demand").
|
||||
Where("state = 1").Find(&demand).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 用 map 存储已经出现过的 ErpCommodityId
|
||||
commodityIds := make(map[uint32]bool)
|
||||
var uniqueCommodityIds []uint32
|
||||
|
||||
for _, d := range demand {
|
||||
if _, ok := commodityIds[d.ErpCommodityId]; !ok {
|
||||
commodityIds[d.ErpCommodityId] = true
|
||||
uniqueCommodityIds = append(uniqueCommodityIds, d.ErpCommodityId)
|
||||
}
|
||||
}
|
||||
|
||||
// 查询商品信息
|
||||
qs := orm.Eloquent.Debug().Table("erp_commodity")
|
||||
if req.ErpCategoryId != 0 {
|
||||
qs = qs.Where("erp_category_id=?", req.ErpCategoryId)
|
||||
}
|
||||
if req.ErpCommoditySerialNumber != "" {
|
||||
qs = qs.Where("serial_number=?", req.ErpCommoditySerialNumber)
|
||||
}
|
||||
if req.ErpCommodityName != "" {
|
||||
qs = qs.Where("name=?", req.ErpCommodityName)
|
||||
}
|
||||
|
||||
var count int64
|
||||
if err := qs.Count(&count).Error; err != nil {
|
||||
logger.Error("count err:", logger.Field("err", err))
|
||||
return resp, err
|
||||
}
|
||||
|
||||
var commodities []ErpCommodity
|
||||
if req.IsExport == 1 { // 导出excel
|
||||
err := qs.Order("id DESC").Find(&commodities).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
return resp, err
|
||||
}
|
||||
} else {
|
||||
err := qs.Order("id DESC").Offset(page * req.PageSize).Limit(req.PageSize).Find(&commodities).Error
|
||||
if err != nil && err != RecordNotFound {
|
||||
return resp, err
|
||||
}
|
||||
}
|
||||
|
||||
// 匹配商品id,有则继续查询返回数据,没有则不返回
|
||||
var matchedCommodities []ErpCommodity
|
||||
for _, c := range commodities {
|
||||
for _, uniqueID := range uniqueCommodityIds {
|
||||
if c.ID == uniqueID {
|
||||
matchedCommodities = append(matchedCommodities, c)
|
||||
break // 找到匹配的商品后跳出内层循环,继续下一个商品
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(matchedCommodities) == 0 {
|
||||
resp.List = nil
|
||||
} else {
|
||||
// 批量查询门店信息
|
||||
stores, err := GetOnlineStores()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 并行查询需求数据
|
||||
var wg sync.WaitGroup
|
||||
demandDataList := make([]DemandData, len(matchedCommodities))
|
||||
|
||||
for i, v := range matchedCommodities {
|
||||
wg.Add(1)
|
||||
go func(index int, commodity ErpCommodity) {
|
||||
defer wg.Done()
|
||||
demandData, err := convertToDemandData(commodity, stores)
|
||||
if err != nil {
|
||||
// Handle error
|
||||
return
|
||||
}
|
||||
demandDataList[index] = demandData
|
||||
}(i, v)
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
if req.IsExport == 1 { // 导出excel
|
||||
if len(demandDataList) == 0 {
|
||||
return nil, errors.New("未查询到数据")
|
||||
}
|
||||
resp.ExportUrl, err = demandDataExport(demandDataList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
resp.List = demandDataList
|
||||
resp.Total = int64(len(matchedCommodities))
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
@ -1764,6 +1937,9 @@ func convertToDemandData(commodity ErpCommodity, stores []Store) (DemandData, er
|
|||
// Handle error
|
||||
return DemandData{}, err
|
||||
}
|
||||
if len(demands) != 0 {
|
||||
demandData.Remark = demands[0].Remark
|
||||
}
|
||||
|
||||
// 使用 WaitGroup 进行并行查询
|
||||
var wg sync.WaitGroup
|
||||
|
@ -1995,3 +2171,205 @@ func GetTotalsAndAveragesByCommodityID(commodityID uint32) (Result, error) {
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// UpdateRetailPrice 更新指导零售价
|
||||
func UpdateRetailPrice(begin *gorm.DB, commodityId, retailPrice uint32) error {
|
||||
// 更新商品信息表
|
||||
err := begin.Table("erp_commodity").Where("id=?", commodityId).
|
||||
Updates(map[string]interface{}{
|
||||
"retail_price": retailPrice,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新库存表
|
||||
err = begin.Table("erp_stock").Where("erp_commodity_id=?", commodityId).
|
||||
Updates(map[string]interface{}{
|
||||
"retail_price": retailPrice,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新库存商品表
|
||||
err = begin.Table("erp_stock_commodity").Where("erp_commodity_id=? and state not in (2,5)", commodityId).
|
||||
Updates(map[string]interface{}{
|
||||
"retail_price": retailPrice,
|
||||
}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 导出采购需求excel
|
||||
func demandDataExport(list []DemandData) (string, error) {
|
||||
file := excelize.NewFile()
|
||||
fSheet := "Sheet1"
|
||||
|
||||
url := ExportUrl
|
||||
fileName := time.Now().Format(TimeFormat) + "采购需求" + ".xlsx"
|
||||
fmt.Println("url fileName:", url+fileName)
|
||||
|
||||
// 组合标题栏第一行数据
|
||||
title1 := []interface{}{"商品编号", "商品名称", "商品分类", "指导零售价", "最近采购价"}
|
||||
storeCount := len(list[0].StoreList)
|
||||
var mergeCells []string // 存储需要合并的单元格范围
|
||||
|
||||
for _, v := range list[0].StoreList {
|
||||
for i := 0; i < 3; i++ {
|
||||
title1 = append(title1, v.StoreName)
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < storeCount; i++ {
|
||||
// 计算每个商户名称的起始和结束单元格
|
||||
startCol, _ := excelize.ColumnNumberToName(6 + i*3) // 从第6列开始,每个商户占3列
|
||||
endCol, _ := excelize.ColumnNumberToName(8 + i*3)
|
||||
mergeCell := startCol + "1:" + endCol + "1"
|
||||
mergeCells = append(mergeCells, mergeCell)
|
||||
}
|
||||
|
||||
title1 = append(title1, "需采购总数量")
|
||||
title1 = append(title1, "需采购总金额")
|
||||
title1 = append(title1, "备注")
|
||||
|
||||
// 合并单元格
|
||||
for _, mergeCell := range mergeCells {
|
||||
startCell, endCell := splitMergeCellCoordinates(mergeCell)
|
||||
_ = file.MergeCell(fSheet, startCell, endCell)
|
||||
}
|
||||
|
||||
// 组合标题栏第二行数据
|
||||
title2 := []interface{}{"商品编号", "商品名称", "商品分类", "指导零售价", "最近采购价"}
|
||||
for _, _ = range list[0].StoreList {
|
||||
title2 = append(title2, "上月销售数")
|
||||
title2 = append(title2, "库存数量")
|
||||
title2 = append(title2, "需采购数")
|
||||
}
|
||||
title2 = append(title2, "需采购总数量")
|
||||
title2 = append(title2, "需采购总金额")
|
||||
title2 = append(title2, "备注")
|
||||
|
||||
for i, _ := range title1 {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, 1)
|
||||
err := file.SetCellValue(fSheet, cell, title1[i])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
for i, _ := range title2 {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, 2)
|
||||
err := file.SetCellValue(fSheet, cell, title2[i])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
var row []interface{}
|
||||
nExcelStartRow := 0
|
||||
for i := 0; i < len(list); i++ {
|
||||
row = []interface{}{
|
||||
list[i].ErpCommoditySerialNumber, // 商品编号
|
||||
list[i].ErpCommodityName, // 商品名称
|
||||
list[i].ErpCategoryName, // 商品分类名称
|
||||
list[i].RetailPrice, // 指导零售价
|
||||
list[i].LastWholesalePrice, // 最近采购价
|
||||
}
|
||||
|
||||
for _, v := range list[i].StoreList {
|
||||
row = append(row, v.LastMonthSales) // 上月销售数
|
||||
row = append(row, v.StockCount) // 库存数量
|
||||
row = append(row, v.NeedCount) // 需采购数
|
||||
}
|
||||
|
||||
row = append(row, list[i].TotalCount) // 需采购总数量
|
||||
row = append(row, list[i].TotalAmount) // 需采购总金额
|
||||
row = append(row, list[i].Remark) // 备注
|
||||
|
||||
for j, _ := range row {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+j, nExcelStartRow+3)
|
||||
err := file.SetCellValue(fSheet, cell, row[j])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
}
|
||||
}
|
||||
nExcelStartRow++
|
||||
}
|
||||
|
||||
// 合并 "需采购总数量","需采购总金额" 和 "备注" 列的单元格
|
||||
strTotalCountCol, strTotalAmountCol, strRemarkCol := computeExtraColumns("E", storeCount)
|
||||
_ = file.MergeCell(fSheet, strTotalCountCol+"1", strTotalCountCol+"2")
|
||||
_ = file.MergeCell(fSheet, strTotalAmountCol+"1", strTotalAmountCol+"2")
|
||||
_ = file.MergeCell(fSheet, strRemarkCol+"1", strRemarkCol+"2")
|
||||
|
||||
// 设置所有单元格的样式: 居中、加边框
|
||||
style, _ := file.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},
|
||||
"border":[{"type":"left","color":"000000","style":1},
|
||||
{"type":"top","color":"000000","style":1},
|
||||
{"type":"right","color":"000000","style":1},
|
||||
{"type":"bottom","color":"000000","style":1}]}`)
|
||||
|
||||
endRow := fmt.Sprintf(strRemarkCol+"%d", nExcelStartRow+2)
|
||||
// 应用样式到整个表格
|
||||
_ = file.SetCellStyle("Sheet1", "A1", endRow, style)
|
||||
|
||||
_ = file.MergeCell(fSheet, "A1", "A2")
|
||||
_ = file.MergeCell(fSheet, "B1", "B2")
|
||||
_ = file.MergeCell(fSheet, "C1", "C2")
|
||||
_ = file.MergeCell(fSheet, "D1", "D2")
|
||||
_ = file.MergeCell(fSheet, "E1", "E2")
|
||||
|
||||
fmt.Println("save fileName:", config.ExportConfig.Path+fileName)
|
||||
if err := file.SaveAs(config.ExportConfig.Path + fileName); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
return url + fileName, nil
|
||||
}
|
||||
|
||||
// 根据合并单元格的字符串获取左上角和右下角的坐标
|
||||
func splitMergeCellCoordinates(cell string) (string, string) {
|
||||
split := strings.Split(cell, ":")
|
||||
if len(split) != 2 {
|
||||
return "", ""
|
||||
}
|
||||
return split[0], split[1]
|
||||
}
|
||||
|
||||
// 计算 "需采购总数量","需采购总金额" 和 "备注" 列的坐标字符串
|
||||
func computeExtraColumns(startCol string, storeCount int) (string, string, string) {
|
||||
// "需采购总数量" 列在商户列表结束后的下一列
|
||||
totalCountCol := convertColumnToLetters(convertLettersToColumn(startCol) + storeCount*3 + 1)
|
||||
|
||||
// "需采购总金额" 列在 "需采购总数量" 列的下一列
|
||||
totalAmountCol := convertColumnToLetters(convertLettersToColumn(totalCountCol) + 1)
|
||||
|
||||
// "备注" 列在 "需采购总金额" 列的下一列
|
||||
remarkCol := convertColumnToLetters(convertLettersToColumn(totalAmountCol) + 1)
|
||||
|
||||
return totalCountCol, totalAmountCol, remarkCol
|
||||
}
|
||||
|
||||
// 将列号转换为字母
|
||||
func convertColumnToLetters(column int) string {
|
||||
var result string
|
||||
for column > 0 {
|
||||
column--
|
||||
result = string('A'+column%26) + result
|
||||
column /= 26
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 将字母转换为列号
|
||||
func convertLettersToColumn(letters string) int {
|
||||
result := 0
|
||||
for _, letter := range letters {
|
||||
result *= 26
|
||||
result += int(letter) - 'A' + 1
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
52
docs/docs.go
52
docs/docs.go
|
@ -6072,6 +6072,10 @@ const docTemplate = `{
|
|||
"description": "最近采购价",
|
||||
"type": "number"
|
||||
},
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"retail_price": {
|
||||
"description": "指导零售价",
|
||||
"type": "integer"
|
||||
|
@ -7484,7 +7488,7 @@ const docTemplate = `{
|
|||
},
|
||||
"rejected_count": {
|
||||
"description": "计划退货数量",
|
||||
"type": "number"
|
||||
"type": "integer"
|
||||
},
|
||||
"rejected_price": {
|
||||
"description": "计划退货单价",
|
||||
|
@ -7503,15 +7507,8 @@ const docTemplate = `{
|
|||
"models.ErpPurchaseCreateReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"bank_account",
|
||||
"delivery_address",
|
||||
"delivery_time",
|
||||
"erp_cashier_id",
|
||||
"erp_purchase_commodities",
|
||||
"erp_supplier_id",
|
||||
"opening_bank",
|
||||
"purchase_type",
|
||||
"store_id"
|
||||
"purchase_type"
|
||||
],
|
||||
"properties": {
|
||||
"account_holder": {
|
||||
|
@ -7716,6 +7713,10 @@ const docTemplate = `{
|
|||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_purchase_commodity_id": {
|
||||
"description": "采购订单商品表id",
|
||||
"type": "integer"
|
||||
},
|
||||
"erp_purchase_order_id": {
|
||||
"description": "商品采购订单id",
|
||||
"type": "integer"
|
||||
|
@ -7750,7 +7751,8 @@ const docTemplate = `{
|
|||
"type": "object",
|
||||
"required": [
|
||||
"erp_purchase_order_id",
|
||||
"inventories"
|
||||
"inventories",
|
||||
"purchase_type"
|
||||
],
|
||||
"properties": {
|
||||
"erp_purchase_order_id": {
|
||||
|
@ -7763,6 +7765,10 @@ const docTemplate = `{
|
|||
"items": {
|
||||
"$ref": "#/definitions/models.ErpPurchaseInventory"
|
||||
}
|
||||
},
|
||||
"purchase_type": {
|
||||
"description": "采购类型:procure-采购 reject-退货",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -7799,8 +7805,12 @@ const docTemplate = `{
|
|||
"description": "创建时间",
|
||||
"type": "string"
|
||||
},
|
||||
"delivery_address": {
|
||||
"description": "交货地址",
|
||||
"type": "string"
|
||||
},
|
||||
"delivery_time": {
|
||||
"description": "交货日期",
|
||||
"description": "交货日期,如:2024-02-23",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_cashier_id": {
|
||||
|
@ -7855,6 +7865,10 @@ const docTemplate = `{
|
|||
"description": "退货采购订单id",
|
||||
"type": "integer"
|
||||
},
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"serial_number": {
|
||||
"description": "单据编号",
|
||||
"type": "string"
|
||||
|
@ -7940,9 +7954,14 @@ const docTemplate = `{
|
|||
"models.ErpPurchaseTerminateReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"remark",
|
||||
"serial_number"
|
||||
],
|
||||
"properties": {
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"serial_number": {
|
||||
"description": "单据编号",
|
||||
"type": "string"
|
||||
|
@ -8467,14 +8486,19 @@ const docTemplate = `{
|
|||
},
|
||||
"models.GetErpPurchaseDemandReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"erp_category_id"
|
||||
],
|
||||
"properties": {
|
||||
"erp_category_id": {
|
||||
"description": "商品分类id",
|
||||
"type": "integer"
|
||||
},
|
||||
"erp_commodity_name": {
|
||||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_commodity_serial_number": {
|
||||
"description": "商品编号",
|
||||
"type": "string"
|
||||
},
|
||||
"hide_flag": {
|
||||
"description": "隐藏标记(默认关闭):ON-开启,隐藏无采购需求的商品,OFF-关闭,展示所有",
|
||||
"type": "string"
|
||||
|
|
|
@ -6061,6 +6061,10 @@
|
|||
"description": "最近采购价",
|
||||
"type": "number"
|
||||
},
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"retail_price": {
|
||||
"description": "指导零售价",
|
||||
"type": "integer"
|
||||
|
@ -7473,7 +7477,7 @@
|
|||
},
|
||||
"rejected_count": {
|
||||
"description": "计划退货数量",
|
||||
"type": "number"
|
||||
"type": "integer"
|
||||
},
|
||||
"rejected_price": {
|
||||
"description": "计划退货单价",
|
||||
|
@ -7492,15 +7496,8 @@
|
|||
"models.ErpPurchaseCreateReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"bank_account",
|
||||
"delivery_address",
|
||||
"delivery_time",
|
||||
"erp_cashier_id",
|
||||
"erp_purchase_commodities",
|
||||
"erp_supplier_id",
|
||||
"opening_bank",
|
||||
"purchase_type",
|
||||
"store_id"
|
||||
"purchase_type"
|
||||
],
|
||||
"properties": {
|
||||
"account_holder": {
|
||||
|
@ -7705,6 +7702,10 @@
|
|||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_purchase_commodity_id": {
|
||||
"description": "采购订单商品表id",
|
||||
"type": "integer"
|
||||
},
|
||||
"erp_purchase_order_id": {
|
||||
"description": "商品采购订单id",
|
||||
"type": "integer"
|
||||
|
@ -7739,7 +7740,8 @@
|
|||
"type": "object",
|
||||
"required": [
|
||||
"erp_purchase_order_id",
|
||||
"inventories"
|
||||
"inventories",
|
||||
"purchase_type"
|
||||
],
|
||||
"properties": {
|
||||
"erp_purchase_order_id": {
|
||||
|
@ -7752,6 +7754,10 @@
|
|||
"items": {
|
||||
"$ref": "#/definitions/models.ErpPurchaseInventory"
|
||||
}
|
||||
},
|
||||
"purchase_type": {
|
||||
"description": "采购类型:procure-采购 reject-退货",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -7788,8 +7794,12 @@
|
|||
"description": "创建时间",
|
||||
"type": "string"
|
||||
},
|
||||
"delivery_address": {
|
||||
"description": "交货地址",
|
||||
"type": "string"
|
||||
},
|
||||
"delivery_time": {
|
||||
"description": "交货日期",
|
||||
"description": "交货日期,如:2024-02-23",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_cashier_id": {
|
||||
|
@ -7844,6 +7854,10 @@
|
|||
"description": "退货采购订单id",
|
||||
"type": "integer"
|
||||
},
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"serial_number": {
|
||||
"description": "单据编号",
|
||||
"type": "string"
|
||||
|
@ -7929,9 +7943,14 @@
|
|||
"models.ErpPurchaseTerminateReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"remark",
|
||||
"serial_number"
|
||||
],
|
||||
"properties": {
|
||||
"remark": {
|
||||
"description": "备注",
|
||||
"type": "string"
|
||||
},
|
||||
"serial_number": {
|
||||
"description": "单据编号",
|
||||
"type": "string"
|
||||
|
@ -8456,14 +8475,19 @@
|
|||
},
|
||||
"models.GetErpPurchaseDemandReq": {
|
||||
"type": "object",
|
||||
"required": [
|
||||
"erp_category_id"
|
||||
],
|
||||
"properties": {
|
||||
"erp_category_id": {
|
||||
"description": "商品分类id",
|
||||
"type": "integer"
|
||||
},
|
||||
"erp_commodity_name": {
|
||||
"description": "商品名称",
|
||||
"type": "string"
|
||||
},
|
||||
"erp_commodity_serial_number": {
|
||||
"description": "商品编号",
|
||||
"type": "string"
|
||||
},
|
||||
"hide_flag": {
|
||||
"description": "隐藏标记(默认关闭):ON-开启,隐藏无采购需求的商品,OFF-关闭,展示所有",
|
||||
"type": "string"
|
||||
|
|
|
@ -948,6 +948,9 @@ definitions:
|
|||
last_wholesale_price:
|
||||
description: 最近采购价
|
||||
type: number
|
||||
remark:
|
||||
description: 备注
|
||||
type: string
|
||||
retail_price:
|
||||
description: 指导零售价
|
||||
type: integer
|
||||
|
@ -1974,7 +1977,7 @@ definitions:
|
|||
type: number
|
||||
rejected_count:
|
||||
description: 计划退货数量
|
||||
type: number
|
||||
type: integer
|
||||
rejected_price:
|
||||
description: 计划退货单价
|
||||
type: number
|
||||
|
@ -2032,15 +2035,8 @@ definitions:
|
|||
description: 门店id
|
||||
type: integer
|
||||
required:
|
||||
- bank_account
|
||||
- delivery_address
|
||||
- delivery_time
|
||||
- erp_cashier_id
|
||||
- erp_purchase_commodities
|
||||
- erp_supplier_id
|
||||
- opening_bank
|
||||
- purchase_type
|
||||
- store_id
|
||||
type: object
|
||||
models.ErpPurchaseDetailReq:
|
||||
properties:
|
||||
|
@ -2144,6 +2140,9 @@ definitions:
|
|||
erp_commodity_name:
|
||||
description: 商品名称
|
||||
type: string
|
||||
erp_purchase_commodity_id:
|
||||
description: 采购订单商品表id
|
||||
type: integer
|
||||
erp_purchase_order_id:
|
||||
description: 商品采购订单id
|
||||
type: integer
|
||||
|
@ -2178,9 +2177,13 @@ definitions:
|
|||
items:
|
||||
$ref: '#/definitions/models.ErpPurchaseInventory'
|
||||
type: array
|
||||
purchase_type:
|
||||
description: 采购类型:procure-采购 reject-退货
|
||||
type: string
|
||||
required:
|
||||
- erp_purchase_order_id
|
||||
- inventories
|
||||
- purchase_type
|
||||
type: object
|
||||
models.ErpPurchaseOrder:
|
||||
properties:
|
||||
|
@ -2206,8 +2209,11 @@ definitions:
|
|||
createdAt:
|
||||
description: 创建时间
|
||||
type: string
|
||||
delivery_address:
|
||||
description: 交货地址
|
||||
type: string
|
||||
delivery_time:
|
||||
description: 交货日期
|
||||
description: 交货日期,如:2024-02-23
|
||||
type: string
|
||||
erp_cashier_id:
|
||||
description: 付款方式/收款方式id
|
||||
|
@ -2248,6 +2254,9 @@ definitions:
|
|||
rejected_purchase_order_id:
|
||||
description: 退货采购订单id
|
||||
type: integer
|
||||
remark:
|
||||
description: 备注
|
||||
type: string
|
||||
serial_number:
|
||||
description: 单据编号
|
||||
type: string
|
||||
|
@ -2309,10 +2318,14 @@ definitions:
|
|||
type: object
|
||||
models.ErpPurchaseTerminateReq:
|
||||
properties:
|
||||
remark:
|
||||
description: 备注
|
||||
type: string
|
||||
serial_number:
|
||||
description: 单据编号
|
||||
type: string
|
||||
required:
|
||||
- remark
|
||||
- serial_number
|
||||
type: object
|
||||
models.ErpStock:
|
||||
|
@ -2698,6 +2711,12 @@ definitions:
|
|||
erp_category_id:
|
||||
description: 商品分类id
|
||||
type: integer
|
||||
erp_commodity_name:
|
||||
description: 商品名称
|
||||
type: string
|
||||
erp_commodity_serial_number:
|
||||
description: 商品编号
|
||||
type: string
|
||||
hide_flag:
|
||||
description: 隐藏标记(默认关闭):ON-开启,隐藏无采购需求的商品,OFF-关闭,展示所有
|
||||
type: string
|
||||
|
@ -2710,8 +2729,6 @@ definitions:
|
|||
pageSize:
|
||||
description: 每页展示数据条数
|
||||
type: integer
|
||||
required:
|
||||
- erp_category_id
|
||||
type: object
|
||||
models.GetErpPurchaseDemandResp:
|
||||
properties:
|
||||
|
|
Loading…
Reference in New Issue
Block a user