package controllers import ( "ERP_storage/Nats" "ERP_storage/Nats/NatsServer" "ERP_storage/conf" "ERP_storage/logs" "ERP_storage/models/Account" "ERP_storage/models/Basic" "ERP_storage/models/Contract" "ERP_storage/models/Percentage" "encoding/json" "fmt" "github.com/beego/beego/v2/adapter/orm" beego "github.com/beego/beego/v2/server/web" "github.com/go-resty/resty/v2" "github.com/robfig/cron/v3" "github.com/xuri/excelize/v2" natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats" userlibs "gogs.baozhida.cn/zoie/ERP_libs/User" "gogs.baozhida.cn/zoie/ERP_libs/lib" "math" "os" "strings" "time" ) type PercentageController struct { beego.Controller User userlibs.User } func (c *PercentageController) Prepare() { if Account.User_r != nil { c.User = *Account.User_r } } // 财务管理列表 func (c *PercentageController) Percentage_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_name := c.GetString("T_name") T_uuid := c.GetString("T_uuid") T_state, _ := c.GetInt("T_state") T_type, _ := c.GetInt("T_type") T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Percentage.Read_VerifyCompany_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) R_List, R_cnt := PercentageDao.Read_Percentage_List_SQL(T_name, T_uuid, T_start_date, T_end_date, false, T_state, T_type, 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 *PercentageController) Percentage_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_name := c.GetString("T_name") T_state, _ := c.GetInt("T_state") T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Percentage.Read_VerifyCompany_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) R_List, R_cnt := PercentageDao.Read_Percentage_User_List_SQL(c.User.T_uuid, T_name, T_start_date, T_end_date, false, T_state, 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 *PercentageController) Percentage_Export() { // 查询 T_name := c.GetString("T_name") T_uuid := c.GetString("T_uuid") T_start_date := c.GetString("T_start_date") // 开始时间 T_end_date := c.GetString("T_end_date") // 结束时间 T_state, _ := c.GetInt("T_state") T_type, _ := c.GetInt("T_type") // 提成类型 userList, _ := NatsServer.Read_User_List_All() Account.Read_User_All_Map(userList) Percentage.Read_VerifyCompany_All_Map() Basic.Read_VerifyItem_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) percentageList, _ := PercentageDao.Read_Percentage_List_SQL(T_name, T_uuid, T_start_date, T_end_date, true, T_state, T_type, 0, 9999) dataInterval := fmt.Sprintf("%s - %s", T_start_date, T_end_date) if dataInterval == " - " { dataInterval = "" } f := excelize.NewFile() // 设置单元格的值 Style1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, }) Style2, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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}, }, }) var schemeStartCell = "H" var schemeEndCell = "U" var reportingStartCell = "V" var reportingEndCell = "AE" f.MergeCell("Sheet1", "A1", reportingEndCell+"1") f.SetRowStyle("Sheet1", 1, 1, Style1) f.SetRowHeight("Sheet1", 1, 50) f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s提成统计表", dataInterval)) f.SetCellStyle("Sheet1", "A2", "G4", Style2) f.SetRowHeight("Sheet1", 2, 30) f.SetRowHeight("Sheet1", 4, 20) // 这里设置表头 f.MergeCell("Sheet1", "A2", "A4") f.MergeCell("Sheet1", "B2", "B4") f.MergeCell("Sheet1", "C2", "C4") f.MergeCell("Sheet1", "D2", "D4") f.MergeCell("Sheet1", "E2", "E4") f.MergeCell("Sheet1", "F2", "F4") f.MergeCell("Sheet1", "G2", "G4") f.SetCellValue("Sheet1", "A2", "序号") f.SetCellValue("Sheet1", "B2", "公司名称") f.SetCellValue("Sheet1", "C2", "项目名称") f.SetCellValue("Sheet1", "D2", "项目负责人") f.SetCellValue("Sheet1", "E2", "统计日期") f.SetCellValue("Sheet1", "F2", "验证类型") f.SetCellValue("Sheet1", "G2", "提成类型") f.MergeCell("Sheet1", schemeStartCell+"2", schemeEndCell+"2") f.SetCellValue("Sheet1", schemeStartCell+"2", "验证实施") f.MergeCell("Sheet1", reportingStartCell+"2", reportingEndCell+"2") f.SetCellValue("Sheet1", reportingStartCell+"2", "报告编写") verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999) for _, item := range verifyItemList { f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name) if item.T_name != "其他" { f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price) } } f.MergeCell("Sheet1", schemeEndCell+"3", schemeEndCell+"4") f.SetCellValue("Sheet1", schemeEndCell+"3", "合计") f.MergeCell("Sheet1", reportingEndCell+"3", reportingEndCell+"4") f.SetCellValue("Sheet1", reportingEndCell+"3", "合计") // 设置列宽 f.SetColWidth("Sheet1", "A", "A", 5) f.SetColWidth("Sheet1", "B", "B", 25) f.SetColWidth("Sheet1", "C", "C", 16) f.SetColWidth("Sheet1", "D", "E", 10) f.SetColWidth("Sheet1", "F", "F", 16) f.SetColWidth("Sheet1", "G", "G", 10) f.SetColWidth("Sheet1", schemeStartCell, reportingEndCell, 10) // 冻结1-3行 f.SetPanes("Sheet1", &excelize.Panes{ Freeze: true, Split: false, XSplit: 4, // 列 YSplit: 4, // 行 TopLeftCell: "A1", ActivePane: "topRight", }) // 过滤器 f.AutoFilter("Sheet1", "A4:G4", nil) // 循环写入数据 line := 5 for i, percentage := range percentageList { f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), percentage.T_verifyCompany.T_name) f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), percentage.T_task_name) f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_uuid_name) if len(percentage.T_reporting_pass_time) > 0 { f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_reporting_pass_time[:10]) } deviceType := fmt.Sprintf("%s-%s", percentage.T_device_type, percentage.T_verify_type) if percentage.T_device_type == "位置" { deviceType = fmt.Sprintf("%s-%s(%d)", percentage.T_device_type, percentage.T_verify_type, percentage.T_device_quantity) } f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), deviceType) verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item) f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), percentage.T_money) var verifyType string if percentage.T_type == Percentage.SchemeType { verifyType = "验证实施" f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), percentage.T_money) } else if percentage.T_type == Percentage.ReportingType { verifyType = "报告编写" f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_money) } f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType) line++ } // ------------- 最后一行 合计 ------------------------ f.SetRowHeight("Sheet1", line, 22) f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("G%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计") f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", schemeEndCell, schemeEndCell, line-1)) f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", reportingEndCell, reportingEndCell, line-1)) Style4, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 11, 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}, }, }) // 黄色填充 StyleYellowFill, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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{"#FFFF00"}, Pattern: 1}, }) // 黄色填充 StyleYellowFill1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 10, 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{"#FFFF00"}, Pattern: 1}, }) // 绿色填充 StyleGreenFill, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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{"#92D050"}, Pattern: 1}, }) StyleGreenFill1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 10, 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{"#92D050"}, Pattern: 1}, }) f.SetCellStyle("Sheet1", "A5", fmt.Sprintf("%s%d", reportingEndCell, line), Style4) f.SetCellStyle("Sheet1", schemeStartCell+"2", schemeEndCell+"4", StyleYellowFill) f.SetCellStyle("Sheet1", schemeEndCell+"5", fmt.Sprintf("%s%d", schemeEndCell, line-1), StyleYellowFill1) f.SetCellStyle("Sheet1", reportingStartCell+"2", reportingEndCell+"4", StyleGreenFill) f.SetCellStyle("Sheet1", reportingEndCell+"5", fmt.Sprintf("%s%d", reportingEndCell, line-1), StyleGreenFill1) filename := fmt.Sprintf("%s提成统计表(%s)", dataInterval, lib.GetRandstring(6, "0123456789", 0)) // 保存文件 if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil { fmt.Println(err) } // 上传 OSS nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix) url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx") if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"} c.ServeJSON() return } //删除目录 err := os.Remove("ofile/" + filename + ".xlsx") if err != nil { logs.Error(lib.FuncName(), err) } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url} c.ServeJSON() return } func (c *PercentageController) Percentage_User_Export() { // 查询 T_name := c.GetString("T_name") // 关键字 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) Percentage.Read_VerifyCompany_All_Map() Basic.Read_VerifyItem_All_Map() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) percentageList, _ := PercentageDao.Read_Percentage_User_List_SQL(c.User.T_uuid, T_name, T_start_date, T_end_date, true, T_state, 0, 9999) dataInterval := fmt.Sprintf("%s - %s", T_start_date, T_end_date) if dataInterval == " - " { dataInterval = "" } f := excelize.NewFile() // 设置单元格的值 Style1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"}, Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"}, }) Style2, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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}, }, }) var schemeStartCell = "H" var schemeEndCell = "U" var reportingStartCell = "V" var reportingEndCell = "AE" f.MergeCell("Sheet1", "A1", reportingEndCell+"1") f.SetRowStyle("Sheet1", 1, 1, Style1) f.SetRowHeight("Sheet1", 1, 50) f.SetCellValue("Sheet1", "A1", fmt.Sprintf("^%s%s提成统计表", c.User.T_name, dataInterval)) f.SetCellStyle("Sheet1", "A2", "G4", Style2) f.SetRowHeight("Sheet1", 2, 30) f.SetRowHeight("Sheet1", 4, 20) // 这里设置表头 f.MergeCell("Sheet1", "A2", "A4") f.MergeCell("Sheet1", "B2", "B4") f.MergeCell("Sheet1", "C2", "C4") f.MergeCell("Sheet1", "D2", "D4") f.MergeCell("Sheet1", "E2", "E4") f.MergeCell("Sheet1", "F2", "F4") f.MergeCell("Sheet1", "G2", "G4") f.SetCellValue("Sheet1", "A2", "序号") f.SetCellValue("Sheet1", "B2", "公司名称") f.SetCellValue("Sheet1", "C2", "项目名称") f.SetCellValue("Sheet1", "D2", "项目负责人") f.SetCellValue("Sheet1", "E2", "统计日期") f.SetCellValue("Sheet1", "F2", "验证类型") f.SetCellValue("Sheet1", "G2", "提成类型") f.MergeCell("Sheet1", schemeStartCell+"2", schemeEndCell+"2") f.SetCellValue("Sheet1", schemeStartCell+"2", "验证实施") f.MergeCell("Sheet1", reportingStartCell+"2", reportingEndCell+"2") f.SetCellValue("Sheet1", reportingStartCell+"2", "报告编写") verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999) for _, item := range verifyItemList { f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name) if item.T_name != "其他" { f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price) } } f.MergeCell("Sheet1", schemeEndCell+"3", schemeEndCell+"4") f.SetCellValue("Sheet1", schemeEndCell+"3", "合计") f.MergeCell("Sheet1", reportingEndCell+"3", reportingEndCell+"4") f.SetCellValue("Sheet1", reportingEndCell+"3", "合计") // 设置列宽 f.SetColWidth("Sheet1", "A", "A", 5) f.SetColWidth("Sheet1", "B", "B", 25) f.SetColWidth("Sheet1", "C", "C", 16) f.SetColWidth("Sheet1", "D", "E", 10) f.SetColWidth("Sheet1", "F", "F", 16) f.SetColWidth("Sheet1", "G", "G", 10) f.SetColWidth("Sheet1", schemeStartCell, reportingEndCell, 10) // 冻结1-3行 f.SetPanes("Sheet1", &excelize.Panes{ Freeze: true, Split: false, XSplit: 4, // 列 YSplit: 4, // 行 TopLeftCell: "A1", ActivePane: "topRight", }) // 过滤器 f.AutoFilter("Sheet1", "A4:G4", nil) // 循环写入数据 line := 5 for i, percentage := range percentageList { f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), percentage.T_verifyCompany.T_name) f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), percentage.T_task_name) f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_uuid_name) if len(percentage.T_reporting_pass_time) > 0 { f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_reporting_pass_time[:10]) } deviceType := fmt.Sprintf("%s-%s", percentage.T_device_type, percentage.T_verify_type) if percentage.T_device_type == "位置" { deviceType = fmt.Sprintf("%s-%s(%d)", percentage.T_device_type, percentage.T_verify_type, percentage.T_device_quantity) } f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), deviceType) verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item) f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), percentage.T_money) var verifyType string if percentage.T_type == Percentage.SchemeType { verifyType = "验证实施" f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), verifyItem.T_price) } else if percentage.T_type == Percentage.ReportingType { verifyType = "报告编写" f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_money) } f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType) line++ } // ------------- 最后一行 合计 ------------------------ f.SetRowHeight("Sheet1", line, 22) f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("G%d", line)) f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计") f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", schemeEndCell, schemeEndCell, line-1)) f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", reportingEndCell, reportingEndCell, line-1)) Style4, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Size: 11, 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}, }, }) // 黄色填充 StyleYellowFill, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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{"#FFFF00"}, Pattern: 1}, }) // 黄色填充 StyleYellowFill1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 10, 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{"#FFFF00"}, Pattern: 1}, }) // 绿色填充 StyleGreenFill, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 12, 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{"#92D050"}, Pattern: 1}, }) StyleGreenFill1, _ := f.NewStyle( &excelize.Style{ Font: &excelize.Font{Bold: true, Size: 10, 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{"#92D050"}, Pattern: 1}, }) f.SetCellStyle("Sheet1", "A5", fmt.Sprintf("%s%d", reportingEndCell, line), Style4) f.SetCellStyle("Sheet1", schemeStartCell+"2", schemeEndCell+"4", StyleYellowFill) f.SetCellStyle("Sheet1", schemeEndCell+"5", fmt.Sprintf("%s%d", schemeEndCell, line-1), StyleYellowFill1) f.SetCellStyle("Sheet1", reportingStartCell+"2", reportingEndCell+"4", StyleGreenFill) f.SetCellStyle("Sheet1", reportingEndCell+"5", fmt.Sprintf("%s%d", reportingEndCell, line-1), StyleGreenFill1) filename := fmt.Sprintf("%s%s提成统计表(%s)", c.User.T_name, dataInterval, lib.GetRandstring(6, "0123456789", 0)) // 保存文件 if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil { fmt.Println(err) } // 上传 OSS nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix) url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx") if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"} c.ServeJSON() return } //删除目录 err := os.Remove("ofile/" + filename + ".xlsx") if err != nil { logs.Error(lib.FuncName(), err) } c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url} c.ServeJSON() return } func (c *PercentageController) Percentage_Get() { // 查询 T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } Percentage.Read_VerifyCompany_All_Map() c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Percentage.PercentageToPercentage_Detail(percentage)} c.ServeJSON() return } func (c *PercentageController) Percentage_Add() { T_device_type := c.GetString("T_device_type") // 提成类型 T_verify_type := c.GetString("T_verify_type") // 验证类型 T_company_uuid := c.GetString("T_company_uuid") // 公司id T_type, _ := c.GetInt("T_type") // 类型 1-验证实施 2-报告编写 T_money, _ := c.GetFloat("T_money") // 金额 company, is := Percentage.Read_VerifyCompany(T_company_uuid) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询公司信息失败!"} c.ServeJSON() return } var verifyItemMap map[string]Basic.VerifyItem verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap() if T_type == Percentage.SchemeType { verifyItemMap = verifyItemSchemeMap } if T_type == Percentage.ReportingType { verifyItemMap = verifyItemReportingMap } var_ := Percentage.Percentage{ T_Distributor_id: company.T_Distributor_id, T_device_type: T_device_type, T_verify_type: T_verify_type, T_uuid: c.User.T_uuid, T_company_uuid: T_company_uuid, T_money: float32(T_money), T_type: T_type, //类型 1-验证实施 2-报告编写 T_State: 6, // 6-未提交审核 T_verify_item: verifyItemMap[T_device_type].Id, } o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) id, err := PercentageDao.Add_Percentage(var_) if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id} c.ServeJSON() return } func (c *PercentageController) Percentage_Approval() { T_id, _ := c.GetInt("T_id") T_state, _ := c.GetInt("T_state") T_approval_money, _ := c.GetFloat("T_approval_money") T_approval_opinion := c.GetString("T_approval_opinion") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"} c.ServeJSON() return } // 未提交审核 不能修改 if percentage.T_State == Percentage.NotSubmit || percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } Basic.Read_VerifyItem_All_Map() if len(T_approval_opinion) > 0 { percentage.T_approval_opinion = T_approval_opinion } if T_approval_money > 0 { percentage.T_approval_money = float32(T_approval_money) } // 2-已通过 3-未通过 if T_state == 2 || T_state == 3 { percentage.T_State = T_state } err = PercentageDao.Update_Percentage(percentage, "T_State", "T_approval_opinion", "T_approval_money") if err != nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } if T_state == Percentage.AuditPass { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核已通过", percentage.T_task_id), conf.MyPercentageUrl) } if T_state == Percentage.AuditUnPass { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核未通过", percentage.T_task_id), conf.MyPercentageUrl) } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PercentageController) Percentage_Edit() { T_id, _ := c.GetInt("T_id") T_device_type := c.GetString("T_device_type") // 提成类型 T_verify_type := c.GetString("T_verify_type") // 验证类型 T_company_uuid := c.GetString("T_company_uuid") // 公司id T_money, _ := c.GetFloat("T_money") // 金额 T_type, _ := c.GetInt("T_type") // 类型 1-验证实施 2-报告编写 company, is := Percentage.Read_VerifyCompany(T_company_uuid) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询公司信息失败!"} c.ServeJSON() return } var verifyItemMap map[string]Basic.VerifyItem verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap() if T_type == Percentage.SchemeType { verifyItemMap = verifyItemSchemeMap } if T_type == Percentage.ReportingType { verifyItemMap = verifyItemReportingMap } o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-未提交审核 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } if len(T_company_uuid) > 0 { percentage.T_company_uuid = T_company_uuid percentage.T_Distributor_id = company.T_Distributor_id } if len(T_device_type) > 0 { percentage.T_device_type = T_device_type } if len(T_verify_type) > 0 { percentage.T_verify_type = T_verify_type } if T_type > 0 { percentage.T_type = T_type } if T_money > 0 { percentage.T_money = float32(T_money) } //percentage.T_money = verifyItemMap[percentage.T_device_type].T_price percentage.T_verify_item = verifyItemMap[percentage.T_device_type].Id err = PercentageDao.Update_Percentage(percentage, "T_company_uuid", "T_Distributor_id", "T_device_type", "T_verify_type", "T_type", "T_money", "T_verify_item") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "修改", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id} c.ServeJSON() return } func (c *PercentageController) Percentage_Del() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止删除!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } err = PercentageDao.Delete_Percentage(percentage) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PercentageController) Percentage_Admin_Del() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } err = PercentageDao.Delete_Percentage(percentage) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } // 打款 func (c *PercentageController) Percentage_Remit() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { o.Rollback() c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"} c.ServeJSON() return } if percentage.T_State == 5 { c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 5-已打款 合同状态为未通过,修改之后将状态更改为待审核 if percentage.T_State == 1 || percentage.T_State == 3 { c.Data["json"] = lib.JSONS{Code: 202, Msg: "当前状态不可提交打款!"} c.ServeJSON() return } percentage.T_State = 5 err = PercentageDao.Update_Percentage(percentage, "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } if percentage.T_State == 5 { NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已打款", percentage.T_task_id), conf.MyPercentageUrl) } NatsServer.AddUserLogs(c.User.T_uuid, "提成", "提交打款", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id} c.ServeJSON() return } func (c *PercentageController) 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") ReimburseDao := Percentage.NewPercentage(orm.NewOrm()) uuidList := ReimburseDao.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 } func (c *PercentageController) Contract_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_name := c.GetString("T_name") ContractDao := Contract.NewContract(orm.NewOrm()) R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 0, 0, 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 *PercentageController) Percentage_Submit_Audit() { T_id, _ := c.GetInt("T_id") o := orm.NewOrm() PercentageDao := Percentage.NewPercentage(o) percentage, err := PercentageDao.Read_Percentage_ById(T_id) if err != nil { c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交失败!"} c.ServeJSON() return } if percentage.T_State != 6 && percentage.T_State != 3 { c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))} c.ServeJSON() return } // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-待审核 审核状态 percentage.T_State = 1 err = PercentageDao.Update_Percentage(percentage, "T_State") if err != nil { c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"} c.ServeJSON() return } NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【提成申请】您有一条提成申请(%s)待审核", percentage.T_task_id), conf.PercentageApprovalUrl) NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id} c.ServeJSON() return } func (c *PercentageController) Percentage_SyncVerify() { SyncVerifyPercentage(false) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"} c.ServeJSON() return } func Cron_Percentage() { //创建一个定时任务对象 c := cron.New(cron.WithSeconds()) //给对象增加定时任务 //c.AddFunc("0 */1 * * * ?", Cron_SyncColdVerifyCompany) c.AddFunc("@daily", Cron_SyncColdVerifyCompany) //c.AddFunc("0 */1 * * * ?", Cron_SyncVerifyPercentage) c.AddFunc("@daily", Cron_SyncVerifyPercentage) //启动定时任务 c.Start() defer c.Stop() //查询语句,阻塞,让main函数不退出,保持程序运行 select {} } func Cron_SyncColdVerifyCompany() { url := "/openapi/company/list" signature, timestamp := lib.GenColdVerifySignature() client := resty.New() resp, err := client.R().SetFormData(map[string]string{ "CreateDate": "", "X-API-KEY": lib.ColdVerify_OpenApi_Key, "X-API-SIGNATURE": signature, "X-API-TIMESTAMP": timestamp, }).Post(conf.ColdVerify_OpenApi_Host + url) if err != nil { logs.Error("请求冷链验证公司列表接口失败!") return } type R_JSONS struct { //必须的大写开头 Data []Percentage.VerifyCompany Code int64 Msg string } var res R_JSONS if err = json.Unmarshal(resp.Body(), &res); err != nil { logs.Error("请求冷链验证公司列表接口失败!") return } for _, company := range res.Data { c, is := Percentage.Read_VerifyCompany(company.T_uuid) if is { if c.T_name != company.T_name || c.T_Distributor_name != company.T_Distributor_name { c.T_name = company.T_name c.T_Distributor_name = company.T_Distributor_name Percentage.Update_VerifyCompany(c, "T_name", "T_Distributor_name") } } else { Percentage.Add_VerifyCompany(company) } } } // 读取冷链验证任务,同步到提成 // 定时统计前一天审核通过的任务 func Cron_SyncVerifyPercentage() { SyncVerifyPercentage(true) } func SyncVerifyPercentage(isCron bool) { url := "/openapi/task/list" signature, timestamp := lib.GenColdVerifySignature() client := resty.New() var createDate string if isCron { createDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02") } client.SetTimeout(30 * time.Second) client.SetRetryCount(3).SetRetryWaitTime(1 * time.Second) resp, err := client.R().SetFormData(map[string]string{ "CreateDate": createDate, "X-API-KEY": lib.ColdVerify_OpenApi_Key, "X-API-SIGNATURE": signature, "X-API-TIMESTAMP": timestamp, }).Post(conf.ColdVerify_OpenApi_Host + url) if err != nil { logs.Error("请求冷链验证任务列表接口失败!") return } type R_JSONS struct { //必须的大写开头 Data []Percentage.VerifyTask Code int64 Msg string } var res R_JSONS if err = json.Unmarshal(resp.Body(), &res); err != nil { logs.Error("请求冷链验证任务列表接口失败!") return } verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap() coldVerifyUUIDMap := GetColdVerifyUUIDMap() PercentageDao := Percentage.NewPercentage(orm.NewOrm()) for _, task := range res.Data { // 自动同步报告提成 _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.ReportingType) if err != nil && err.Error() == orm.ErrNoRows.Error() { verifyItem := GetPercentageMoney(Percentage.DeviceTypeMap[task.T_device_type], task.T_verify_type, verifyItemReportingMap) // 添加报告提成 percentage := Percentage.Percentage{ T_Distributor_id: task.T_Distributor_id, T_task_id: task.T_task_id, T_task_int_id: task.Id, T_device_type: Percentage.DeviceTypeMap[task.T_device_type], T_verify_type: task.T_verify_type, T_device_quantity: task.T_device_quantity, T_company_uuid: task.T_uuid, T_task_name: task.T_name, T_uuid: coldVerifyUUIDMap[task.T_reporting], T_money: verifyItem.T_price, T_type: Percentage.ReportingType, T_State: 1, T_verify_item: verifyItem.Id, T_reporting_pass_time: task.T_reporting_pass_time, } if task.T_device_type == "WZ" { percentage.T_money = verifyItem.T_price * float32(task.T_device_quantity) } _, err = PercentageDao.Add_Percentage(percentage) } // 由经销商id的任务 只有报告,不需要同步实施提成 if len(task.T_Distributor_id) > 0 { continue } // 自动同步实施提成 _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.SchemeType) if err != nil && err.Error() == orm.ErrNoRows.Error() { T_device_type := Percentage.DeviceTypeMap[task.T_device_type] verifyItem := GetPercentageMoney(T_device_type, task.T_verify_type, verifyItemSchemeMap) // 添加报告提成 percentage := Percentage.Percentage{ T_Distributor_id: task.T_Distributor_id, T_task_id: task.T_task_id, T_task_int_id: task.Id, T_device_type: T_device_type, T_verify_type: task.T_verify_type, T_device_quantity: task.T_device_quantity, T_company_uuid: task.T_uuid, T_task_name: task.T_name, T_uuid: coldVerifyUUIDMap[task.T_delivery], T_money: verifyItem.T_price, T_type: Percentage.SchemeType, T_State: 1, T_verify_item: verifyItem.Id, T_reporting_pass_time: task.T_reporting_pass_time, } if task.T_device_type == "WZ" { percentage.T_money = verifyItem.T_price * float32(task.T_device_quantity) } _, err = PercentageDao.Add_Percentage(percentage) } } } func GetVerifyItemMap() (map[string]Basic.VerifyItem, map[string]Basic.VerifyItem) { verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 999) var verifyItemSchemeMap = make(map[string]Basic.VerifyItem) // 实施 var verifyItemReportingMap = make(map[string]Basic.VerifyItem) // 实施 for _, item := range verifyItemList { if item.T_type == Percentage.SchemeType { verifyItemSchemeMap[item.T_name] = item } if item.T_type == Percentage.ReportingType { verifyItemReportingMap[item.T_name] = item } } return verifyItemSchemeMap, verifyItemReportingMap } func GetColdVerifyUUIDMap() (uuidMap map[string]string) { uuidMap = make(map[string]string) userList, _ := NatsServer.Read_User_List_All() for _, user := range userList { uuidMap[user.T_verify_cold_uuid] = user.T_uuid } return uuidMap } // 获取实施提成金额 func GetPercentageMoney(T_device_type, T_verify_type string, verifyItemMap map[string]Basic.VerifyItem) (money Basic.VerifyItem) { if strings.Contains(T_device_type, "箱") { return verifyItemMap["箱"] } if strings.Contains(T_device_type, "车") { if strings.Contains(T_verify_type, "空载") { return verifyItemMap["车(空载)"] } else { return verifyItemMap["车(满载)"] } } if strings.Contains(T_device_type, "柜") { if strings.Contains(T_verify_type, "空载") { return verifyItemMap["库(空载)"] } else { return verifyItemMap["库(满载)"] } } if strings.Contains(T_device_type, "库") { if strings.Contains(T_verify_type, "空载") { return verifyItemMap["库(空载)"] } else { return verifyItemMap["库(满载)"] } } if strings.Contains(T_device_type, "系统") { return verifyItemMap["系统"] } if strings.Contains(T_device_type, "位置") { return verifyItemMap["位置"] } if strings.Contains(T_device_type, "巡检") { return verifyItemMap["巡检"] } if strings.Contains(T_device_type, "培训") { return verifyItemMap["培训"] } if strings.Contains(T_device_type, "其他") { return verifyItemMap["其他"] } return Basic.VerifyItem{} } func (c *PercentageController) VerifyCompany_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_name := c.GetString("T_name") T_state, _ := c.GetInt("T_state") R_List, R_cnt := Percentage.Read_VerifyCompany_List(T_name, T_state, 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 *PercentageController) VerifyCompany_Add() { T_name := c.GetString("T_name") T_recoveries_time := c.GetString("T_recoveries_time") // 回款时间 T_State, _ := c.GetInt("T_State") // 总价 var_ := Percentage.VerifyCompany{ T_name: T_name, T_State: T_State, T_recoveries_time: T_recoveries_time, } if _, is := Percentage.Read_VerifyCompanyByT_name(T_name); is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称重复!"} c.ServeJSON() return } Id, is := Percentage.Add_VerifyCompany(var_) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "添加", var_) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id} c.ServeJSON() return } func (c *PercentageController) VerifyCompany_Edit() { T_uuid := c.GetString("T_uuid") T_State, _ := c.GetInt("T_State") // 总价 T_recoveries_time := c.GetString("T_recoveries_time") // 回款时间 company, is := Percentage.Read_VerifyCompany(T_uuid) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"} c.ServeJSON() return } if T_State > 0 { company.T_State = T_State } if len(T_recoveries_time) > 0 { company.T_recoveries_time = T_recoveries_time } if !Percentage.Update_VerifyCompany(company, "T_State", "T_recoveries_time") { c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改验证公司失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "修改", company) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid} c.ServeJSON() return } func (c *PercentageController) VerifyCompany_Del() { T_uuid := c.GetString("T_uuid") company, is := Percentage.Read_VerifyCompany(T_uuid) if !is { c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"} c.ServeJSON() return } if !Percentage.Delete_VerifyCompany(company) { c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除验证公司失败"} c.ServeJSON() return } NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "删除", company.T_uuid) c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid} c.ServeJSON() return }