Percentage.go 45 KB

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