Percentage.go 43 KB

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