Percentage.go 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393
  1. package controllers
  2. import (
  3. "ERP_storage/Nats"
  4. "ERP_storage/Nats/NatsServer"
  5. "ERP_storage/conf"
  6. "ERP_storage/logs"
  7. "ERP_storage/models/Account"
  8. "ERP_storage/models/Basic"
  9. "ERP_storage/models/Contract"
  10. "ERP_storage/models/Percentage"
  11. "encoding/json"
  12. "fmt"
  13. "github.com/beego/beego/v2/adapter/orm"
  14. beego "github.com/beego/beego/v2/server/web"
  15. "github.com/go-resty/resty/v2"
  16. "github.com/robfig/cron/v3"
  17. "github.com/xuri/excelize/v2"
  18. natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
  19. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  20. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  21. "math"
  22. "os"
  23. "strings"
  24. "time"
  25. )
  26. type PercentageController struct {
  27. beego.Controller
  28. User userlibs.User
  29. }
  30. func (c *PercentageController) Prepare() {
  31. if Account.User_r != nil {
  32. c.User = *Account.User_r
  33. }
  34. }
  35. // 财务管理列表
  36. func (c *PercentageController) Percentage_List() {
  37. // 分页参数 初始化
  38. page, _ := c.GetInt("page")
  39. if page < 1 {
  40. page = 1
  41. }
  42. page_z, _ := c.GetInt("page_z")
  43. if page_z < 1 {
  44. page_z = conf.Page_size
  45. }
  46. // 查询
  47. T_name := c.GetString("T_name")
  48. T_uuid := c.GetString("T_uuid")
  49. T_state, _ := c.GetInt("T_state")
  50. T_type, _ := c.GetInt("T_type")
  51. T_start_date := c.GetString("T_start_date") // 开始时间
  52. T_end_date := c.GetString("T_end_date") // 结束时间
  53. T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
  54. T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
  55. userList, _ := NatsServer.Read_User_List_All()
  56. Account.Read_User_All_Map(userList)
  57. Percentage.Read_VerifyCompany_All_Map()
  58. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  59. 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,
  60. false, T_state, T_type, page, page_z)
  61. var r_jsons lib.R_JSONS
  62. r_jsons.Num = R_cnt
  63. r_jsons.Data = R_List
  64. r_jsons.Page = page
  65. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  66. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  67. c.ServeJSON()
  68. return
  69. }
  70. func (c *PercentageController) Percentage_User_List() {
  71. // 分页参数 初始化
  72. page, _ := c.GetInt("page")
  73. if page < 1 {
  74. page = 1
  75. }
  76. page_z, _ := c.GetInt("page_z")
  77. if page_z < 1 {
  78. page_z = conf.Page_size
  79. }
  80. // 查询
  81. T_name := c.GetString("T_name")
  82. T_state, _ := c.GetInt("T_state")
  83. T_start_date := c.GetString("T_start_date") // 开始时间
  84. T_end_date := c.GetString("T_end_date") // 结束时间
  85. T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
  86. T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
  87. userList, _ := NatsServer.Read_User_List_All()
  88. Account.Read_User_All_Map(userList)
  89. Percentage.Read_VerifyCompany_All_Map()
  90. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  91. 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)
  92. var r_jsons lib.R_JSONS
  93. r_jsons.Num = R_cnt
  94. r_jsons.Data = R_List
  95. r_jsons.Page = page
  96. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  97. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  98. c.ServeJSON()
  99. return
  100. }
  101. func (c *PercentageController) Percentage_Export() {
  102. // 查询
  103. T_name := c.GetString("T_name")
  104. T_uuid := c.GetString("T_uuid")
  105. T_start_date := c.GetString("T_start_date") // 开始时间
  106. T_end_date := c.GetString("T_end_date") // 结束时间
  107. T_state, _ := c.GetInt("T_state")
  108. T_type, _ := c.GetInt("T_type") // 提成类型
  109. T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
  110. T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
  111. userList, _ := NatsServer.Read_User_List_All()
  112. Account.Read_User_All_Map(userList)
  113. Percentage.Read_VerifyCompany_All_Map()
  114. Basic.Read_VerifyItem_All_Map()
  115. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  116. 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)
  117. dataInterval := fmt.Sprintf("%s - %s", T_start_date, T_end_date)
  118. if dataInterval == " - " {
  119. dataInterval = ""
  120. }
  121. f := excelize.NewFile() // 设置单元格的值
  122. Style1, _ := f.NewStyle(
  123. &excelize.Style{
  124. Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
  125. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  126. })
  127. Style2, _ := f.NewStyle(
  128. &excelize.Style{
  129. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  130. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  131. Border: []excelize.Border{
  132. {Type: "left", Color: "000000", Style: 1},
  133. {Type: "top", Color: "000000", Style: 1},
  134. {Type: "bottom", Color: "000000", Style: 1},
  135. {Type: "right", Color: "000000", Style: 1},
  136. },
  137. })
  138. var schemeStartCell = "H"
  139. var schemeEndCell = "U"
  140. var reportingStartCell = "V"
  141. var reportingEndCell = "AE"
  142. f.MergeCell("Sheet1", "A1", reportingEndCell+"1")
  143. f.SetRowStyle("Sheet1", 1, 1, Style1)
  144. f.SetRowHeight("Sheet1", 1, 50)
  145. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("%s提成统计表", dataInterval))
  146. f.SetCellStyle("Sheet1", "A2", "G4", Style2)
  147. f.SetRowHeight("Sheet1", 2, 30)
  148. f.SetRowHeight("Sheet1", 4, 20)
  149. // 这里设置表头
  150. f.MergeCell("Sheet1", "A2", "A4")
  151. f.MergeCell("Sheet1", "B2", "B4")
  152. f.MergeCell("Sheet1", "C2", "C4")
  153. f.MergeCell("Sheet1", "D2", "D4")
  154. f.MergeCell("Sheet1", "E2", "E4")
  155. f.MergeCell("Sheet1", "F2", "F4")
  156. f.MergeCell("Sheet1", "G2", "G4")
  157. f.SetCellValue("Sheet1", "A2", "序号")
  158. f.SetCellValue("Sheet1", "B2", "公司名称")
  159. f.SetCellValue("Sheet1", "C2", "项目名称")
  160. f.SetCellValue("Sheet1", "D2", "项目负责人")
  161. f.SetCellValue("Sheet1", "E2", "统计日期")
  162. f.SetCellValue("Sheet1", "F2", "验证类型")
  163. f.SetCellValue("Sheet1", "G2", "提成类型")
  164. f.MergeCell("Sheet1", schemeStartCell+"2", schemeEndCell+"2")
  165. f.SetCellValue("Sheet1", schemeStartCell+"2", "验证实施")
  166. f.MergeCell("Sheet1", reportingStartCell+"2", reportingEndCell+"2")
  167. f.SetCellValue("Sheet1", reportingStartCell+"2", "报告编写")
  168. verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999)
  169. for _, item := range verifyItemList {
  170. f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name)
  171. if item.T_name != "其他" {
  172. f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price)
  173. }
  174. }
  175. f.MergeCell("Sheet1", schemeEndCell+"3", schemeEndCell+"4")
  176. f.SetCellValue("Sheet1", schemeEndCell+"3", "合计")
  177. f.MergeCell("Sheet1", reportingEndCell+"3", reportingEndCell+"4")
  178. f.SetCellValue("Sheet1", reportingEndCell+"3", "合计")
  179. // 设置列宽
  180. f.SetColWidth("Sheet1", "A", "A", 5)
  181. f.SetColWidth("Sheet1", "B", "B", 25)
  182. f.SetColWidth("Sheet1", "C", "C", 16)
  183. f.SetColWidth("Sheet1", "D", "E", 10)
  184. f.SetColWidth("Sheet1", "F", "F", 16)
  185. f.SetColWidth("Sheet1", "G", "G", 10)
  186. f.SetColWidth("Sheet1", schemeStartCell, reportingEndCell, 10)
  187. // 冻结1-3行
  188. f.SetPanes("Sheet1", &excelize.Panes{
  189. Freeze: true,
  190. Split: false,
  191. XSplit: 4, // 列
  192. YSplit: 4, // 行
  193. TopLeftCell: "A1",
  194. ActivePane: "topRight",
  195. })
  196. // 过滤器
  197. f.AutoFilter("Sheet1", "A4:G4", nil)
  198. // 循环写入数据
  199. line := 5
  200. for i, percentage := range percentageList {
  201. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  202. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), percentage.T_verifyCompany.T_name)
  203. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), percentage.T_task_name)
  204. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_uuid_name)
  205. if len(percentage.T_reporting_pass_time) > 0 {
  206. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_reporting_pass_time[:10])
  207. }
  208. deviceType := fmt.Sprintf("%s-%s", percentage.T_device_type, percentage.T_verify_type)
  209. if percentage.T_device_type == "位置" {
  210. deviceType = fmt.Sprintf("%s-%s(%d)", percentage.T_device_type, percentage.T_verify_type, percentage.T_device_quantity)
  211. }
  212. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), deviceType)
  213. verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item)
  214. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), percentage.T_approval_money)
  215. var verifyType string
  216. if percentage.T_type == Percentage.SchemeType {
  217. verifyType = "验证实施"
  218. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), percentage.T_approval_money)
  219. } else if percentage.T_type == Percentage.ReportingType {
  220. verifyType = "报告编写"
  221. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_approval_money)
  222. }
  223. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType)
  224. line++
  225. }
  226. // ------------- 最后一行 合计 ------------------------
  227. f.SetRowHeight("Sheet1", line, 22)
  228. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("G%d", line))
  229. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计")
  230. f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", schemeEndCell, schemeEndCell, line-1))
  231. f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", reportingEndCell, reportingEndCell, line-1))
  232. Style4, _ := f.NewStyle(
  233. &excelize.Style{
  234. Font: &excelize.Font{Size: 11, Family: "宋体"},
  235. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  236. Border: []excelize.Border{
  237. {Type: "left", Color: "000000", Style: 1},
  238. {Type: "top", Color: "000000", Style: 1},
  239. {Type: "bottom", Color: "000000", Style: 1},
  240. {Type: "right", Color: "000000", Style: 1},
  241. },
  242. })
  243. // 黄色填充
  244. StyleYellowFill, _ := f.NewStyle(
  245. &excelize.Style{
  246. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  247. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  248. Border: []excelize.Border{
  249. {Type: "left", Color: "000000", Style: 1},
  250. {Type: "top", Color: "000000", Style: 1},
  251. {Type: "bottom", Color: "000000", Style: 1},
  252. {Type: "right", Color: "000000", Style: 1},
  253. },
  254. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
  255. })
  256. // 黄色填充
  257. StyleYellowFill1, _ := f.NewStyle(
  258. &excelize.Style{
  259. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  260. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  261. Border: []excelize.Border{
  262. {Type: "left", Color: "000000", Style: 1},
  263. {Type: "top", Color: "000000", Style: 1},
  264. {Type: "bottom", Color: "000000", Style: 1},
  265. {Type: "right", Color: "000000", Style: 1},
  266. },
  267. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
  268. })
  269. // 绿色填充
  270. StyleGreenFill, _ := f.NewStyle(
  271. &excelize.Style{
  272. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  273. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  274. Border: []excelize.Border{
  275. {Type: "left", Color: "000000", Style: 1},
  276. {Type: "top", Color: "000000", Style: 1},
  277. {Type: "bottom", Color: "000000", Style: 1},
  278. {Type: "right", Color: "000000", Style: 1},
  279. },
  280. Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
  281. })
  282. StyleGreenFill1, _ := f.NewStyle(
  283. &excelize.Style{
  284. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  285. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  286. Border: []excelize.Border{
  287. {Type: "left", Color: "000000", Style: 1},
  288. {Type: "top", Color: "000000", Style: 1},
  289. {Type: "bottom", Color: "000000", Style: 1},
  290. {Type: "right", Color: "000000", Style: 1},
  291. },
  292. Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
  293. })
  294. f.SetCellStyle("Sheet1", "A5", fmt.Sprintf("%s%d", reportingEndCell, line), Style4)
  295. f.SetCellStyle("Sheet1", schemeStartCell+"2", schemeEndCell+"4", StyleYellowFill)
  296. f.SetCellStyle("Sheet1", schemeEndCell+"5", fmt.Sprintf("%s%d", schemeEndCell, line-1), StyleYellowFill1)
  297. f.SetCellStyle("Sheet1", reportingStartCell+"2", reportingEndCell+"4", StyleGreenFill)
  298. f.SetCellStyle("Sheet1", reportingEndCell+"5", fmt.Sprintf("%s%d", reportingEndCell, line-1), StyleGreenFill1)
  299. filename := fmt.Sprintf("%s提成统计表(%s)", dataInterval, lib.GetRandstring(6, "0123456789", 0))
  300. // 保存文件
  301. if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  302. fmt.Println(err)
  303. }
  304. // 上传 OSS
  305. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  306. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  307. if !is {
  308. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  309. c.ServeJSON()
  310. return
  311. }
  312. //删除目录
  313. err := os.Remove("ofile/" + filename + ".xlsx")
  314. if err != nil {
  315. logs.Error(lib.FuncName(), err)
  316. }
  317. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  318. c.ServeJSON()
  319. return
  320. }
  321. func (c *PercentageController) Percentage_User_Export() {
  322. // 查询
  323. T_name := c.GetString("T_name") // 关键字
  324. T_start_date := c.GetString("T_start_date") // 开始时间
  325. T_end_date := c.GetString("T_end_date") // 结束时间
  326. T_state, _ := c.GetInt("T_state")
  327. T_reporting_start_time := c.GetString("T_reporting_start_time") // 统计开始时间
  328. T_reporting_end_time := c.GetString("T_reporting_end_time") // 统计开始时间
  329. userList, _ := NatsServer.Read_User_List_All()
  330. Account.Read_User_All_Map(userList)
  331. Percentage.Read_VerifyCompany_All_Map()
  332. Basic.Read_VerifyItem_All_Map()
  333. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  334. 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)
  335. dataInterval := fmt.Sprintf("%s - %s", T_start_date, T_end_date)
  336. if dataInterval == " - " {
  337. dataInterval = ""
  338. }
  339. f := excelize.NewFile() // 设置单元格的值
  340. Style1, _ := f.NewStyle(
  341. &excelize.Style{
  342. Font: &excelize.Font{Bold: true, Size: 20, Family: "宋体"},
  343. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  344. })
  345. Style2, _ := f.NewStyle(
  346. &excelize.Style{
  347. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  348. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  349. Border: []excelize.Border{
  350. {Type: "left", Color: "000000", Style: 1},
  351. {Type: "top", Color: "000000", Style: 1},
  352. {Type: "bottom", Color: "000000", Style: 1},
  353. {Type: "right", Color: "000000", Style: 1},
  354. },
  355. })
  356. var schemeStartCell = "H"
  357. var schemeEndCell = "U"
  358. var reportingStartCell = "V"
  359. var reportingEndCell = "AE"
  360. f.MergeCell("Sheet1", "A1", reportingEndCell+"1")
  361. f.SetRowStyle("Sheet1", 1, 1, Style1)
  362. f.SetRowHeight("Sheet1", 1, 50)
  363. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("^%s%s提成统计表", c.User.T_name, dataInterval))
  364. f.SetCellStyle("Sheet1", "A2", "G4", Style2)
  365. f.SetRowHeight("Sheet1", 2, 30)
  366. f.SetRowHeight("Sheet1", 4, 20)
  367. // 这里设置表头
  368. f.MergeCell("Sheet1", "A2", "A4")
  369. f.MergeCell("Sheet1", "B2", "B4")
  370. f.MergeCell("Sheet1", "C2", "C4")
  371. f.MergeCell("Sheet1", "D2", "D4")
  372. f.MergeCell("Sheet1", "E2", "E4")
  373. f.MergeCell("Sheet1", "F2", "F4")
  374. f.MergeCell("Sheet1", "G2", "G4")
  375. f.SetCellValue("Sheet1", "A2", "序号")
  376. f.SetCellValue("Sheet1", "B2", "公司名称")
  377. f.SetCellValue("Sheet1", "C2", "项目名称")
  378. f.SetCellValue("Sheet1", "D2", "项目负责人")
  379. f.SetCellValue("Sheet1", "E2", "统计日期")
  380. f.SetCellValue("Sheet1", "F2", "验证类型")
  381. f.SetCellValue("Sheet1", "G2", "提成类型")
  382. f.MergeCell("Sheet1", schemeStartCell+"2", schemeEndCell+"2")
  383. f.SetCellValue("Sheet1", schemeStartCell+"2", "验证实施")
  384. f.MergeCell("Sheet1", reportingStartCell+"2", reportingEndCell+"2")
  385. f.SetCellValue("Sheet1", reportingStartCell+"2", "报告编写")
  386. verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 9999)
  387. for _, item := range verifyItemList {
  388. f.SetCellValue("Sheet1", fmt.Sprintf("%s3", item.T_cell), item.T_name)
  389. if item.T_name != "其他" {
  390. f.SetCellValue("Sheet1", fmt.Sprintf("%s4", item.T_cell), item.T_price)
  391. }
  392. }
  393. f.MergeCell("Sheet1", schemeEndCell+"3", schemeEndCell+"4")
  394. f.SetCellValue("Sheet1", schemeEndCell+"3", "合计")
  395. f.MergeCell("Sheet1", reportingEndCell+"3", reportingEndCell+"4")
  396. f.SetCellValue("Sheet1", reportingEndCell+"3", "合计")
  397. // 设置列宽
  398. f.SetColWidth("Sheet1", "A", "A", 5)
  399. f.SetColWidth("Sheet1", "B", "B", 25)
  400. f.SetColWidth("Sheet1", "C", "C", 16)
  401. f.SetColWidth("Sheet1", "D", "E", 10)
  402. f.SetColWidth("Sheet1", "F", "F", 16)
  403. f.SetColWidth("Sheet1", "G", "G", 10)
  404. f.SetColWidth("Sheet1", schemeStartCell, reportingEndCell, 10)
  405. // 冻结1-3行
  406. f.SetPanes("Sheet1", &excelize.Panes{
  407. Freeze: true,
  408. Split: false,
  409. XSplit: 4, // 列
  410. YSplit: 4, // 行
  411. TopLeftCell: "A1",
  412. ActivePane: "topRight",
  413. })
  414. // 过滤器
  415. f.AutoFilter("Sheet1", "A4:G4", nil)
  416. // 循环写入数据
  417. line := 5
  418. for i, percentage := range percentageList {
  419. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), i+1)
  420. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), percentage.T_verifyCompany.T_name)
  421. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), percentage.T_task_name)
  422. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), percentage.T_uuid_name)
  423. if len(percentage.T_reporting_pass_time) > 0 {
  424. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), percentage.T_reporting_pass_time[:10])
  425. }
  426. deviceType := fmt.Sprintf("%s-%s", percentage.T_device_type, percentage.T_verify_type)
  427. if percentage.T_device_type == "位置" {
  428. deviceType = fmt.Sprintf("%s-%s(%d)", percentage.T_device_type, percentage.T_verify_type, percentage.T_device_quantity)
  429. }
  430. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), deviceType)
  431. verifyItem := Basic.Read_VerifyItem_Get(percentage.T_verify_item)
  432. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", verifyItem.T_cell, line), percentage.T_approval_money)
  433. var verifyType string
  434. if percentage.T_type == Percentage.SchemeType {
  435. verifyType = "验证实施"
  436. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), percentage.T_approval_money)
  437. } else if percentage.T_type == Percentage.ReportingType {
  438. verifyType = "报告编写"
  439. f.SetCellValue("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), percentage.T_approval_money)
  440. }
  441. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), verifyType)
  442. line++
  443. }
  444. // ------------- 最后一行 合计 ------------------------
  445. f.SetRowHeight("Sheet1", line, 22)
  446. f.MergeCell("Sheet1", fmt.Sprintf("B%d", line), fmt.Sprintf("G%d", line))
  447. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), "合计")
  448. f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", schemeEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", schemeEndCell, schemeEndCell, line-1))
  449. f.SetCellFormula("Sheet1", fmt.Sprintf("%s%d", reportingEndCell, line), fmt.Sprintf("SUM(%s5:%s%d)", reportingEndCell, reportingEndCell, line-1))
  450. Style4, _ := f.NewStyle(
  451. &excelize.Style{
  452. Font: &excelize.Font{Size: 11, Family: "宋体"},
  453. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  454. Border: []excelize.Border{
  455. {Type: "left", Color: "000000", Style: 1},
  456. {Type: "top", Color: "000000", Style: 1},
  457. {Type: "bottom", Color: "000000", Style: 1},
  458. {Type: "right", Color: "000000", Style: 1},
  459. },
  460. })
  461. // 黄色填充
  462. StyleYellowFill, _ := f.NewStyle(
  463. &excelize.Style{
  464. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  465. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  466. Border: []excelize.Border{
  467. {Type: "left", Color: "000000", Style: 1},
  468. {Type: "top", Color: "000000", Style: 1},
  469. {Type: "bottom", Color: "000000", Style: 1},
  470. {Type: "right", Color: "000000", Style: 1},
  471. },
  472. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
  473. })
  474. // 黄色填充
  475. StyleYellowFill1, _ := f.NewStyle(
  476. &excelize.Style{
  477. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  478. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  479. Border: []excelize.Border{
  480. {Type: "left", Color: "000000", Style: 1},
  481. {Type: "top", Color: "000000", Style: 1},
  482. {Type: "bottom", Color: "000000", Style: 1},
  483. {Type: "right", Color: "000000", Style: 1},
  484. },
  485. Fill: excelize.Fill{Type: "pattern", Color: []string{"#FFFF00"}, Pattern: 1},
  486. })
  487. // 绿色填充
  488. StyleGreenFill, _ := f.NewStyle(
  489. &excelize.Style{
  490. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  491. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  492. Border: []excelize.Border{
  493. {Type: "left", Color: "000000", Style: 1},
  494. {Type: "top", Color: "000000", Style: 1},
  495. {Type: "bottom", Color: "000000", Style: 1},
  496. {Type: "right", Color: "000000", Style: 1},
  497. },
  498. Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
  499. })
  500. StyleGreenFill1, _ := f.NewStyle(
  501. &excelize.Style{
  502. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  503. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  504. Border: []excelize.Border{
  505. {Type: "left", Color: "000000", Style: 1},
  506. {Type: "top", Color: "000000", Style: 1},
  507. {Type: "bottom", Color: "000000", Style: 1},
  508. {Type: "right", Color: "000000", Style: 1},
  509. },
  510. Fill: excelize.Fill{Type: "pattern", Color: []string{"#92D050"}, Pattern: 1},
  511. })
  512. f.SetCellStyle("Sheet1", "A5", fmt.Sprintf("%s%d", reportingEndCell, line), Style4)
  513. f.SetCellStyle("Sheet1", schemeStartCell+"2", schemeEndCell+"4", StyleYellowFill)
  514. f.SetCellStyle("Sheet1", schemeEndCell+"5", fmt.Sprintf("%s%d", schemeEndCell, line-1), StyleYellowFill1)
  515. f.SetCellStyle("Sheet1", reportingStartCell+"2", reportingEndCell+"4", StyleGreenFill)
  516. f.SetCellStyle("Sheet1", reportingEndCell+"5", fmt.Sprintf("%s%d", reportingEndCell, line-1), StyleGreenFill1)
  517. filename := fmt.Sprintf("%s%s提成统计表(%s)", c.User.T_name, dataInterval, lib.GetRandstring(6, "0123456789", 0))
  518. // 保存文件
  519. if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  520. fmt.Println(err)
  521. }
  522. // 上传 OSS
  523. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  524. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  525. if !is {
  526. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  527. c.ServeJSON()
  528. return
  529. }
  530. //删除目录
  531. err := os.Remove("ofile/" + filename + ".xlsx")
  532. if err != nil {
  533. logs.Error(lib.FuncName(), err)
  534. }
  535. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  536. c.ServeJSON()
  537. return
  538. }
  539. func (c *PercentageController) Percentage_Get() {
  540. // 查询
  541. T_id, _ := c.GetInt("T_id")
  542. o := orm.NewOrm()
  543. PercentageDao := Percentage.NewPercentage(o)
  544. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  545. if err != nil {
  546. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  547. c.ServeJSON()
  548. return
  549. }
  550. Percentage.Read_VerifyCompany_All_Map()
  551. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Percentage.PercentageToPercentage_Detail(percentage)}
  552. c.ServeJSON()
  553. return
  554. }
  555. func (c *PercentageController) Percentage_Add() {
  556. T_device_type := c.GetString("T_device_type") // 提成类型
  557. T_verify_type := c.GetString("T_verify_type") // 验证类型
  558. T_company_uuid := c.GetString("T_company_uuid") // 公司id
  559. T_type, _ := c.GetInt("T_type") // 类型 1-验证实施 2-报告编写
  560. T_money, _ := c.GetFloat("T_money") // 金额
  561. company, is := Percentage.Read_VerifyCompany(T_company_uuid)
  562. if !is {
  563. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询公司信息失败!"}
  564. c.ServeJSON()
  565. return
  566. }
  567. var verifyItemMap map[string]Basic.VerifyItem
  568. verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap()
  569. if T_type == Percentage.SchemeType {
  570. verifyItemMap = verifyItemSchemeMap
  571. }
  572. if T_type == Percentage.ReportingType {
  573. verifyItemMap = verifyItemReportingMap
  574. }
  575. var_ := Percentage.Percentage{
  576. T_Distributor_id: company.T_Distributor_id,
  577. T_device_type: T_device_type,
  578. T_verify_type: T_verify_type,
  579. T_uuid: c.User.T_uuid,
  580. T_company_uuid: T_company_uuid,
  581. T_money: float32(T_money),
  582. T_type: T_type, //类型 1-验证实施 2-报告编写
  583. T_State: 6, // 6-未提交审核
  584. T_verify_item: verifyItemMap[T_device_type].Id,
  585. }
  586. o := orm.NewOrm()
  587. PercentageDao := Percentage.NewPercentage(o)
  588. id, err := PercentageDao.Add_Percentage(var_)
  589. if err != nil {
  590. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  591. c.ServeJSON()
  592. return
  593. }
  594. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "添加", var_)
  595. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: id}
  596. c.ServeJSON()
  597. return
  598. }
  599. func (c *PercentageController) Percentage_Approval() {
  600. T_id, _ := c.GetInt("T_id")
  601. T_state, _ := c.GetInt("T_state")
  602. T_approval_money, _ := c.GetFloat("T_approval_money")
  603. T_approval_opinion := c.GetString("T_approval_opinion")
  604. o := orm.NewOrm()
  605. PercentageDao := Percentage.NewPercentage(o)
  606. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  607. if err != nil {
  608. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改失败!"}
  609. c.ServeJSON()
  610. return
  611. }
  612. // 未提交审核 不能修改
  613. if percentage.T_State == Percentage.NotSubmit ||
  614. percentage.T_State == Percentage.AuditPass ||
  615. percentage.T_State == Percentage.RemitPart ||
  616. percentage.T_State == Percentage.RemitAll {
  617. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))}
  618. c.ServeJSON()
  619. return
  620. }
  621. Basic.Read_VerifyItem_All_Map()
  622. if len(T_approval_opinion) > 0 {
  623. percentage.T_approval_opinion = T_approval_opinion
  624. }
  625. if T_approval_money > 0 {
  626. percentage.T_approval_money = float32(T_approval_money)
  627. }
  628. // 2-已通过 3-未通过
  629. if T_state == 2 || T_state == 3 {
  630. percentage.T_State = T_state
  631. }
  632. err = PercentageDao.Update_Percentage(percentage, "T_State", "T_approval_opinion", "T_approval_money")
  633. if err != nil {
  634. o.Rollback()
  635. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  636. c.ServeJSON()
  637. return
  638. }
  639. if T_state == Percentage.AuditPass {
  640. NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核已通过", percentage.T_task_id), conf.MyPercentageUrl)
  641. }
  642. if T_state == Percentage.AuditUnPass {
  643. NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)审核未通过", percentage.T_task_id), conf.MyPercentageUrl)
  644. }
  645. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage)
  646. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  647. c.ServeJSON()
  648. return
  649. }
  650. func (c *PercentageController) Percentage_Edit() {
  651. T_id, _ := c.GetInt("T_id")
  652. T_device_type := c.GetString("T_device_type") // 提成类型
  653. T_verify_type := c.GetString("T_verify_type") // 验证类型
  654. T_company_uuid := c.GetString("T_company_uuid") // 公司id
  655. T_money, _ := c.GetFloat("T_money") // 金额
  656. T_type, _ := c.GetInt("T_type") // 类型 1-验证实施 2-报告编写
  657. company, is := Percentage.Read_VerifyCompany(T_company_uuid)
  658. if !is {
  659. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询公司信息失败!"}
  660. c.ServeJSON()
  661. return
  662. }
  663. var verifyItemMap map[string]Basic.VerifyItem
  664. verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap()
  665. if T_type == Percentage.SchemeType {
  666. verifyItemMap = verifyItemSchemeMap
  667. }
  668. if T_type == Percentage.ReportingType {
  669. verifyItemMap = verifyItemReportingMap
  670. }
  671. o := orm.NewOrm()
  672. PercentageDao := Percentage.NewPercentage(o)
  673. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  674. if err != nil {
  675. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  676. c.ServeJSON()
  677. return
  678. }
  679. // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-未提交审核 合同状态为未通过,修改之后将状态更改为待审核
  680. if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll {
  681. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止修改!", Percentage.Read_Audit_Get(percentage.T_State))}
  682. c.ServeJSON()
  683. return
  684. }
  685. if len(T_company_uuid) > 0 {
  686. percentage.T_company_uuid = T_company_uuid
  687. percentage.T_Distributor_id = company.T_Distributor_id
  688. }
  689. if len(T_device_type) > 0 {
  690. percentage.T_device_type = T_device_type
  691. }
  692. if len(T_verify_type) > 0 {
  693. percentage.T_verify_type = T_verify_type
  694. }
  695. if T_type > 0 {
  696. percentage.T_type = T_type
  697. }
  698. if T_money > 0 {
  699. percentage.T_money = float32(T_money)
  700. }
  701. //percentage.T_money = verifyItemMap[percentage.T_device_type].T_price
  702. percentage.T_verify_item = verifyItemMap[percentage.T_device_type].Id
  703. err = PercentageDao.Update_Percentage(percentage, "T_company_uuid", "T_Distributor_id", "T_device_type", "T_verify_type", "T_type", "T_money", "T_verify_item")
  704. if err != nil {
  705. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  706. c.ServeJSON()
  707. return
  708. }
  709. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "修改", percentage)
  710. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id}
  711. c.ServeJSON()
  712. return
  713. }
  714. func (c *PercentageController) Percentage_Del() {
  715. T_id, _ := c.GetInt("T_id")
  716. o := orm.NewOrm()
  717. PercentageDao := Percentage.NewPercentage(o)
  718. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  719. if err != nil {
  720. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  721. c.ServeJSON()
  722. return
  723. }
  724. // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 合同状态为未通过,修改之后将状态更改为待审核
  725. if percentage.T_State == Percentage.AuditPass || percentage.T_State == Percentage.RemitPart || percentage.T_State == Percentage.RemitAll {
  726. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止删除!", Percentage.Read_Audit_Get(percentage.T_State))}
  727. c.ServeJSON()
  728. return
  729. }
  730. err = PercentageDao.Delete_Percentage(percentage)
  731. if err != nil {
  732. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  733. c.ServeJSON()
  734. return
  735. }
  736. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id)
  737. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  738. c.ServeJSON()
  739. return
  740. }
  741. func (c *PercentageController) Percentage_Admin_Del() {
  742. T_id, _ := c.GetInt("T_id")
  743. o := orm.NewOrm()
  744. PercentageDao := Percentage.NewPercentage(o)
  745. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  746. if err != nil {
  747. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  748. c.ServeJSON()
  749. return
  750. }
  751. err = PercentageDao.Delete_Percentage(percentage)
  752. if err != nil {
  753. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除失败!"}
  754. c.ServeJSON()
  755. return
  756. }
  757. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "删除", T_id)
  758. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  759. c.ServeJSON()
  760. return
  761. }
  762. // 打款
  763. func (c *PercentageController) Percentage_Remit() {
  764. T_id, _ := c.GetInt("T_id")
  765. o := orm.NewOrm()
  766. PercentageDao := Percentage.NewPercentage(o)
  767. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  768. if err != nil {
  769. o.Rollback()
  770. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  771. c.ServeJSON()
  772. return
  773. }
  774. if percentage.T_State == 5 {
  775. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id}
  776. c.ServeJSON()
  777. return
  778. }
  779. // 1-待审核 2-审核通过 3-审核不通过 5-已打款 合同状态为未通过,修改之后将状态更改为待审核
  780. if percentage.T_State == 1 || percentage.T_State == 3 {
  781. c.Data["json"] = lib.JSONS{Code: 202, Msg: "当前状态不可提交打款!"}
  782. c.ServeJSON()
  783. return
  784. }
  785. percentage.T_State = 5
  786. err = PercentageDao.Update_Percentage(percentage, "T_State")
  787. if err != nil {
  788. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  789. c.ServeJSON()
  790. return
  791. }
  792. if percentage.T_State == 5 {
  793. NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已打款", percentage.T_task_id), conf.MyPercentageUrl)
  794. }
  795. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "提交打款", percentage)
  796. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id}
  797. c.ServeJSON()
  798. return
  799. }
  800. func (c *PercentageController) User_List() {
  801. var r_jsons lib.R_JSONS
  802. // 分页参数 初始化
  803. page, _ := c.GetInt("page")
  804. if page < 1 {
  805. page = 1
  806. }
  807. page_z, _ := c.GetInt("page_z")
  808. if page_z < 1 {
  809. page_z = conf.Page_size
  810. }
  811. T_name := c.GetString("T_name")
  812. ReimburseDao := Percentage.NewPercentage(orm.NewOrm())
  813. uuidList := ReimburseDao.Read_T_uuid_List()
  814. if len(uuidList) == 0 {
  815. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  816. c.ServeJSON()
  817. return
  818. }
  819. R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
  820. if err != nil {
  821. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
  822. c.ServeJSON()
  823. return
  824. }
  825. var U_List []userlibs.User
  826. for _, user := range R_List {
  827. U_List = append(U_List, user)
  828. }
  829. r_jsons.Num = R_cnt
  830. r_jsons.Data = U_List
  831. r_jsons.Page = page
  832. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  833. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  834. c.ServeJSON()
  835. return
  836. }
  837. func (c *PercentageController) Contract_List() {
  838. // 分页参数 初始化
  839. page, _ := c.GetInt("page")
  840. if page < 1 {
  841. page = 1
  842. }
  843. page_z, _ := c.GetInt("page_z")
  844. if page_z < 1 {
  845. page_z = conf.Page_size
  846. }
  847. // 查询
  848. T_name := c.GetString("T_name")
  849. ContractDao := Contract.NewContract(orm.NewOrm())
  850. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 0, 0, page, page_z)
  851. var r_jsons lib.R_JSONS
  852. r_jsons.Num = R_cnt
  853. r_jsons.Data = R_List
  854. r_jsons.Page = page
  855. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  856. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  857. c.ServeJSON()
  858. return
  859. }
  860. // 提交审核
  861. func (c *PercentageController) Percentage_Submit_Audit() {
  862. T_id, _ := c.GetInt("T_id")
  863. o := orm.NewOrm()
  864. PercentageDao := Percentage.NewPercentage(o)
  865. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  866. if err != nil {
  867. c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交失败!"}
  868. c.ServeJSON()
  869. return
  870. }
  871. if percentage.T_State != 6 && percentage.T_State != 3 {
  872. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))}
  873. c.ServeJSON()
  874. return
  875. }
  876. // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-待审核 审核状态
  877. percentage.T_State = 1
  878. err = PercentageDao.Update_Percentage(percentage, "T_State")
  879. if err != nil {
  880. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  881. c.ServeJSON()
  882. return
  883. }
  884. NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【提成申请】您有一条提成申请(%s)待审核", percentage.T_task_id), conf.PercentageApprovalUrl)
  885. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage)
  886. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  887. c.ServeJSON()
  888. return
  889. }
  890. func (c *PercentageController) Percentage_SyncVerify() {
  891. SyncVerifyPercentage(false)
  892. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  893. c.ServeJSON()
  894. return
  895. }
  896. func Cron_Percentage() {
  897. //创建一个定时任务对象
  898. c := cron.New(cron.WithSeconds())
  899. //给对象增加定时任务
  900. //c.AddFunc("0 */1 * * * ?", Cron_SyncColdVerifyCompany)
  901. c.AddFunc("@daily", Cron_SyncColdVerifyCompany)
  902. //c.AddFunc("0 */1 * * * ?", Cron_SyncVerifyPercentage)
  903. c.AddFunc("@daily", Cron_SyncVerifyPercentage)
  904. //启动定时任务
  905. c.Start()
  906. defer c.Stop()
  907. //查询语句,阻塞,让main函数不退出,保持程序运行
  908. select {}
  909. }
  910. func Cron_SyncColdVerifyCompany() {
  911. url := "/openapi/company/list"
  912. signature, timestamp := lib.GenColdVerifySignature()
  913. client := resty.New()
  914. resp, err := client.R().SetFormData(map[string]string{
  915. "T_reporting_pass_start_time": "",
  916. "T_reporting_pass_end_time": "",
  917. "X-API-KEY": lib.ColdVerify_OpenApi_Key,
  918. "X-API-SIGNATURE": signature,
  919. "X-API-TIMESTAMP": timestamp,
  920. }).Post(conf.ColdVerify_OpenApi_Host + url)
  921. if err != nil {
  922. logs.Error("请求冷链验证公司列表接口失败!")
  923. return
  924. }
  925. type R_JSONS struct {
  926. //必须的大写开头
  927. Data []Percentage.VerifyCompany
  928. Code int64
  929. Msg string
  930. }
  931. var res R_JSONS
  932. if err = json.Unmarshal(resp.Body(), &res); err != nil {
  933. logs.Error("请求冷链验证公司列表接口失败!")
  934. return
  935. }
  936. for _, company := range res.Data {
  937. c, is := Percentage.Read_VerifyCompany(company.T_uuid)
  938. if is {
  939. if c.T_name != company.T_name || c.T_Distributor_name != company.T_Distributor_name {
  940. c.T_name = company.T_name
  941. c.T_Distributor_name = company.T_Distributor_name
  942. Percentage.Update_VerifyCompany(c, "T_name", "T_Distributor_name")
  943. }
  944. } else {
  945. Percentage.Add_VerifyCompany(company)
  946. }
  947. }
  948. }
  949. // 读取冷链验证任务,同步到提成
  950. // 定时统计前一天审核通过的任务
  951. func Cron_SyncVerifyPercentage() {
  952. SyncVerifyPercentage(true)
  953. }
  954. func SyncVerifyPercentage(isCron bool) {
  955. url := "/openapi/task/list"
  956. signature, timestamp := lib.GenColdVerifySignature()
  957. client := resty.New()
  958. var start_time, end_time string
  959. if isCron {
  960. t := time.Now().Add(-time.Hour * 24).Format("2006-01-02")
  961. start_time = t + " 00:00:00"
  962. end_time = t + " 23:59:59"
  963. }
  964. client.SetTimeout(30 * time.Second)
  965. client.SetRetryCount(3).SetRetryWaitTime(1 * time.Second)
  966. resp, err := client.R().SetFormData(map[string]string{
  967. "T_reporting_pass_start_time": start_time,
  968. "T_reporting_pass_end_time": end_time,
  969. "X-API-KEY": lib.ColdVerify_OpenApi_Key,
  970. "X-API-SIGNATURE": signature,
  971. "X-API-TIMESTAMP": timestamp,
  972. }).Post(conf.ColdVerify_OpenApi_Host + url)
  973. if err != nil {
  974. logs.Error("请求冷链验证任务列表接口失败!")
  975. return
  976. }
  977. type R_JSONS struct {
  978. //必须的大写开头
  979. Data []Percentage.VerifyTask
  980. Code int64
  981. Msg string
  982. }
  983. var res R_JSONS
  984. if err = json.Unmarshal(resp.Body(), &res); err != nil {
  985. logs.Error("请求冷链验证任务列表接口失败!")
  986. return
  987. }
  988. verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap()
  989. coldVerifyUUIDMap := GetColdVerifyUUIDMap()
  990. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  991. for _, task := range res.Data {
  992. // 自动同步报告提成
  993. _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.ReportingType)
  994. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  995. verifyItem := GetPercentageMoney(Percentage.DeviceTypeMap[task.T_device_type], task.T_verify_type, verifyItemReportingMap)
  996. // 添加报告提成
  997. percentage := Percentage.Percentage{
  998. T_Distributor_id: task.T_Distributor_id,
  999. T_task_id: task.T_task_id,
  1000. T_task_int_id: task.Id,
  1001. T_device_type: Percentage.DeviceTypeMap[task.T_device_type],
  1002. T_verify_type: task.T_verify_type,
  1003. T_device_quantity: task.T_device_quantity,
  1004. T_company_uuid: task.T_uuid,
  1005. T_task_name: task.T_name,
  1006. T_uuid: coldVerifyUUIDMap[task.T_reporting],
  1007. T_money: verifyItem.T_price,
  1008. T_type: Percentage.ReportingType,
  1009. T_State: 1,
  1010. T_verify_item: verifyItem.Id,
  1011. T_reporting_pass_time: task.T_reporting_pass_time,
  1012. }
  1013. if task.T_device_type == "WZ" {
  1014. percentage.T_money = verifyItem.T_price * float32(task.T_device_quantity)
  1015. }
  1016. _, err = PercentageDao.Add_Percentage(percentage)
  1017. }
  1018. // 由经销商id的任务 只有报告,不需要同步实施提成
  1019. if len(task.T_Distributor_id) > 0 {
  1020. continue
  1021. }
  1022. // 自动同步实施提成
  1023. _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.SchemeType)
  1024. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  1025. T_device_type := Percentage.DeviceTypeMap[task.T_device_type]
  1026. verifyItem := GetPercentageMoney(T_device_type, task.T_verify_type, verifyItemSchemeMap)
  1027. // 添加报告提成
  1028. percentage := Percentage.Percentage{
  1029. T_Distributor_id: task.T_Distributor_id,
  1030. T_task_id: task.T_task_id,
  1031. T_task_int_id: task.Id,
  1032. T_device_type: T_device_type,
  1033. T_verify_type: task.T_verify_type,
  1034. T_device_quantity: task.T_device_quantity,
  1035. T_company_uuid: task.T_uuid,
  1036. T_task_name: task.T_name,
  1037. T_uuid: coldVerifyUUIDMap[task.T_collection],
  1038. T_money: verifyItem.T_price,
  1039. T_type: Percentage.SchemeType,
  1040. T_State: 1,
  1041. T_verify_item: verifyItem.Id,
  1042. T_reporting_pass_time: task.T_reporting_pass_time,
  1043. }
  1044. if task.T_device_type == "WZ" {
  1045. percentage.T_money = verifyItem.T_price * float32(task.T_device_quantity)
  1046. }
  1047. _, err = PercentageDao.Add_Percentage(percentage)
  1048. }
  1049. }
  1050. }
  1051. func GetVerifyItemMap() (map[string]Basic.VerifyItem, map[string]Basic.VerifyItem) {
  1052. verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 999)
  1053. var verifyItemSchemeMap = make(map[string]Basic.VerifyItem) // 实施
  1054. var verifyItemReportingMap = make(map[string]Basic.VerifyItem) // 实施
  1055. for _, item := range verifyItemList {
  1056. if item.T_type == Percentage.SchemeType {
  1057. verifyItemSchemeMap[item.T_name] = item
  1058. }
  1059. if item.T_type == Percentage.ReportingType {
  1060. verifyItemReportingMap[item.T_name] = item
  1061. }
  1062. }
  1063. return verifyItemSchemeMap, verifyItemReportingMap
  1064. }
  1065. func GetColdVerifyUUIDMap() (uuidMap map[string]string) {
  1066. uuidMap = make(map[string]string)
  1067. userList, _ := NatsServer.Read_User_List_All()
  1068. for _, user := range userList {
  1069. uuidMap[user.T_verify_cold_uuid] = user.T_uuid
  1070. }
  1071. return uuidMap
  1072. }
  1073. // 获取实施提成金额
  1074. func GetPercentageMoney(T_device_type, T_verify_type string, verifyItemMap map[string]Basic.VerifyItem) (money Basic.VerifyItem) {
  1075. if strings.Contains(T_device_type, "箱") {
  1076. return verifyItemMap["箱"]
  1077. }
  1078. if strings.Contains(T_device_type, "车") {
  1079. if strings.Contains(T_verify_type, "空载") {
  1080. return verifyItemMap["车(空载)"]
  1081. } else {
  1082. return verifyItemMap["车(满载)"]
  1083. }
  1084. }
  1085. if strings.Contains(T_device_type, "柜") {
  1086. if strings.Contains(T_verify_type, "空载") {
  1087. return verifyItemMap["库(空载)"]
  1088. } else {
  1089. return verifyItemMap["库(满载)"]
  1090. }
  1091. }
  1092. if strings.Contains(T_device_type, "库") {
  1093. if strings.Contains(T_verify_type, "空载") {
  1094. return verifyItemMap["库(空载)"]
  1095. } else {
  1096. return verifyItemMap["库(满载)"]
  1097. }
  1098. }
  1099. if strings.Contains(T_device_type, "系统") {
  1100. return verifyItemMap["系统"]
  1101. }
  1102. if strings.Contains(T_device_type, "位置") {
  1103. return verifyItemMap["位置"]
  1104. }
  1105. if strings.Contains(T_device_type, "巡检") {
  1106. return verifyItemMap["巡检"]
  1107. }
  1108. if strings.Contains(T_device_type, "培训") {
  1109. return verifyItemMap["培训"]
  1110. }
  1111. if strings.Contains(T_device_type, "其他") {
  1112. return verifyItemMap["其他"]
  1113. }
  1114. return Basic.VerifyItem{}
  1115. }
  1116. func (c *PercentageController) VerifyCompany_List() {
  1117. // 分页参数 初始化
  1118. page, _ := c.GetInt("page")
  1119. if page < 1 {
  1120. page = 1
  1121. }
  1122. page_z, _ := c.GetInt("page_z")
  1123. if page_z < 1 {
  1124. page_z = conf.Page_size
  1125. }
  1126. // 查询
  1127. T_name := c.GetString("T_name")
  1128. T_state, _ := c.GetInt("T_state")
  1129. R_List, R_cnt := Percentage.Read_VerifyCompany_List(T_name, T_state, page, page_z)
  1130. var r_jsons lib.R_JSONS
  1131. r_jsons.Num = R_cnt
  1132. r_jsons.Data = R_List
  1133. r_jsons.Page = page
  1134. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1135. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1136. c.ServeJSON()
  1137. return
  1138. }
  1139. func (c *PercentageController) VerifyCompany_Add() {
  1140. T_name := c.GetString("T_name")
  1141. T_recoveries_time := c.GetString("T_recoveries_time") // 回款时间
  1142. T_State, _ := c.GetInt("T_State") // 总价
  1143. var_ := Percentage.VerifyCompany{
  1144. T_name: T_name,
  1145. T_State: T_State,
  1146. T_recoveries_time: T_recoveries_time,
  1147. }
  1148. if _, is := Percentage.Read_VerifyCompanyByT_name(T_name); is {
  1149. c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称重复!"}
  1150. c.ServeJSON()
  1151. return
  1152. }
  1153. Id, is := Percentage.Add_VerifyCompany(var_)
  1154. if !is {
  1155. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1156. c.ServeJSON()
  1157. return
  1158. }
  1159. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "添加", var_)
  1160. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  1161. c.ServeJSON()
  1162. return
  1163. }
  1164. func (c *PercentageController) VerifyCompany_Edit() {
  1165. T_uuid := c.GetString("T_uuid")
  1166. T_State, _ := c.GetInt("T_State") // 总价
  1167. T_recoveries_time := c.GetString("T_recoveries_time") // 回款时间
  1168. company, is := Percentage.Read_VerifyCompany(T_uuid)
  1169. if !is {
  1170. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"}
  1171. c.ServeJSON()
  1172. return
  1173. }
  1174. if T_State > 0 {
  1175. company.T_State = T_State
  1176. }
  1177. if len(T_recoveries_time) > 0 {
  1178. company.T_recoveries_time = T_recoveries_time
  1179. }
  1180. if !Percentage.Update_VerifyCompany(company, "T_State", "T_recoveries_time") {
  1181. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改验证公司失败"}
  1182. c.ServeJSON()
  1183. return
  1184. }
  1185. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "修改", company)
  1186. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid}
  1187. c.ServeJSON()
  1188. return
  1189. }
  1190. func (c *PercentageController) VerifyCompany_Del() {
  1191. T_uuid := c.GetString("T_uuid")
  1192. company, is := Percentage.Read_VerifyCompany(T_uuid)
  1193. if !is {
  1194. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"}
  1195. c.ServeJSON()
  1196. return
  1197. }
  1198. if !Percentage.Delete_VerifyCompany(company) {
  1199. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除验证公司失败"}
  1200. c.ServeJSON()
  1201. return
  1202. }
  1203. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "删除", company.T_uuid)
  1204. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid}
  1205. c.ServeJSON()
  1206. return
  1207. }