Percentage.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346
  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. o := orm.NewOrm()
  748. PercentageDao := Percentage.NewPercentage(o)
  749. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  750. if err != nil {
  751. o.Rollback()
  752. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败!"}
  753. c.ServeJSON()
  754. return
  755. }
  756. if percentage.T_State == 5 {
  757. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id}
  758. c.ServeJSON()
  759. return
  760. }
  761. // 1-待审核 2-审核通过 3-审核不通过 5-已打款 合同状态为未通过,修改之后将状态更改为待审核
  762. if percentage.T_State == 1 || percentage.T_State == 3 {
  763. c.Data["json"] = lib.JSONS{Code: 202, Msg: "当前状态不可提交打款!"}
  764. c.ServeJSON()
  765. return
  766. }
  767. percentage.T_State = 5
  768. err = PercentageDao.Update_Percentage(percentage, "T_State")
  769. if err != nil {
  770. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  771. c.ServeJSON()
  772. return
  773. }
  774. if percentage.T_State == 5 {
  775. NatsServer.AddNews(percentage.T_uuid, fmt.Sprintf("【提成申请】您提交的提成申请(%s)已打款", percentage.T_task_id), conf.MyPercentageUrl)
  776. }
  777. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "提交打款", percentage)
  778. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: percentage.Id}
  779. c.ServeJSON()
  780. return
  781. }
  782. func (c *PercentageController) User_List() {
  783. var r_jsons lib.R_JSONS
  784. // 分页参数 初始化
  785. page, _ := c.GetInt("page")
  786. if page < 1 {
  787. page = 1
  788. }
  789. page_z, _ := c.GetInt("page_z")
  790. if page_z < 1 {
  791. page_z = conf.Page_size
  792. }
  793. T_name := c.GetString("T_name")
  794. ReimburseDao := Percentage.NewPercentage(orm.NewOrm())
  795. uuidList := ReimburseDao.Read_T_uuid_List()
  796. if len(uuidList) == 0 {
  797. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  798. c.ServeJSON()
  799. return
  800. }
  801. R_List, R_cnt, err := NatsServer.Read_User_List_T_uuid(T_name, uuidList, page, page_z)
  802. if err != nil {
  803. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询失败"}
  804. c.ServeJSON()
  805. return
  806. }
  807. var U_List []userlibs.User
  808. for _, user := range R_List {
  809. U_List = append(U_List, user)
  810. }
  811. r_jsons.Num = R_cnt
  812. r_jsons.Data = U_List
  813. r_jsons.Page = page
  814. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  815. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  816. c.ServeJSON()
  817. return
  818. }
  819. func (c *PercentageController) Contract_List() {
  820. // 分页参数 初始化
  821. page, _ := c.GetInt("page")
  822. if page < 1 {
  823. page = 1
  824. }
  825. page_z, _ := c.GetInt("page_z")
  826. if page_z < 1 {
  827. page_z = conf.Page_size
  828. }
  829. // 查询
  830. T_name := c.GetString("T_name")
  831. ContractDao := Contract.NewContract(orm.NewOrm())
  832. R_List, R_cnt := ContractDao.Read_Contract_List("", T_name, 0, 0, page, page_z)
  833. var r_jsons lib.R_JSONS
  834. r_jsons.Num = R_cnt
  835. r_jsons.Data = R_List
  836. r_jsons.Page = page
  837. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  838. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  839. c.ServeJSON()
  840. return
  841. }
  842. // 提交审核
  843. func (c *PercentageController) Percentage_Submit_Audit() {
  844. T_id, _ := c.GetInt("T_id")
  845. o := orm.NewOrm()
  846. PercentageDao := Percentage.NewPercentage(o)
  847. percentage, err := PercentageDao.Read_Percentage_ById(T_id)
  848. if err != nil {
  849. c.Data["json"] = lib.JSONS{Code: 202, Msg: "提交失败!"}
  850. c.ServeJSON()
  851. return
  852. }
  853. if percentage.T_State != 6 && percentage.T_State != 3 {
  854. c.Data["json"] = lib.JSONS{Code: 202, Msg: fmt.Sprintf("状态为%s,禁止提交!", Percentage.Read_Audit_Get(percentage.T_State))}
  855. c.ServeJSON()
  856. return
  857. }
  858. // 1-待审核 2-审核通过 3-审核不通过 4-部分打款 5-全部打款 6-待审核 审核状态
  859. percentage.T_State = 1
  860. err = PercentageDao.Update_Percentage(percentage, "T_State")
  861. if err != nil {
  862. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  863. c.ServeJSON()
  864. return
  865. }
  866. NatsServer.AddNews(conf.FinanceUuid, fmt.Sprintf("【提成申请】您有一条提成申请(%s)待审核", percentage.T_task_id), conf.PercentageApprovalUrl)
  867. NatsServer.AddUserLogs(c.User.T_uuid, "提成", "审核", percentage)
  868. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: T_id}
  869. c.ServeJSON()
  870. return
  871. }
  872. func (c *PercentageController) Percentage_SyncVerify() {
  873. SyncVerifyPercentage(false)
  874. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  875. c.ServeJSON()
  876. return
  877. }
  878. func Cron_Percentage() {
  879. //创建一个定时任务对象
  880. c := cron.New(cron.WithSeconds())
  881. //给对象增加定时任务
  882. //c.AddFunc("0 */1 * * * ?", Cron_SyncColdVerifyCompany)
  883. c.AddFunc("@daily", Cron_SyncColdVerifyCompany)
  884. //c.AddFunc("0 */1 * * * ?", Cron_SyncVerifyPercentage)
  885. c.AddFunc("@daily", Cron_SyncVerifyPercentage)
  886. //启动定时任务
  887. c.Start()
  888. defer c.Stop()
  889. //查询语句,阻塞,让main函数不退出,保持程序运行
  890. select {}
  891. }
  892. func Cron_SyncColdVerifyCompany() {
  893. url := "/openapi/company/list"
  894. signature, timestamp := lib.GenColdVerifySignature()
  895. client := resty.New()
  896. resp, err := client.R().SetFormData(map[string]string{
  897. "CreateDate": "",
  898. "X-API-KEY": lib.ColdVerify_OpenApi_Key,
  899. "X-API-SIGNATURE": signature,
  900. "X-API-TIMESTAMP": timestamp,
  901. }).Post(conf.ColdVerify_OpenApi_Host + url)
  902. if err != nil {
  903. logs.Error("请求冷链验证公司列表接口失败!")
  904. return
  905. }
  906. type R_JSONS struct {
  907. //必须的大写开头
  908. Data []Percentage.VerifyCompany
  909. Code int64
  910. Msg string
  911. }
  912. var res R_JSONS
  913. if err = json.Unmarshal(resp.Body(), &res); err != nil {
  914. logs.Error("请求冷链验证公司列表接口失败!")
  915. return
  916. }
  917. for _, company := range res.Data {
  918. c, is := Percentage.Read_VerifyCompany(company.T_uuid)
  919. if is {
  920. if c.T_name != company.T_name || c.T_Distributor_name != company.T_Distributor_name {
  921. c.T_name = company.T_name
  922. c.T_Distributor_name = company.T_Distributor_name
  923. Percentage.Update_VerifyCompany(c, "T_name", "T_Distributor_name")
  924. }
  925. } else {
  926. Percentage.Add_VerifyCompany(company)
  927. }
  928. }
  929. }
  930. // 读取冷链验证任务,同步到提成
  931. // 定时统计前一天审核通过的任务
  932. func Cron_SyncVerifyPercentage() {
  933. SyncVerifyPercentage(true)
  934. }
  935. func SyncVerifyPercentage(isCron bool) {
  936. url := "/openapi/task/list"
  937. signature, timestamp := lib.GenColdVerifySignature()
  938. client := resty.New()
  939. var createDate string
  940. if isCron {
  941. createDate = time.Now().Add(-time.Hour * 24).Format("2006-01-02")
  942. }
  943. client.SetTimeout(30 * time.Second)
  944. client.SetRetryCount(3).SetRetryWaitTime(1 * time.Second)
  945. resp, err := client.R().SetFormData(map[string]string{
  946. "CreateDate": createDate,
  947. "X-API-KEY": lib.ColdVerify_OpenApi_Key,
  948. "X-API-SIGNATURE": signature,
  949. "X-API-TIMESTAMP": timestamp,
  950. }).Post(conf.ColdVerify_OpenApi_Host + url)
  951. if err != nil {
  952. logs.Error("请求冷链验证任务列表接口失败!")
  953. return
  954. }
  955. type R_JSONS struct {
  956. //必须的大写开头
  957. Data []Percentage.VerifyTask
  958. Code int64
  959. Msg string
  960. }
  961. var res R_JSONS
  962. if err = json.Unmarshal(resp.Body(), &res); err != nil {
  963. logs.Error("请求冷链验证任务列表接口失败!")
  964. return
  965. }
  966. verifyItemSchemeMap, verifyItemReportingMap := GetVerifyItemMap()
  967. coldVerifyUUIDMap := GetColdVerifyUUIDMap()
  968. PercentageDao := Percentage.NewPercentage(orm.NewOrm())
  969. for _, task := range res.Data {
  970. // 自动同步报告提成
  971. _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.ReportingType)
  972. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  973. verifyItem := GetPercentageMoney(task.T_device_type, task.T_verify_type, verifyItemReportingMap)
  974. // 添加报告提成
  975. percentage := Percentage.Percentage{
  976. T_Distributor_id: task.T_Distributor_id,
  977. T_task_id: task.T_task_id,
  978. T_task_int_id: task.Id,
  979. T_device_type: Percentage.DeviceTypeMap[task.T_device_type],
  980. T_verify_type: task.T_verify_type,
  981. T_company_uuid: task.T_uuid,
  982. T_task_name: task.T_name,
  983. T_uuid: coldVerifyUUIDMap[task.T_reporting],
  984. T_money: verifyItem.T_price,
  985. T_type: Percentage.ReportingType,
  986. T_State: 1,
  987. T_verify_item: verifyItem.Id,
  988. T_reporting_pass_time: task.T_reporting_pass_time,
  989. }
  990. _, err = PercentageDao.Add_Percentage(percentage)
  991. }
  992. // 由经销商id的任务 只有报告,不需要同步实施提成
  993. if len(task.T_Distributor_id) > 0 {
  994. continue
  995. }
  996. // 自动同步实施提成
  997. _, err = PercentageDao.Read_Percentage_ByT_T_task_id_T_type(task.T_task_id, Percentage.SchemeType)
  998. if err != nil && err.Error() == orm.ErrNoRows.Error() {
  999. verifyItem := GetPercentageMoney(task.T_device_type, task.T_verify_type, verifyItemSchemeMap)
  1000. // 添加报告提成
  1001. percentage := Percentage.Percentage{
  1002. T_Distributor_id: task.T_Distributor_id,
  1003. T_task_id: task.T_task_id,
  1004. T_task_int_id: task.Id,
  1005. T_device_type: Percentage.DeviceTypeMap[task.T_device_type],
  1006. T_verify_type: task.T_verify_type,
  1007. T_company_uuid: task.T_uuid,
  1008. T_task_name: task.T_name,
  1009. T_uuid: coldVerifyUUIDMap[task.T_scheme],
  1010. T_money: verifyItem.T_price,
  1011. T_type: Percentage.SchemeType,
  1012. T_State: 1,
  1013. T_verify_item: verifyItem.Id,
  1014. T_reporting_pass_time: task.T_reporting_pass_time,
  1015. }
  1016. _, err = PercentageDao.Add_Percentage(percentage)
  1017. }
  1018. }
  1019. }
  1020. func GetVerifyItemMap() (map[string]Basic.VerifyItem, map[string]Basic.VerifyItem) {
  1021. verifyItemList, _ := Basic.Read_VerifyItem_List(0, "", 0, 999)
  1022. var verifyItemSchemeMap = make(map[string]Basic.VerifyItem) // 实施
  1023. var verifyItemReportingMap = make(map[string]Basic.VerifyItem) // 实施
  1024. for _, item := range verifyItemList {
  1025. if item.T_type == Percentage.SchemeType {
  1026. verifyItemSchemeMap[item.T_name] = item
  1027. }
  1028. if item.T_type == Percentage.ReportingType {
  1029. verifyItemReportingMap[item.T_name] = item
  1030. }
  1031. }
  1032. return verifyItemSchemeMap, verifyItemReportingMap
  1033. }
  1034. func GetColdVerifyUUIDMap() (uuidMap map[string]string) {
  1035. uuidMap = make(map[string]string)
  1036. userList, _ := NatsServer.Read_User_List_All()
  1037. for _, user := range userList {
  1038. uuidMap[user.T_verify_cold_uuid] = user.T_uuid
  1039. }
  1040. return uuidMap
  1041. }
  1042. // 获取实施提成金额
  1043. func GetPercentageMoney(T_device_type, T_verify_type string, verifyItemMap map[string]Basic.VerifyItem) (money Basic.VerifyItem) {
  1044. if strings.Contains(T_device_type, "箱") {
  1045. return verifyItemMap["保温箱"]
  1046. }
  1047. if strings.Contains(T_device_type, "车") {
  1048. if strings.Contains(T_verify_type, "空载") {
  1049. return verifyItemMap["冷藏车(空载)"]
  1050. } else {
  1051. return verifyItemMap["冷藏车(满载)"]
  1052. }
  1053. }
  1054. if strings.Contains(T_device_type, "柜") {
  1055. if strings.Contains(T_verify_type, "空载") {
  1056. return verifyItemMap["冷库(空载)"]
  1057. } else {
  1058. return verifyItemMap["冷库(满载)"]
  1059. }
  1060. }
  1061. if strings.Contains(T_device_type, "库") {
  1062. if strings.Contains(T_verify_type, "空载") {
  1063. return verifyItemMap["冷库(空载)"]
  1064. } else {
  1065. return verifyItemMap["冷库(满载)"]
  1066. }
  1067. }
  1068. if strings.Contains(T_device_type, "系统验证") {
  1069. return verifyItemMap["系统验证"]
  1070. }
  1071. if strings.Contains(T_device_type, "位置") {
  1072. return verifyItemMap["位置"]
  1073. }
  1074. return Basic.VerifyItem{}
  1075. }
  1076. func (c *PercentageController) VerifyCompany_List() {
  1077. // 分页参数 初始化
  1078. page, _ := c.GetInt("page")
  1079. if page < 1 {
  1080. page = 1
  1081. }
  1082. page_z, _ := c.GetInt("page_z")
  1083. if page_z < 1 {
  1084. page_z = conf.Page_size
  1085. }
  1086. // 查询
  1087. T_name := c.GetString("T_name")
  1088. T_state, _ := c.GetInt("T_state")
  1089. R_List, R_cnt := Percentage.Read_VerifyCompany_List(T_name, T_state, page, page_z)
  1090. var r_jsons lib.R_JSONS
  1091. r_jsons.Num = R_cnt
  1092. r_jsons.Data = R_List
  1093. r_jsons.Page = page
  1094. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(page_z)))
  1095. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  1096. c.ServeJSON()
  1097. return
  1098. }
  1099. func (c *PercentageController) VerifyCompany_Add() {
  1100. T_name := c.GetString("T_name")
  1101. T_State, _ := c.GetInt("T_State") // 总价
  1102. var_ := Percentage.VerifyCompany{
  1103. T_name: T_name,
  1104. T_State: T_State,
  1105. }
  1106. if _, is := Percentage.Read_VerifyCompanyByT_name(T_name); is {
  1107. c.Data["json"] = lib.JSONS{Code: 202, Msg: "公司名称重复!"}
  1108. c.ServeJSON()
  1109. return
  1110. }
  1111. Id, is := Percentage.Add_VerifyCompany(var_)
  1112. if !is {
  1113. c.Data["json"] = lib.JSONS{Code: 202, Msg: "添加失败!"}
  1114. c.ServeJSON()
  1115. return
  1116. }
  1117. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "添加", var_)
  1118. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  1119. c.ServeJSON()
  1120. return
  1121. }
  1122. func (c *PercentageController) VerifyCompany_Edit() {
  1123. T_uuid := c.GetString("T_uuid")
  1124. T_State, _ := c.GetInt("T_State") // 总价
  1125. company, is := Percentage.Read_VerifyCompany(T_uuid)
  1126. if !is {
  1127. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"}
  1128. c.ServeJSON()
  1129. return
  1130. }
  1131. if T_State > 0 {
  1132. company.T_State = T_State
  1133. if !Percentage.Update_VerifyCompany(company, "T_State") {
  1134. c.Data["json"] = lib.JSONS{Code: 202, Msg: "修改验证公司失败"}
  1135. c.ServeJSON()
  1136. return
  1137. }
  1138. }
  1139. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "修改", company)
  1140. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid}
  1141. c.ServeJSON()
  1142. return
  1143. }
  1144. func (c *PercentageController) VerifyCompany_Del() {
  1145. T_uuid := c.GetString("T_uuid")
  1146. company, is := Percentage.Read_VerifyCompany(T_uuid)
  1147. if !is {
  1148. c.Data["json"] = lib.JSONS{Code: 202, Msg: "查询验证公司失败"}
  1149. c.ServeJSON()
  1150. return
  1151. }
  1152. if !Percentage.Delete_VerifyCompany(company) {
  1153. c.Data["json"] = lib.JSONS{Code: 202, Msg: "删除验证公司失败"}
  1154. c.ServeJSON()
  1155. return
  1156. }
  1157. NatsServer.AddUserLogs(c.User.T_uuid, "验证公司", "删除", company.T_uuid)
  1158. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: company.T_uuid}
  1159. c.ServeJSON()
  1160. return
  1161. }