123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389 |
- 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") // 结束时间
- T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
- T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
- 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, T_reporting_start_time, T_reporting_end_time,
- 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") // 结束时间
- T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
- T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
- 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, T_reporting_start_time, T_reporting_end_time, 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") // 提成类型
- T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
- T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
- 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, T_reporting_start_time, T_reporting_end_time, 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_approval_money)
- var verifyType string
- if percentage.T_type == Percentage.SchemeType {
- verifyType = "验证实施"
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), percentage.T_approval_money)
- } else if percentage.T_type == Percentage.ReportingType {
- verifyType = "报告编写"
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_approval_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")
- T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
- T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
- 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, T_reporting_start_time, T_reporting_end_time, 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_approval_money)
- var verifyType string
- if percentage.T_type == Percentage.SchemeType {
- verifyType = "验证实施"
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), percentage.T_approval_money)
- } else if percentage.T_type == Percentage.ReportingType {
- verifyType = "报告编写"
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_approval_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
- }
|