12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346 |
- 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")
- 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(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_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: Percentage.DeviceTypeMap[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
- }
|