Percentage.go 43 KB

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