123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- package controllers
- import (
- "ERP_storage/Nats/NatsServer"
- "ERP_storage/conf"
- "ERP_storage/logs"
- "ERP_storage/models/Account"
- "ERP_storage/models/Purchase"
- "fmt"
- "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"
- "math"
- "net/url"
- "os"
- "time"
- )
- 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")
- 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,
- }
- 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")
- 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")
- }
- _, 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},
- },
- })
- f.MergeCell("Sheet1", "A1", "I1")
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%d宝智达冷链采购申请", time.Now().Year()))
- f.SetCellStyle("Sheet1", "A1", "I1", Style1)
- f.MergeCell("Sheet1", "A2", "E2")
- date, _ := lib.DateStrToTime(detail.T_date)
- f.SetCellValue("Sheet1", "A2", fmt.Sprintf("申请时间:%s", date.Format("2006年01月02日")))
- f.MergeCell("Sheet1", "F2", "I2")
- f.SetCellValue("Sheet1", "F2", fmt.Sprintf("申请人:%-10s负责人审批:", detail.T_uuid_name))
- f.MergeCell("Sheet1", "A3", "E3")
- f.SetCellValue("Sheet1", "A3", "执行时间:")
- f.MergeCell("Sheet1", "F3", "I3")
- f.SetCellValue("Sheet1", "F3", fmt.Sprintf("执行部门:%-15s执行人:", ""))
- f.MergeCell("Sheet1", "A4", "E4")
- f.SetCellValue("Sheet1", "A4", fmt.Sprintf("审批人:%s", detail.T_approver_name))
- f.MergeCell("Sheet1", "F4", "I4")
- 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", "F4", fmt.Sprintf("审批时间:%s", approver_date))
- f.SetCellStyle("Sheet1", "A2", "I4", 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", "I5")
- f.SetCellValue("Sheet1", "A5", "申请采购明细")
- f.SetCellStyle("Sheet1", "A5", "I5", Style1)
- f.SetCellValue("Sheet1", "A6", "序号")
- f.SetCellValue("Sheet1", "B6", "名称")
- f.SetCellValue("Sheet1", "C6", "型号")
- f.SetCellValue("Sheet1", "D6", "规格")
- f.SetCellValue("Sheet1", "E6", "数量")
- f.SetCellValue("Sheet1", "F6", "参考网址")
- f.SetCellValue("Sheet1", "G6", "需求")
- f.SetCellValue("Sheet1", "H6", "备注")
- f.SetCellValue("Sheet1", "I6", "采购金额")
- // 这里设置表头
- f.SetCellStyle("Sheet1", "A6", "H6", Style3)
- f.SetRowHeight("Sheet1", 2, 25)
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 6)
- f.SetColWidth("Sheet1", "B", "B", 12)
- f.SetColWidth("Sheet1", "C", "C", 10)
- f.SetColWidth("Sheet1", "D", "D", 10)
- f.SetColWidth("Sheet1", "E", "E", 6)
- f.SetColWidth("Sheet1", "F", "F", 30)
- f.SetColWidth("Sheet1", "G", "G", 12)
- f.SetColWidth("Sheet1", "H", "H", 15)
- f.SetColWidth("Sheet1", "I", "I", 15)
- line := 6
- for i, v := range detail.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_spec)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_quantity)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_reference_site)
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_demand)
- f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_remark)
- f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("%.2f", v.T_unit_price*float32(v.T_quantity)))
- }
- line++
- f.MergeCell("Sheet1", fmt.Sprintf("A%d", line), fmt.Sprintf("H%d", line))
- f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), "合计")
- f.SetCellFormula("Sheet1", fmt.Sprintf("I%d", line), fmt.Sprintf("SUM(I7:I%d)", line-1))
- f.SetCellStyle("Sheet1", "A6", fmt.Sprintf("I%d", line), Style4)
- 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
- }
|