Percentage.go 44 KB

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