ContractReview.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package controllers
  2. import (
  3. "ERP_storage/Nats"
  4. "ERP_storage/Nats/NatsServer"
  5. "ERP_storage/conf"
  6. "ERP_storage/dto"
  7. "ERP_storage/logs"
  8. "ERP_storage/models/Account"
  9. models "ERP_storage/models/ContractReview"
  10. "ERP_storage/services"
  11. "encoding/json"
  12. "fmt"
  13. natslibs "gogs.baozhida.cn/zoie/ERP_libs/Nats"
  14. userlibs "gogs.baozhida.cn/zoie/ERP_libs/User"
  15. "gogs.baozhida.cn/zoie/ERP_libs/lib"
  16. beego "github.com/beego/beego/v2/server/web"
  17. "github.com/xuri/excelize/v2"
  18. "math"
  19. "os"
  20. "strconv"
  21. )
  22. type ContractReviewController struct {
  23. beego.Controller
  24. User userlibs.User
  25. }
  26. func (c *ContractReviewController) Prepare() {
  27. c.User = *Account.User_r
  28. }
  29. // 服务类型
  30. func (c *ContractReviewController) ServiceType_List() {
  31. s := services.ServiceType{}
  32. reqData := dto.ServiceTypePageReq{}
  33. if err := c.ParseForm(&reqData); err != nil {
  34. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  35. c.ServeJSON()
  36. return
  37. }
  38. if err := Validate(&reqData); err != nil {
  39. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  40. c.ServeJSON()
  41. return
  42. }
  43. R_List, R_cnt := s.GetPage(&reqData)
  44. var r_jsons lib.R_JSONS
  45. r_jsons.Num = R_cnt
  46. r_jsons.Data = R_List
  47. r_jsons.Page = reqData.Page
  48. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize)))
  49. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  50. c.ServeJSON()
  51. return
  52. }
  53. func (c *ContractReviewController) ServiceType_Add() {
  54. s := services.ServiceType{}
  55. reqData := dto.ServiceTypeInsertReq{}
  56. if err := c.ParseForm(&reqData); err != nil {
  57. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  58. c.ServeJSON()
  59. return
  60. }
  61. if err := Validate(&reqData); err != nil {
  62. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  63. c.ServeJSON()
  64. return
  65. }
  66. Id, err := s.Insert(&reqData)
  67. if err != nil {
  68. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  69. c.ServeJSON()
  70. return
  71. }
  72. NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "添加", reqData)
  73. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  74. c.ServeJSON()
  75. return
  76. }
  77. func (c *ContractReviewController) ServiceType_Edit() {
  78. s := services.ServiceType{}
  79. reqData := dto.ServiceTypeUpdateReq{}
  80. if err := c.ParseForm(&reqData); err != nil {
  81. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  82. c.ServeJSON()
  83. return
  84. }
  85. if err := Validate(&reqData); err != nil {
  86. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  87. c.ServeJSON()
  88. return
  89. }
  90. if err := s.Update(&reqData); err != nil {
  91. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  92. c.ServeJSON()
  93. return
  94. }
  95. NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "修改", reqData)
  96. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  97. c.ServeJSON()
  98. return
  99. }
  100. func (c *ContractReviewController) ServiceType_Del() {
  101. s := services.ServiceType{}
  102. reqData := dto.ServiceTypeDeleteReq{}
  103. if err := c.ParseForm(&reqData); err != nil {
  104. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  105. c.ServeJSON()
  106. return
  107. }
  108. if err := Validate(&reqData); err != nil {
  109. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  110. c.ServeJSON()
  111. return
  112. }
  113. if err := s.Delete(&reqData); err != nil {
  114. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  115. c.ServeJSON()
  116. return
  117. }
  118. NatsServer.AddUserLogs(c.User.T_uuid, "服务类型", "删除", strconv.Itoa(reqData.T_id))
  119. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  120. c.ServeJSON()
  121. return
  122. }
  123. // 服务内容
  124. func (c *ContractReviewController) ServiceItem_List() {
  125. s := services.ServiceItem{}
  126. reqData := dto.ServiceItemPageReq{}
  127. if err := c.ParseForm(&reqData); err != nil {
  128. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  129. c.ServeJSON()
  130. return
  131. }
  132. if err := Validate(&reqData); err != nil {
  133. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  134. c.ServeJSON()
  135. return
  136. }
  137. R_List, R_cnt := s.GetPage(&reqData)
  138. var r_jsons lib.R_JSONS
  139. r_jsons.Num = R_cnt
  140. r_jsons.Data = R_List
  141. r_jsons.Page = reqData.Page
  142. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize)))
  143. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  144. c.ServeJSON()
  145. return
  146. }
  147. func (c *ContractReviewController) ServiceItem_Add() {
  148. s := services.ServiceItem{}
  149. reqData := dto.ServiceItemInsertReq{}
  150. if err := c.ParseForm(&reqData); err != nil {
  151. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  152. c.ServeJSON()
  153. return
  154. }
  155. if err := Validate(&reqData); err != nil {
  156. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  157. c.ServeJSON()
  158. return
  159. }
  160. Id, err := s.Insert(&reqData)
  161. if err != nil {
  162. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  163. c.ServeJSON()
  164. return
  165. }
  166. NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "添加", reqData)
  167. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  168. c.ServeJSON()
  169. return
  170. }
  171. func (c *ContractReviewController) ServiceItem_Edit() {
  172. s := services.ServiceItem{}
  173. reqData := dto.ServiceItemUpdateReq{}
  174. if err := c.ParseForm(&reqData); err != nil {
  175. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  176. c.ServeJSON()
  177. return
  178. }
  179. if err := Validate(&reqData); err != nil {
  180. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  181. c.ServeJSON()
  182. return
  183. }
  184. if err := s.Update(&reqData); err != nil {
  185. c.Data["json"] = lib.JSONS{Code: 203, Msg: "修改失败"}
  186. c.ServeJSON()
  187. return
  188. }
  189. NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "修改", reqData)
  190. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  191. c.ServeJSON()
  192. return
  193. }
  194. func (c *ContractReviewController) ServiceItem_Del() {
  195. s := services.ServiceItem{}
  196. reqData := dto.ServiceItemDeleteReq{}
  197. if err := c.ParseForm(&reqData); err != nil {
  198. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  199. c.ServeJSON()
  200. return
  201. }
  202. if err := Validate(&reqData); err != nil {
  203. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  204. c.ServeJSON()
  205. return
  206. }
  207. if err := s.Delete(&reqData); err != nil {
  208. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  209. c.ServeJSON()
  210. return
  211. }
  212. NatsServer.AddUserLogs(c.User.T_uuid, "服务内容", "删除", strconv.Itoa(reqData.T_id))
  213. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  214. c.ServeJSON()
  215. return
  216. }
  217. // 合同评审-用户
  218. func (c *ContractReviewController) List() {
  219. s := services.ContractReview{}
  220. reqData := dto.ContractReviewPageReq{}
  221. if err := c.ParseForm(&reqData); err != nil {
  222. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  223. c.ServeJSON()
  224. return
  225. }
  226. if err := Validate(&reqData); err != nil {
  227. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  228. c.ServeJSON()
  229. return
  230. }
  231. userList, _ := NatsServer.Read_User_List_All()
  232. Account.Read_User_All_Map(userList)
  233. reqData.T_submit = c.User.T_uuid
  234. R_List, R_cnt := s.GetPage(&reqData)
  235. var r_jsons lib.R_JSONS
  236. r_jsons.Num = R_cnt
  237. r_jsons.Data = R_List
  238. r_jsons.Page = reqData.Page
  239. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize)))
  240. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  241. c.ServeJSON()
  242. return
  243. }
  244. // 合同评审-财务
  245. func (c *ContractReviewController) Finance_List() {
  246. s := services.ContractReview{}
  247. reqData := dto.ContractReviewPageReq{}
  248. if err := c.ParseForm(&reqData); err != nil {
  249. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  250. c.ServeJSON()
  251. return
  252. }
  253. if err := Validate(&reqData); err != nil {
  254. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  255. c.ServeJSON()
  256. return
  257. }
  258. userList, _ := NatsServer.Read_User_List_All()
  259. Account.Read_User_All_Map(userList)
  260. R_List, R_cnt := s.GetFinancePage(&reqData)
  261. var r_jsons lib.R_JSONS
  262. r_jsons.Num = R_cnt
  263. r_jsons.Data = R_List
  264. r_jsons.Page = reqData.Page
  265. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize)))
  266. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  267. c.ServeJSON()
  268. return
  269. }
  270. // 合同评审-财务
  271. func (c *ContractReviewController) Manager_List() {
  272. s := services.ContractReview{}
  273. reqData := dto.ContractReviewPageReq{}
  274. if err := c.ParseForm(&reqData); err != nil {
  275. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  276. c.ServeJSON()
  277. return
  278. }
  279. if err := Validate(&reqData); err != nil {
  280. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  281. c.ServeJSON()
  282. return
  283. }
  284. userList, _ := NatsServer.Read_User_List_All()
  285. Account.Read_User_All_Map(userList)
  286. R_List, R_cnt := s.GetManagerPage(&reqData)
  287. var r_jsons lib.R_JSONS
  288. r_jsons.Num = R_cnt
  289. r_jsons.Data = R_List
  290. r_jsons.Page = reqData.Page
  291. r_jsons.Page_size = int(math.Ceil(float64(R_cnt) / float64(reqData.PageSize)))
  292. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  293. c.ServeJSON()
  294. return
  295. }
  296. // 负责人列表
  297. func (c *ContractReviewController) Submit_User_List() {
  298. s := services.ContractReview{}
  299. reqData := dto.ContractReviewSubmitUserPageReq{}
  300. if err := c.ParseForm(&reqData); err != nil {
  301. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  302. c.ServeJSON()
  303. return
  304. }
  305. if err := Validate(&reqData); err != nil {
  306. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  307. c.ServeJSON()
  308. return
  309. }
  310. userList, _ := NatsServer.Read_User_List_All()
  311. Account.Read_User_All_Map(userList)
  312. R_List, R_cnt := s.GetSubmitUserPage(&reqData)
  313. var r_jsons lib.R_JSONS
  314. r_jsons.Num = R_cnt
  315. r_jsons.Data = R_List
  316. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: r_jsons}
  317. c.ServeJSON()
  318. return
  319. }
  320. func (c *ContractReviewController) Add() {
  321. s := services.ContractReview{}
  322. reqData := dto.ContractReviewInsertReq{}
  323. if err := c.ParseForm(&reqData); err != nil {
  324. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  325. c.ServeJSON()
  326. return
  327. }
  328. if err := json.Unmarshal([]byte(reqData.ServiceItems), &reqData.ServiceItemList); err != nil {
  329. c.Data["json"] = lib.JSONS{Code: 202, Msg: "服务内容 参数错误"}
  330. c.ServeJSON()
  331. return
  332. }
  333. if err := Validate(&reqData); err != nil {
  334. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  335. c.ServeJSON()
  336. return
  337. }
  338. reqData.T_submit = c.User.T_uuid
  339. Id, err := s.Insert(&reqData)
  340. if err != nil {
  341. c.Data["json"] = lib.JSONS{Code: 203, Msg: "添加失败"}
  342. c.ServeJSON()
  343. return
  344. }
  345. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "添加", reqData)
  346. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: Id}
  347. c.ServeJSON()
  348. return
  349. }
  350. func (c *ContractReviewController) Edit() {
  351. s := services.ContractReview{}
  352. reqData := dto.ContractReviewUpdateReq{}
  353. if err := c.ParseForm(&reqData); err != nil {
  354. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  355. c.ServeJSON()
  356. return
  357. }
  358. if err := json.Unmarshal([]byte(reqData.ServiceItems), &reqData.ServiceItemList); err != nil {
  359. c.Data["json"] = lib.JSONS{Code: 202, Msg: "服务内容 参数错误"}
  360. c.ServeJSON()
  361. return
  362. }
  363. if err := Validate(&reqData); err != nil {
  364. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  365. c.ServeJSON()
  366. return
  367. }
  368. if err := s.Update(&reqData); err != nil {
  369. c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
  370. c.ServeJSON()
  371. return
  372. }
  373. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "修改", reqData)
  374. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  375. c.ServeJSON()
  376. return
  377. }
  378. // 提交审核
  379. func (c *ContractReviewController) Submit_Audit() {
  380. s := services.ContractReview{}
  381. reqData := dto.ContractReviewGetReq{}
  382. if err := c.ParseForm(&reqData); err != nil {
  383. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  384. c.ServeJSON()
  385. return
  386. }
  387. if err := Validate(&reqData); err != nil {
  388. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  389. c.ServeJSON()
  390. return
  391. }
  392. if err := s.SubmitAudit(&reqData); err != nil {
  393. c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
  394. c.ServeJSON()
  395. return
  396. }
  397. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "提交审核", reqData)
  398. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  399. c.ServeJSON()
  400. return
  401. }
  402. // 财务审核
  403. func (c *ContractReviewController) Finance_Audit() {
  404. s := services.ContractReview{}
  405. reqData := dto.ContractReviewAuditReq{}
  406. if err := c.ParseForm(&reqData); err != nil {
  407. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  408. c.ServeJSON()
  409. return
  410. }
  411. if err := Validate(&reqData); err != nil {
  412. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  413. c.ServeJSON()
  414. return
  415. }
  416. if !(reqData.T_audit == 3 || reqData.T_audit == 4) {
  417. c.Data["json"] = lib.JSONS{Code: 202, Msg: "状态参数错误"}
  418. c.ServeJSON()
  419. return
  420. }
  421. if err := s.FinanceAudit(&reqData); err != nil {
  422. c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
  423. c.ServeJSON()
  424. return
  425. }
  426. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "财务审核", reqData)
  427. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  428. c.ServeJSON()
  429. return
  430. }
  431. // 管理员审核
  432. func (c *ContractReviewController) Manager_Audit() {
  433. s := services.ContractReview{}
  434. reqData := dto.ContractReviewAuditReq{}
  435. if err := c.ParseForm(&reqData); err != nil {
  436. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  437. c.ServeJSON()
  438. return
  439. }
  440. if err := Validate(&reqData); err != nil {
  441. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  442. c.ServeJSON()
  443. return
  444. }
  445. if !(reqData.T_audit == 5 || reqData.T_audit == 6) {
  446. c.Data["json"] = lib.JSONS{Code: 202, Msg: "状态参数错误"}
  447. c.ServeJSON()
  448. return
  449. }
  450. if err := s.ManagerAudit(&reqData); err != nil {
  451. c.Data["json"] = lib.JSONS{Code: 203, Msg: err.Error()}
  452. c.ServeJSON()
  453. return
  454. }
  455. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "总经理审核", reqData)
  456. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  457. c.ServeJSON()
  458. return
  459. }
  460. func (c *ContractReviewController) Del() {
  461. s := services.ContractReview{}
  462. reqData := dto.ContractReviewDeleteReq{}
  463. if err := c.ParseForm(&reqData); err != nil {
  464. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  465. c.ServeJSON()
  466. return
  467. }
  468. if err := Validate(&reqData); err != nil {
  469. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  470. c.ServeJSON()
  471. return
  472. }
  473. if err := s.Delete(&reqData); err != nil {
  474. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  475. c.ServeJSON()
  476. return
  477. }
  478. NatsServer.AddUserLogs(c.User.T_uuid, "合同评审", "删除", strconv.Itoa(reqData.T_id))
  479. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!"}
  480. c.ServeJSON()
  481. return
  482. }
  483. func (c *ContractReviewController) Stock_Detail_Excel() {
  484. s := services.ContractReview{}
  485. reqData := dto.ContractReviewPageReq{}
  486. if err := c.ParseForm(&reqData); err != nil {
  487. c.Data["json"] = lib.JSONS{Code: 202, Msg: "参数错误"}
  488. c.ServeJSON()
  489. return
  490. }
  491. if err := Validate(&reqData); err != nil {
  492. c.Data["json"] = lib.JSONS{Code: 202, Msg: err.Error()}
  493. c.ServeJSON()
  494. return
  495. }
  496. userList, _ := NatsServer.Read_User_List_All()
  497. Account.Read_User_All_Map(userList)
  498. reqData.PageSize = 9999
  499. R_List, _ := s.GetFinancePage(&reqData)
  500. filename := fmt.Sprintf("合同评审统计表(%s)", lib.GetRandstring(6, "0123456789", 0))
  501. f := excelize.NewFile() // 设置单元格的值
  502. Style1, _ := f.NewStyle(
  503. &excelize.Style{
  504. Font: &excelize.Font{Bold: true, Size: 12, Family: "宋体"},
  505. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center"},
  506. })
  507. Style2, _ := f.NewStyle(
  508. &excelize.Style{
  509. Font: &excelize.Font{Bold: true, Size: 10, Family: "宋体"},
  510. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  511. Border: []excelize.Border{
  512. {Type: "left", Color: "000000", Style: 1},
  513. {Type: "top", Color: "000000", Style: 1},
  514. {Type: "bottom", Color: "000000", Style: 1},
  515. {Type: "right", Color: "000000", Style: 1},
  516. },
  517. })
  518. f.MergeCell("Sheet1", "A1", "I1")
  519. f.SetRowStyle("Sheet1", 1, 1, Style1)
  520. f.SetCellValue("Sheet1", "A1", fmt.Sprintf("宝智达科技合同评审统计表"))
  521. f.SetRowHeight("Sheet1", 1, 30)
  522. // 这里设置表头
  523. f.SetCellStyle("Sheet1", "A2", "I2", Style2)
  524. f.SetRowHeight("Sheet1", 2, 20)
  525. f.SetCellValue("Sheet1", "A2", "序号")
  526. f.SetCellValue("Sheet1", "B2", "状态")
  527. f.SetCellValue("Sheet1", "C2", "项目名称")
  528. f.SetCellValue("Sheet1", "D2", "项目地址")
  529. f.SetCellValue("Sheet1", "E2", "项目负责人")
  530. f.SetCellValue("Sheet1", "F2", "预计签约时间")
  531. f.SetCellValue("Sheet1", "G2", "总金额")
  532. f.SetCellValue("Sheet1", "H2", "最终优惠金额")
  533. f.SetCellValue("Sheet1", "I2", "是否有居间费")
  534. f.SetCellValue("Sheet1", "J2", "居间费金额")
  535. // 设置列宽
  536. f.SetColWidth("Sheet1", "A", "A", 10)
  537. f.SetColWidth("Sheet1", "B", "B", 10)
  538. f.SetColWidth("Sheet1", "C", "D", 15)
  539. f.SetColWidth("Sheet1", "D", "D", 20)
  540. f.SetColWidth("Sheet1", "E", "E", 12)
  541. f.SetColWidth("Sheet1", "F", "F", 12)
  542. f.SetColWidth("Sheet1", "G", "H", 10)
  543. f.SetColWidth("Sheet1", "I", "I", 12)
  544. f.SetColWidth("Sheet1", "J", "J", 10)
  545. line := 2
  546. // 循环写入数据
  547. for _, v := range R_List {
  548. line++
  549. f.SetCellValue("Sheet1", fmt.Sprintf("A%d", line), line-2)
  550. f.SetCellValue("Sheet1", fmt.Sprintf("B%d", line), models.Get_T_audit_name(v.T_audit))
  551. f.SetCellValue("Sheet1", fmt.Sprintf("C%d", line), v.T_name)
  552. f.SetCellValue("Sheet1", fmt.Sprintf("D%d", line), v.T_address)
  553. f.SetCellValue("Sheet1", fmt.Sprintf("E%d", line), v.T_submit_name)
  554. f.SetCellValue("Sheet1", fmt.Sprintf("F%d", line), v.T_predict_sign_time)
  555. f.SetCellValue("Sheet1", fmt.Sprintf("G%d", line), v.T_money)
  556. f.SetCellValue("Sheet1", fmt.Sprintf("H%d", line), v.T_discount_money)
  557. T_have_brokerage_fee_str := "否"
  558. if v.T_have_brokerage_fee == true {
  559. T_have_brokerage_fee_str = "是"
  560. }
  561. f.SetCellValue("Sheet1", fmt.Sprintf("I%d", line), T_have_brokerage_fee_str)
  562. f.SetCellValue("Sheet1", fmt.Sprintf("J%d", line), v.T_brokerage_fee_money)
  563. }
  564. Style4, _ := f.NewStyle(
  565. &excelize.Style{
  566. Font: &excelize.Font{Size: 10, Family: "宋体"},
  567. Alignment: &excelize.Alignment{Horizontal: "center", Vertical: "center", WrapText: true},
  568. Border: []excelize.Border{
  569. {Type: "left", Color: "000000", Style: 1},
  570. {Type: "top", Color: "000000", Style: 1},
  571. {Type: "bottom", Color: "000000", Style: 1},
  572. {Type: "right", Color: "000000", Style: 1},
  573. },
  574. })
  575. f.SetCellStyle("Sheet1", "A2", fmt.Sprintf("I%d", line), Style4)
  576. // 保存文件
  577. if err := f.SaveAs("ofile/" + filename + ".xlsx"); err != nil {
  578. fmt.Println(err)
  579. }
  580. var url string
  581. //// 上传 OSS
  582. nats := natslibs.NewNats(Nats.Nats, conf.NatsSubj_Prefix)
  583. url, is := nats.Qiniu_UploadFile(lib.GetCurrentDirectory()+"/ofile/"+filename+".xlsx", "ofile/"+filename+".xlsx")
  584. if !is {
  585. c.Data["json"] = lib.JSONS{Code: 202, Msg: "oss!"}
  586. c.ServeJSON()
  587. return
  588. }
  589. //删除目录
  590. err := os.Remove("ofile/" + filename + ".xlsx")
  591. if err != nil {
  592. logs.Error(lib.FuncName(), err)
  593. }
  594. c.Data["json"] = lib.JSONS{Code: 200, Msg: "ok!", Data: url}
  595. c.ServeJSON()
  596. return
  597. }