1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363 |
- 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") // 结束时间
- var T_company_list []string
- if len(T_name) > 0 {
- T_company_list = Percentage.Read_VerifyCompany_T_uuid_ListByT_name(T_name)
- }
- 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(T_name, T_uuid, T_start_date, T_end_date,
- T_company_list, 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") // 结束时间
- var T_company_list []string
- if len(T_name) > 0 {
- T_company_list = Percentage.Read_VerifyCompany_T_uuid_ListByT_name(T_name)
- }
- userList, _ := NatsServer.Read_User_List_All()
- Account.Read_User_All_Map(userList)
- Contract.Read_VerifyContract_All_Map()
- PercentageDao := Percentage.NewPercentage(orm.NewOrm())
- R_List, R_cnt := PercentageDao.Read_Percentage_User_List(c.User.T_uuid, T_name, T_start_date, T_end_date, T_company_list, 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_For_Excel(T_name, T_uuid, T_start_date, T_end_date, []string{}, T_state, T_type)
- 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},
- },
- })
- f.MergeCell("Sheet1", "A1", "AC1")
- f.SetRowStyle("Sheet1", 1, 1, Style1)
- f.SetRowHeight("Sheet1", 1, 50)
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s提成统计表", dataInterval))
- //Style3, _ := 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},
- // },
- // })
- f.SetCellStyle("Sheet1", "A2", "G4", Style2)
- f.SetRowHeight("Sheet1", 2, 20)
- 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", "H2", "S2")
- f.SetCellValue("Sheet1", "H2", "验证实施")
- f.MergeCell("Sheet1", "T2", "AC2")
- f.SetCellValue("Sheet1", "T2", "报告编写")
- verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999)
- for _, item := range verifyItemList {
- f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price)
- }
- f.MergeCell("Sheet1", "S3", "S4")
- f.SetCellValue("Sheet1", "S3", "合计")
- f.MergeCell("Sheet1", "AC3", "AC4")
- f.SetCellValue("Sheet1", "AC3", "合计")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 5)
- f.SetColWidth("Sheet1", "B", "G", 16)
- f.SetColWidth("Sheet1", "E", "G", 10)
- f.SetColWidth("Sheet1", "H", "AC", 10)
- // 冻结1-3行
- f.SetPanes("Sheet1", &excelize.Panes{
- Freeze: true,
- Split: false,
- XSplit: 2,
- 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_device_type+percentage.T_verify_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_task_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_uuid_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), percentage.T_reporting_pass_time[:10])
- verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item)
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), verifyItem.T_price)
- var verifyType string
- if percentage.T_type == Percentage.SchemeType {
- verifyType = "验证实施"
- f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), verifyItem.T_price)
- } else if percentage.T_type == Percentage.ReportingType {
- verifyType = "报告编写"
- f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), verifyItem.T_price)
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType)
- line++
- }
- // 函数统计
- //f.SetCellFormula("Sheet1", fmt.Sprintf("S%d", line), fmt.Sprintf("SUM(S5:S%d)", line-1))
- //f.SetCellFormula("Sheet1", fmt.Sprintf("AC%d", line), fmt.Sprintf("SUM(AC5:AC%d)", 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("AC%d", line-1), Style4)
- f.SetCellStyle("Sheet1", "H2", "S4", StyleYellowFill)
- f.SetCellStyle("Sheet1", "S5", fmt.Sprintf("S%d", line-1), StyleYellowFill1)
- f.SetCellStyle("Sheet1", "T2", "AC4", StyleGreenFill)
- f.SetCellStyle("Sheet1", "AC5", fmt.Sprintf("AC%d", 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_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_For_Excel(T_name, c.User.T_uuid, T_start_date, T_end_date, []string{}, T_state, T_type)
- 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},
- },
- })
- f.MergeCell("Sheet1", "A1", "AC1")
- f.SetRowStyle("Sheet1", 1, 1, Style1)
- f.SetRowHeight("Sheet1", 1, 50)
- f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s提成统计表", dataInterval))
- //Style3, _ := 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},
- // },
- // })
- f.SetCellStyle("Sheet1", "A2", "G4", Style2)
- f.SetRowHeight("Sheet1", 2, 20)
- 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", "H2", "S2")
- f.SetCellValue("Sheet1", "H2", "验证实施")
- f.MergeCell("Sheet1", "T2", "AC2")
- f.SetCellValue("Sheet1", "T2", "报告编写")
- verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999)
- for _, item := range verifyItemList {
- f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price)
- }
- f.MergeCell("Sheet1", "S3", "S4")
- f.SetCellValue("Sheet1", "S3", "合计")
- f.MergeCell("Sheet1", "AC3", "AC4")
- f.SetCellValue("Sheet1", "AC3", "合计")
- // 设置列宽
- f.SetColWidth("Sheet1", "A", "A", 5)
- f.SetColWidth("Sheet1", "B", "G", 16)
- f.SetColWidth("Sheet1", "E", "G", 10)
- f.SetColWidth("Sheet1", "H", "AC", 10)
- // 冻结1-3行
- f.SetPanes("Sheet1", &excelize.Panes{
- Freeze: true,
- Split: false,
- XSplit: 2,
- 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_device_type+percentage.T_verify_type)
- f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_task_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_uuid_name)
- f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), percentage.T_reporting_pass_time[:10])
- verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item)
- f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), verifyItem.T_price)
- var verifyType string
- if percentage.T_type == Percentage.SchemeType {
- verifyType = "验证实施"
- f.SetCellValue("Sheet1", fmt.Sprintf("S%d", line), verifyItem.T_price)
- } else if percentage.T_type == Percentage.ReportingType {
- verifyType = "报告编写"
- f.SetCellValue("Sheet1", fmt.Sprintf("AC%d", line), verifyItem.T_price)
- }
- f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType)
- line++
- }
- // 函数统计
- //f.SetCellFormula("Sheet1", fmt.Sprintf("S%d", line), fmt.Sprintf("SUM(S5:S%d)", line-1))
- //f.SetCellFormula("Sheet1", fmt.Sprintf("AC%d", line), fmt.Sprintf("SUM(AC5:AC%d)", 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("AC%d", line-1), Style4)
- f.SetCellStyle("Sheet1", "H2", "S4", StyleYellowFill)
- f.SetCellStyle("Sheet1", "S5", fmt.Sprintf("S%d", line-1), StyleYellowFill1)
- f.SetCellStyle("Sheet1", "T2", "AC4", StyleGreenFill)
- f.SetCellStyle("Sheet1", "AC5", fmt.Sprintf("AC%d", 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_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-报告编写
- 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: verifyItemMap[T_device_type].T_price,
- 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_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
- }
- 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")
- //T_remit := c.GetString("T_remit")
- 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
- }
- // 1-待审核 2-审核通过 3-审核不通过 5-已打款 合同状态为未通过,修改之后将状态更改为待审核
- if percentage.T_State == 1 || percentage.T_State == 3 {
- c.Data["json"] = lib.JSONS{Code: 202, Msg: "当前状态不可提交打款!"}
- c.ServeJSON()
- return
- }
- //if len(T_remit) == 0 {
- // c.Data["json"] = lib.JSONS{Code: 202, Msg: "打款明细不能为空"}
- // c.ServeJSON()
- // return
- //}
- //if len(T_remit) > 0 {
- // percentage.T_remit = T_remit
- //}
- //_, money := Percentage.PercentageToPercentageRemit_R(T_remit)
- //// 部分打款
- //if percentage.T_approval_money > money && money > 0 {
- // percentage.T_State = 4
- //}
- //// 全部打款
- //if percentage.T_approval_money == money && money > 0 {
- // percentage.T_State = 5
- //}
- 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 == 4 {
- // NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已部分打款", percentage.T_task_id), conf.MyPercentageUrl)
- //}
- 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(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: task.T_device_type,
- T_verify_type: task.T_verify_type,
- 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,
- }
- _, 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() {
- verifyItem := GetPercentageMoney(task.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: task.T_device_type,
- T_verify_type: task.T_verify_type,
- T_company_uuid: task.T_uuid,
- T_task_name: task.T_name,
- T_uuid: coldVerifyUUIDMap[task.T_scheme],
- 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,
- }
- _, 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["位置"]
- }
- 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_State, _ := c.GetInt("T_State") // 总价
- var_ := Percentage.VerifyCompany{
- T_name: T_name,
- T_State: T_State,
- }
- 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") // 总价
- 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 !Percentage.Update_VerifyCompany(company, "T_State") {
- 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
- }
|