package controllers import ( "ERP_storage/Nats/NatsServer" "ERP_storage/conf" "ERP_storage/logs" "ERP_storage/models/Account" "ERP_storage/models/Purchase" "fmt" "math" "net/url" "os" "time" "github.com/beego/beego/v2/adapter/orm" beego "github.com/beego/beego/v2/server/web" "github.com/xuri/excelize/v2" userlibs "gogs.baozhida.cn/zoie/ERP_libs/User" "gogs.baozhida.cn/zoie/ERP_libs/lib" ) type PurchaseController struct { beego.Controller User userlibs.User } func (c *PurchaseController) Prepare() { c.User = *Account.User_r } // 管理员 func (c *PurchaseController) Purchase_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } T_uuid := c.GetString("T_uuid") T_dept := c.GetString("T_dept") T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 T_state, _ := c.GetInt("T_state") userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) PurchaseDao := Purchase.NewPurchase(orm.NewOrm()) R_List, R_cnt := PurchaseDao.Read_Purchase_List(T_dept, T_uuid, "", T_state, true, T_start_date, T_end_date, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *PurchaseController) Purchase_Audit_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) PurchaseDao := Purchase.NewPurchase(orm.NewOrm()) R_List, R_cnt := PurchaseDao.Read_Purchase_List("", "", c.User.T_uuid, Purchase.WaitAudit, false, "", "", page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } // 用户采购列表 func (c *PurchaseController) Purchase_User_List() { // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 T_state, _ := c.GetInt("T_state") userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) PurchaseDao := Purchase.NewPurchase(orm.NewOrm()) R_List, R_cnt := PurchaseDao.Read_Purchase_List("", c.User.T_uuid, "", T_state, false, T_start_date, T_end_date, page, page_z) var r_jsons lib.R_JSONS r_jsons.Num = R_cnt r_jsons.Data = R_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return } func (c *PurchaseController) Purchase_Get() { // 查询 T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) purchase, err := PurchaseDao.Read_Purchase_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Purchase.PurchaseToPurchase_Detail(purchase)} c.ServeJSON() return } func (c *PurchaseController) Purchase_Add() { T_uuid := c.GetString("T_uuid") T_date := c.GetString("T_date") T_remark := c.GetString("T_remark") T_detail := c.GetString("T_detail") T_approver := c.GetString("T_approver") T_dept := c.GetString("T_dept") T_product_name := c.GetString("T_product_name") T_total_price, _ := c.GetFloat("T_total_price") T_product_quantity, _ := c.GetInt("T_product_quantity") var_ := Purchase.Purchase{ T_dept: T_dept, T_uuid: T_uuid, T_submit: c.User.T_uuid, T_date: T_date, T_remark: T_remark, T_detail: T_detail, T_approver: T_approver, T_State: Purchase.WaitAudit, T_product_name: T_product_name, T_total_price: float32(T_total_price), T_product_quantity: T_product_quantity, } o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) id, err := PurchaseDao.Add_Purchase(var_) if err != nil { //o.Rollback() c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddNews(T_approver, fmt.Sprintf("【采购申请】您有一条%s的采购申请待审批", c.User.T_name), conf.PurchaseAuditUrl) NatsServer.AddUserLogs(c.User.T_uuid, "采购", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id} c.ServeJSON() return } func (c *PurchaseController) Purchase_Approval() { T_id, _ := c.GetInt("T_id") T_State, _ := c.GetInt("T_State") o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) purchase, err := PurchaseDao.Read_Purchase_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } if purchase.T_State == T_State { c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } // 1 待采购 2 已采购 purchase.T_State = T_State _, err = PurchaseDao.Update_Purchase(purchase, "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } if T_State == Purchase.PurchaseCompleted { NatsServer.AddNews(purchase.T_uuid, "【采购审核】您提交的采购申请已采购", conf.MyPurchaseNewsUrl) } NatsServer.AddUserLogs(c.User.T_uuid, "采购申请", "采购", purchase) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PurchaseController) Purchase_Edit() { T_id, _ := c.GetInt("T_id") T_uuid := c.GetString("T_uuid") T_date := c.GetString("T_date") T_remark := c.GetString("T_remark") T_State, _ := c.GetInt("T_State") T_detail := c.GetString("T_detail") T_approver := c.GetString("T_approver") T_dept := c.GetString("T_dept") T_product_name := c.GetString("T_product_name") T_total_price, _ := c.GetFloat("T_total_price") T_product_quantity, _ := c.GetInt("T_product_quantity") o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) purchase, err := PurchaseDao.Read_Purchase_ById(T_id) if err != nil { //o.Rollback() c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } clos := []string{} if len(T_uuid) > 0 { purchase.T_uuid = T_uuid clos = append(clos, "T_uuid") } if len(T_date) > 0 { purchase.T_date = T_date clos = append(clos, "T_date") } if len(T_dept) > 0 { purchase.T_dept = T_dept clos = append(clos, "T_dept") } if len(T_remark) > 0 { purchase.T_remark = T_remark clos = append(clos, "T_remark") } if len(T_detail) > 0 { purchase.T_detail = T_detail clos = append(clos, "T_detail") } if len(T_approver) > 0 { purchase.T_approver = T_approver clos = append(clos, "T_approver") } if T_State > 0 { if T_State == Purchase.NotPass { T_State = Purchase.WaitAudit } purchase.T_State = T_State clos = append(clos, "T_State") } if len(T_product_name) > 0 { purchase.T_product_name = T_product_name clos = append(clos, "T_product_name") } if T_total_price > 0 { purchase.T_total_price = float32(T_total_price) clos = append(clos, "T_total_price") } if T_product_quantity > 0 { purchase.T_product_quantity = T_product_quantity clos = append(clos, "T_product_quantity") } _, err = PurchaseDao.Update_Purchase(purchase, clos...) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "采购", "修改", purchase) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: purchase.Id} c.ServeJSON() return } func (c *PurchaseController) Purchase_Del() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) purchase, err := PurchaseDao.Read_Purchase_ById(T_id) if err != nil { //o.Rollback() c.Data["json"] = lib.JSONS{Code: 202, Msg: "T_id Err!"} c.ServeJSON() return } if purchase.T_State == 2 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "已采购,禁止删除!"} c.ServeJSON() return } _, err = PurchaseDao.Delete_Purchase(purchase) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "采购", "删除", purchase.Id) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: purchase.Id} c.ServeJSON() return } // 下载采购申请 func (c *PurchaseController) Purchase_Excel() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PurchaseDao := Purchase.NewPurchase(o) purchase, err := PurchaseDao.Read_Purchase_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) detail := Purchase.PurchaseToPurchase_Detail(purchase) f := excelize.NewFile() //设置单元格值 // 这里设置表头ÒÒ Style1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 16, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) Style2, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 15, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "left", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) Style3, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 13, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) Style4, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 13, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) // 定义列配置(可随时增加、删除或调整字段位置) type ExcelColumn struct { Header string // 表头名称 Width float64 // 列宽 DataFunc func(detail Purchase.PurchaseDetail_R, index int) interface{} } columns := []ExcelColumn{ {"序号", 6, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return index + 1 }}, {"名称", 18, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_name }}, {"位号", 15, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_bit_number }}, {"封装", 15, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_packaging }}, {"型号", 15, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_model }}, {"规格", 20, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_spec }}, {"数量", 6, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_quantity }}, {"需求", 12, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_demand }}, {"采购单价", 10, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_unit_price }}, {"采购金额", 15, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return fmt.Sprintf("%.2f", detail.T_unit_price*float32(detail.T_quantity)) }}, {"参考网址", 30, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_reference_site }}, {"备注", 20, func(detail Purchase.PurchaseDetail_R, index int) interface{} { return detail.T_remark }}, } // 计算最后一列的列名 lastCol := string(rune('A' + len(columns) - 1)) // 计算中间列(用于分隔左右两部分信息) midCol := string(rune('A' + len(columns)/2)) // 设置头部信息 f.MergeCell("Sheet1", "A1", lastCol+"1") f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%d宝智达冷链采购申请", time.Now().Year())) f.SetCellStyle("Sheet1", "A1", lastCol+"1", Style1) f.MergeCell("Sheet1", "A2", midCol+"2") date, _ := lib.DateStrToTime(detail.T_date) f.SetCellValue("Sheet1", "A2", fmt.Sprintf("申请时间:%s", date.Format("2006年01月02日"))) f.MergeCell("Sheet1", string(rune('A'+len(columns)/2+1))+"2", lastCol+"2") f.SetCellValue("Sheet1", string(rune('A'+len(columns)/2+1))+"2", fmt.Sprintf("申请人:%-10s负责人审批:", detail.T_uuid_name)) f.MergeCell("Sheet1", "A3", midCol+"3") f.SetCellValue("Sheet1", "A3", "执行时间:") f.MergeCell("Sheet1", string(rune('A'+len(columns)/2+1))+"3", lastCol+"3") f.SetCellValue("Sheet1", string(rune('A'+len(columns)/2+1))+"3", fmt.Sprintf("执行部门:%-15s执行人:", "")) f.MergeCell("Sheet1", "A4", midCol+"4") f.SetCellValue("Sheet1", "A4", fmt.Sprintf("审批人:%s", detail.T_approver_name)) f.MergeCell("Sheet1", string(rune('A'+len(columns)/2+1))+"4", lastCol+"4") approver_date := "" if len(detail.T_approver_date) > 0 { date2, _ := lib.DateStrToTime(detail.T_approver_date) approver_date = date2.Format("2006年01月02日") } f.SetCellValue("Sheet1", string(rune('A'+len(columns)/2+1))+"4", fmt.Sprintf("审批时间:%s", approver_date)) f.SetCellStyle("Sheet1", "A2", lastCol+"4", Style2) f.SetRowHeight("Sheet1", 1, 40) height := 30.0 f.SetRowHeight("Sheet1", 2, height) f.SetRowHeight("Sheet1", 3, height) f.SetRowHeight("Sheet1", 4, height) f.SetRowHeight("Sheet1", 5, height) // 设置"申请采购明细"标题行 f.MergeCell("Sheet1", "A5", lastCol+"5") f.SetCellValue("Sheet1", "A5", "申请采购明细") f.SetCellStyle("Sheet1", "A5", lastCol+"5", Style1) // 设置表头样式 f.SetCellStyle("Sheet1", "A6", lastCol+"6", Style3) f.SetRowHeight("Sheet1", 2, 25) // 循环设置表头和列宽 for i, col := range columns { colName := string(rune('A' + i)) f.SetCellValue("Sheet1", colName+"6", col.Header) f.SetColWidth("Sheet1", colName, colName, col.Width) } // 填充数据 line := 6 // 用于记录需要设置超链接的单元格 type hyperlinkCell struct { cellRef string url string displayText string } var hyperlinkCells []hyperlinkCell for i, v := range detail.T_Detail { line++ // 循环填充每列数据 for j, col := range columns { colName := string(rune('A' + j)) cellRef := fmt.Sprintf("%s%d", colName, line) // 特殊处理"参考网址"列 if col.Header == "参考网址" { // 确定显示的文本 displayText := v.T_reference_site_title if len(displayText) == 0 { displayText = "参考网址" } // 设置单元格值 f.SetCellValue("Sheet1", cellRef, displayText) // 如果有网址,记录下来,稍后统一设置超链接 if len(v.T_reference_site) > 0 { hyperlinkCells = append(hyperlinkCells, hyperlinkCell{ cellRef: cellRef, url: v.T_reference_site, displayText: displayText, }) } } else { f.SetCellValue("Sheet1", cellRef, col.DataFunc(v, i)) } } } // 合计行 line++ // 合并"序号"到"备注"列(最后一列之前的所有列) f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("F%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计") // 在最后一列设置求和公式 f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", "J", line), fmt.Sprintf("SUM(%s7:%s%d)", "J", "J", line-1)) // 设置数据区域样式 f.SetCellStyle("Sheet1", "A6", fmt.Sprintf("%s%d", lastCol, line), Style4) // 在统一样式之后,设置超链接和超链接样式 linkStyle, _ := f.NewStyle(&excelize.Style{ Font: &excelize.Font{ Color: "0563C1", Underline: "single", Size: 13, Family: "宋体", }, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) for _, cell := range hyperlinkCells { f.SetCellHyperLink("Sheet1", cell.cellRef, cell.url, "External") f.SetCellStyle("Sheet1", cell.cellRef, cell.cellRef, linkStyle) } timeStr := time.Now().Format("20060102150405") fileName := fmt.Sprintf("%d宝智达冷链采购申请%v.xlsx", time.Now().Year(), timeStr) filePath := "ofile/" + fileName // 保存文件 if err = f.SaveAs(filePath); err != nil { logs.Error("保存文件失败:", err) } defer func() { os.Remove(filePath) }() c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8") c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName)) c.Ctx.Output.Header("Content-Transfer-Encoding", "binary") c.Ctx.Output.Download(filePath, fileName) } // 下载采购统计 func (c *PurchaseController) Purchase_Stat_Excel() { T_uuid := c.GetString("T_uuid") T_dept := c.GetString("T_dept") T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 T_state, _ := c.GetInt("T_state") userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) PurchaseDao := Purchase.NewPurchase(orm.NewOrm()) R_List, _ := PurchaseDao.Read_Purchase_Stat(T_dept, T_uuid, "", T_state, true, T_start_date, T_end_date, 0, 9999) f := excelize.NewFile() //设置单元格值 // 这里设置表头ÒÒ Style1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 20, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, }) Style2, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 15, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, Fill: excelize.Fill{Type: "pattern", Color: []string{"D9D9D9"}, Pattern: 1}, }) Style3, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 15, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true}, Border: []excelize.Border{ {Type: "left", Color: "000000", Style: 1}, {Type: "top", Color: "000000", Style: 1}, {Type: "bottom", Color: "000000", Style: 1}, {Type: "right", Color: "000000", Style: 1}, }, }) f.MergeCell("Sheet1", "A1", "M1") f.SetCellValue("Sheet1", "A1", "资金一览表") f.SetCellStyle("Sheet1", "A1", "M1", Style1) // 写入表头 headers := []string{"序号", "采购物品", "规格", "单价", "数量", "实际金额", "合计金额", "用途", "采购申请人", "采购申请时间", "是否已有发票", "报销上报时间", "备注"} for col, header := range headers { cell := fmt.Sprintf("%c%d", rune('A'+col), 2) f.SetCellValue("Sheet1", cell, header) } // 这里设置表头 f.SetCellStyle("Sheet1", "A2", "M2", Style2) f.SetRowHeight("Sheet1", 2, 25) colsWidth := []float64{6, 12, 10, 10, 6, 30, 12, 15, 15, 15, 15, 15, 15} for col, width := range colsWidth { cell := fmt.Sprintf("%c", rune('A'+col)) f.SetColWidth("Sheet1", cell, cell, width) } line := 2 for i, purchase := range R_List { // 写入数据 startRow := line + 1 for _, v := range purchase.T_Detail { line++ f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), v.T_name) f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_model) f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_unit_price) f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_quantity) f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_amount) if len(purchase.T_Detail) == 1 { f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_amount) f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), purchase.T_uuid_name) f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), purchase.T_date) f.SetCellValue("Sheet1", fmt.Sprintf("M%d", line), purchase.T_remark) } } if len(purchase.T_Detail) > 1 { f.MergeCell("Sheet1", fmt.Sprintf("G%d", startRow), fmt.Sprintf("G%d", line)) f.SetCellFormula("Sheet1", fmt.Sprintf("G%d", startRow), fmt.Sprintf("SUM(F%d:F%d)", startRow, line)) f.MergeCell("Sheet1", fmt.Sprintf("I%d", startRow), fmt.Sprintf("I%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("I%d", startRow), purchase.T_uuid_name) f.MergeCell("Sheet1", fmt.Sprintf("J%d", startRow), fmt.Sprintf("J%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("J%d", startRow), purchase.T_date) f.MergeCell("Sheet1", fmt.Sprintf("M%d", startRow), fmt.Sprintf("M%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("M%d", startRow), purchase.T_remark) } } f.SetCellStyle("Sheet1", "A3", fmt.Sprintf("M%d", line), Style3) timeStr := time.Now().Format("20060102150405") fileName := fmt.Sprintf("%d资金一览表%v.xlsx", time.Now().Year(), timeStr) filePath := "ofile/" + fileName // 保存文件 if err := f.SaveAs(filePath); err != nil { logs.Error("保存文件失败:", err) } defer func() { os.Remove(filePath) }() c.Ctx.Output.Header("Content-Type", "application/vnd.ms-excel;charset=utf8") c.Ctx.Output.Header("Content-Disposition", "attachment; filename="+url.PathEscape(fileName)) c.Ctx.Output.Header("Content-Transfer-Encoding", "binary") c.Ctx.Output.Download(filePath, fileName) } func (c *PurchaseController) User_List() { var r_jsons lib.R_JSONS // 分页参数 初始化 page, _ := c.GetInt("page") if page < 1 { page = 1 } page_z, _ := c.GetInt("page_z") if page_z < 1 { page_z = conf.Page_size } T_name := c.GetString("T_name") PurchaseDao := Purchase.NewPurchase(orm.NewOrm()) uuidList := PurchaseDao.Read_T_uuid_List() if len(uuidList) == 0 { c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"} c.ServeJSON() return } var U_List []userlibs.User for _, user := range R_List { U_List = append(U_List, user) } r_jsons.Num = R_cnt r_jsons.Data = U_List r_jsons.Page = page r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z))) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons} c.ServeJSON() return }