chart_census.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. package yb
  2. import (
  3. "errors"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "github.com/tealeg/xlsx"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/yb"
  9. "hongze/hz_crm_api/utils"
  10. "os"
  11. "path/filepath"
  12. "strconv"
  13. "strings"
  14. "time"
  15. )
  16. // ChartController 研报图表统计模块
  17. type ChartCensusController struct {
  18. controllers.BaseAuthController
  19. }
  20. // GetChartVisitCensusList
  21. // @Title 获取图表阅读统计列表
  22. // @Description 获取图表阅读统计列表
  23. // @Param ClassifyId query int false "图表分类ID"
  24. // @Success 200 {object} yb.ChartVisitPageListResp
  25. // @router /chartCensus/getVisitList [get]
  26. func (this *ChartCensusController) GetChartVisitCensusList() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. classifyId, _ := this.GetInt("ClassifyId")
  40. order, _ := this.GetInt("Order")
  41. // 分页
  42. pageSize, _ := this.GetInt("PageSize")
  43. currentIndex, _ := this.GetInt("CurrentIndex")
  44. var startSize int
  45. if pageSize <= 0 {
  46. pageSize = utils.PageSize20
  47. }
  48. if currentIndex <= 0 {
  49. currentIndex = 1
  50. }
  51. startSize = paging.StartIndex(currentIndex, pageSize)
  52. total, list, err := yb.GetChartVisitPageList(classifyId, startSize, pageSize, order)
  53. if err != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取失败, Err: " + err.Error()
  56. return
  57. }
  58. page := paging.GetPaging(currentIndex, pageSize, total)
  59. resp := yb.ChartVisitPageListResp{
  60. List: list,
  61. Paging: page,
  62. }
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "获取成功"
  66. br.Data = resp
  67. }
  68. // GetChartVisitDetailCensusList
  69. // @Title 获取图表阅读详情统计列表
  70. // @Description 获取图表阅读详情统计列表
  71. // @Param ClassifyId query int true "图表分类ID"
  72. // @Param SellerId query string false "销售IDs,多个用英文逗号拼接"
  73. // @Param CompanyStatus query string false "图表分类ID,多个用英文逗号拼接"
  74. // @Param Keyword query string false "关键词"
  75. // @Param Order query int false "排序 1-查看时间升序 2-查看时间倒序"
  76. // @Success 200 {object} yb.ChartVisitDetailPageListResp
  77. // @router /chartCensus/getVisitDetailList [get]
  78. func (this *ChartCensusController) GetChartVisitDetailCensusList() {
  79. br := new(models.BaseResponse).Init()
  80. defer func() {
  81. this.Data["json"] = br
  82. this.ServeJSON()
  83. }()
  84. sysUser := this.SysUser
  85. if sysUser == nil {
  86. br.Msg = "请登录"
  87. br.ErrMsg = "请登录,SysUser Is Empty"
  88. br.Ret = 408
  89. return
  90. }
  91. classifyId, _ := this.GetInt("ClassifyId")
  92. if classifyId <= 0 {
  93. br.Msg = "分类ID有误"
  94. return
  95. }
  96. sellerId := this.GetString("SellerId")
  97. companyStatus := this.GetString("CompanyStatus")
  98. keyword := this.GetString("Keyword")
  99. order, _ := this.GetInt("Order")
  100. pageSize, _ := this.GetInt("PageSize")
  101. currentIndex, _ := this.GetInt("CurrentIndex")
  102. totalList, totalClassify, list, err := getChartVisitDetailCensusData(classifyId, order, pageSize, currentIndex, sellerId, companyStatus, keyword)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.Msg = "获取阅读详情统计失败-" + err.Error()
  106. return
  107. }
  108. page := paging.GetPaging(currentIndex, pageSize, totalList)
  109. resp := yb.ChartVisitDetailPageListResp{
  110. List: list,
  111. VisitTotal: totalClassify,
  112. Paging: page,
  113. }
  114. br.Ret = 200
  115. br.Success = true
  116. br.Msg = "获取成功"
  117. br.Data = resp
  118. }
  119. // GetCompanyChartVisitDetail
  120. // @Title 获取用户图表访问明细
  121. // @Description 获取用户图表访问明细
  122. // @Param ClassifyId query int true "图表分类ID"
  123. // @Param UserId query int true "用户ID"
  124. // @Success 200 {object} yb.UserClassifyChartVisitList
  125. // @router /chartCensus/getCompanyChartVisitDetail [get]
  126. func (this *ChartCensusController) GetCompanyChartVisitDetail() {
  127. br := new(models.BaseResponse).Init()
  128. defer func() {
  129. this.Data["json"] = br
  130. this.ServeJSON()
  131. }()
  132. sysUser := this.SysUser
  133. if sysUser == nil {
  134. br.Msg = "请登录"
  135. br.ErrMsg = "请登录,SysUser Is Empty"
  136. br.Ret = 408
  137. return
  138. }
  139. classifyId, _ := this.GetInt("ClassifyId")
  140. if classifyId <= 0 {
  141. br.Msg = "分类ID有误"
  142. return
  143. }
  144. userId, _ := this.GetInt("UserId")
  145. if userId <= 0 {
  146. br.Msg = "用户ID有误"
  147. return
  148. }
  149. list, err := yb.GetUserClassifyChartVisitList(classifyId, userId)
  150. if err != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "获取用户分类阅读统计失败, Err: " + err.Error()
  153. return
  154. }
  155. br.Ret = 200
  156. br.Success = true
  157. br.Msg = "获取成功"
  158. br.Data = list
  159. }
  160. // GetChartCompanyAuthCensusList
  161. // @Title 获取图库权限开通客户统计列表
  162. // @Description 获取图库权限开通客户统计列表
  163. // @Param SellerId query string false "销售IDs,多个用英文逗号拼接"
  164. // @Param CompanyStatus query string false "图表分类ID,多个用英文逗号拼接"
  165. // @Param Keyword query string false "关键词"
  166. // @Success 200 {object} yb.CompanyAuthCensusPageListResp
  167. // @router /chartCensus/getCompanyAuthCensusList [get]
  168. func (this *ChartCensusController) GetChartCompanyAuthCensusList() {
  169. br := new(models.BaseResponse).Init()
  170. defer func() {
  171. this.Data["json"] = br
  172. this.ServeJSON()
  173. }()
  174. sysUser := this.SysUser
  175. if sysUser == nil {
  176. br.Msg = "请登录"
  177. br.ErrMsg = "请登录,SysUser Is Empty"
  178. br.Ret = 408
  179. return
  180. }
  181. sellerId := this.GetString("SellerId")
  182. companyStatus := this.GetString("CompanyStatus")
  183. keyword := this.GetString("Keyword")
  184. pageSize, _ := this.GetInt("PageSize")
  185. currentIndex, _ := this.GetInt("CurrentIndex")
  186. totalUser, totalItem, list, err := getChartCompanyAuthCensusData(sellerId, companyStatus, keyword, pageSize, currentIndex)
  187. if err != nil {
  188. br.Msg = "获取失败"
  189. br.ErrMsg = "获取图库权限开通客户统计列表-" + err.Error()
  190. return
  191. }
  192. page := paging.GetPaging(currentIndex, pageSize, totalUser)
  193. resp := yb.CompanyAuthCensusPageListResp{
  194. List: list,
  195. Paging: page,
  196. UserTotal: totalUser,
  197. CompanyTotal: totalItem.CountCompany,
  198. }
  199. br.Ret = 200
  200. br.Success = true
  201. br.Msg = "获取成功"
  202. br.Data = resp
  203. }
  204. // ExportChartVisitCensusList
  205. // @Title 导出图表阅读统计列表
  206. // @Description 导出图表阅读统计列表
  207. // @Param ClassifyId query int false "图表分类ID"
  208. // @Success 200 {object} yb.ChartVisitPageListResp
  209. // @router /chartCensus/exportChartVisitCensusList [get]
  210. func (this *ChartCensusController) ExportChartVisitCensusList() {
  211. br := new(models.BaseResponse).Init()
  212. defer func() {
  213. this.Data["json"] = br
  214. this.ServeJSON()
  215. }()
  216. sysUser := this.SysUser
  217. if sysUser == nil {
  218. br.Msg = "请登录"
  219. br.ErrMsg = "请登录,SysUser Is Empty"
  220. br.Ret = 408
  221. return
  222. }
  223. classifyId, _ := this.GetInt("ClassifyId")
  224. order, _ := this.GetInt("Order")
  225. _, list, err := yb.GetChartVisitPageList(classifyId, 0, 100000, order)
  226. if err != nil {
  227. br.Msg = "获取失败"
  228. br.ErrMsg = "获取失败, Err: " + err.Error()
  229. return
  230. }
  231. // 生成excel
  232. dir, err := os.Executable()
  233. exPath := filepath.Dir(dir)
  234. downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  235. xlsxFile := xlsx.NewFile()
  236. if err != nil {
  237. br.Msg = "生成文件失败"
  238. br.ErrMsg = "生成文件失败"
  239. return
  240. }
  241. style := xlsx.NewStyle()
  242. alignment := xlsx.Alignment{
  243. Horizontal: "center",
  244. Vertical: "center",
  245. WrapText: true,
  246. }
  247. style.Alignment = alignment
  248. style.ApplyAlignment = true
  249. sheel, err := xlsxFile.AddSheet("图库阅读统计")
  250. if err != nil {
  251. br.Msg = "新增Sheet失败"
  252. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  253. return
  254. }
  255. titleRow := sheel.AddRow()
  256. titleRow.AddCell().SetValue("图分类")
  257. titleRow.AddCell().SetValue("阅读量")
  258. titleRow.AddCell().SetValue("最近一次阅读时间")
  259. // excel赋值
  260. for _, v := range list {
  261. dataRow := sheel.AddRow()
  262. dataRow.SetHeight(20)
  263. dataRow.AddCell().SetString(v.ClassifyName)
  264. dataRow.AddCell().SetString(strconv.Itoa(v.VisitCount))
  265. dataRow.AddCell().SetString(v.LastVisitTime)
  266. }
  267. // 保存excel
  268. err = xlsxFile.Save(downloadFilePath)
  269. if err != nil {
  270. br.Msg = "保存文件失败"
  271. br.ErrMsg = "保存文件失败"
  272. return
  273. }
  274. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  275. downloadFileName := "图库统计列表_" + randStr + ".xlsx"
  276. this.Ctx.Output.Download(downloadFilePath, downloadFileName)
  277. defer func() {
  278. os.Remove(downloadFilePath)
  279. }()
  280. br.Ret = 200
  281. br.Success = true
  282. br.Msg = "导出成功"
  283. }
  284. // ExportChartVisitDetailCensusList
  285. // @Title 导出图表阅读详情统计列表
  286. // @Description 导出图表阅读详情统计列表
  287. // @Param ClassifyId query int true "图表分类ID"
  288. // @Param SellerId query string false "销售IDs,多个用英文逗号拼接"
  289. // @Param CompanyStatus query string false "图表分类ID,多个用英文逗号拼接"
  290. // @Param Keyword query string false "关键词"
  291. // @Success 200 {object} yb.ChartVisitPageListResp
  292. // @router /chartCensus/exportChartVisitDetailCensusList [get]
  293. func (this *ChartCensusController) ExportChartVisitDetailCensusList() {
  294. br := new(models.BaseResponse).Init()
  295. defer func() {
  296. this.Data["json"] = br
  297. this.ServeJSON()
  298. }()
  299. sysUser := this.SysUser
  300. if sysUser == nil {
  301. br.Msg = "请登录"
  302. br.ErrMsg = "请登录,SysUser Is Empty"
  303. br.Ret = 408
  304. return
  305. }
  306. classifyId, _ := this.GetInt("ClassifyId")
  307. if classifyId <= 0 {
  308. br.Msg = "分类ID有误"
  309. return
  310. }
  311. sellerId := this.GetString("SellerId")
  312. companyStatus := this.GetString("CompanyStatus")
  313. keyword := this.GetString("Keyword")
  314. _, _, list, err := getChartVisitDetailCensusData(classifyId, 0, 100000, 0, sellerId, companyStatus, keyword)
  315. if err != nil {
  316. br.Msg = "获取阅读详情统计失败"
  317. br.Msg = "获取阅读详情统计失败-" + err.Error()
  318. return
  319. }
  320. // 生成excel
  321. dir, err := os.Executable()
  322. exPath := filepath.Dir(dir)
  323. downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  324. xlsxFile := xlsx.NewFile()
  325. if err != nil {
  326. br.Msg = "生成文件失败"
  327. br.ErrMsg = "生成文件失败"
  328. return
  329. }
  330. style := xlsx.NewStyle()
  331. alignment := xlsx.Alignment{
  332. Horizontal: "center",
  333. Vertical: "center",
  334. WrapText: true,
  335. }
  336. style.Alignment = alignment
  337. style.ApplyAlignment = true
  338. sheel, err := xlsxFile.AddSheet("图库阅读统计详情")
  339. if err != nil {
  340. br.Msg = "新增Sheet失败"
  341. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  342. return
  343. }
  344. titleRow := sheel.AddRow()
  345. titleRow.AddCell().SetValue("联系人姓名")
  346. titleRow.AddCell().SetValue("客户名称")
  347. titleRow.AddCell().SetValue("所属销售")
  348. titleRow.AddCell().SetValue("客户状态")
  349. titleRow.AddCell().SetValue("查看明细")
  350. titleRow.AddCell().SetValue("最近一次查看时间")
  351. // excel赋值
  352. for _, v := range list {
  353. dataRow := sheel.AddRow()
  354. dataRow.SetHeight(20)
  355. dataRow.AddCell().SetString(v.UserName)
  356. dataRow.AddCell().SetString(v.CompanyName)
  357. dataRow.AddCell().SetString(v.SellerName)
  358. dataRow.AddCell().SetString(v.CompanyStatus)
  359. dataRow.AddCell().SetString(strconv.Itoa(v.VisitCount))
  360. dataRow.AddCell().SetString(v.LastVisitTime)
  361. }
  362. // 保存excel
  363. err = xlsxFile.Save(downloadFilePath)
  364. if err != nil {
  365. br.Msg = "保存文件失败"
  366. br.ErrMsg = "保存文件失败"
  367. return
  368. }
  369. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  370. downloadFileName := "图库阅读统计详情_" + randStr + ".xlsx"
  371. this.Ctx.Output.Download(downloadFilePath, downloadFileName)
  372. defer func() {
  373. os.Remove(downloadFilePath)
  374. }()
  375. br.Ret = 200
  376. br.Success = true
  377. br.Msg = "导出成功"
  378. }
  379. // ExportChartCompanyAuthCensusList
  380. // @Title 导出图库权限开通客户统计列表
  381. // @Description 导出图库权限开通客户统计列表
  382. // @Param SellerId query string false "销售IDs,多个用英文逗号拼接"
  383. // @Param CompanyStatus query string false "图表分类ID,多个用英文逗号拼接"
  384. // @Param Keyword query string false "关键词"
  385. // @Success 200 string "导出成功"
  386. // @router /chartCensus/exportChartCompanyAuthCensusList [get]
  387. func (this *ChartCensusController) ExportChartCompanyAuthCensusList() {
  388. br := new(models.BaseResponse).Init()
  389. defer func() {
  390. this.Data["json"] = br
  391. this.ServeJSON()
  392. }()
  393. sysUser := this.SysUser
  394. if sysUser == nil {
  395. br.Msg = "请登录"
  396. br.ErrMsg = "请登录,SysUser Is Empty"
  397. br.Ret = 408
  398. return
  399. }
  400. sellerId := this.GetString("SellerId")
  401. companyStatus := this.GetString("CompanyStatus")
  402. keyword := this.GetString("Keyword")
  403. _, _, list, err := getChartCompanyAuthCensusData(sellerId, companyStatus, keyword, 100000, 0)
  404. if err != nil {
  405. br.Msg = "获取失败"
  406. br.ErrMsg = "获取图库权限开通客户统计列表-" + err.Error()
  407. return
  408. }
  409. // 生成excel
  410. dir, err := os.Executable()
  411. exPath := filepath.Dir(dir)
  412. downloadFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  413. xlsxFile := xlsx.NewFile()
  414. if err != nil {
  415. br.Msg = "生成文件失败"
  416. br.ErrMsg = "生成文件失败"
  417. return
  418. }
  419. style := xlsx.NewStyle()
  420. alignment := xlsx.Alignment{
  421. Horizontal: "center",
  422. Vertical: "center",
  423. WrapText: true,
  424. }
  425. style.Alignment = alignment
  426. style.ApplyAlignment = true
  427. sheel, err := xlsxFile.AddSheet("图库权限开通统计")
  428. if err != nil {
  429. br.Msg = "新增Sheet失败"
  430. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  431. return
  432. }
  433. titleRow := sheel.AddRow()
  434. titleRow.AddCell().SetValue("联系人姓名")
  435. titleRow.AddCell().SetValue("客户名称")
  436. titleRow.AddCell().SetValue("所属销售")
  437. titleRow.AddCell().SetValue("客户状态")
  438. titleRow.AddCell().SetValue("图库服务期限")
  439. titleRow.AddCell().SetValue("剩余天数")
  440. // excel赋值
  441. for _, v := range list {
  442. dataRow := sheel.AddRow()
  443. dataRow.SetHeight(20)
  444. dataRow.AddCell().SetString(v.UserName)
  445. dataRow.AddCell().SetString(v.CompanyName)
  446. dataRow.AddCell().SetString(v.SellerName)
  447. dataRow.AddCell().SetString(v.CompanyStatus)
  448. dataRow.AddCell().SetString(v.StartTime + "~" + v.EndTime)
  449. dataRow.AddCell().SetString(strconv.Itoa(v.RestDay))
  450. }
  451. // 保存excel
  452. err = xlsxFile.Save(downloadFilePath)
  453. if err != nil {
  454. br.Msg = "保存文件失败"
  455. br.ErrMsg = "保存文件失败"
  456. return
  457. }
  458. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  459. downloadFileName := "图库权限开通统计_" + randStr + ".xlsx"
  460. this.Ctx.Output.Download(downloadFilePath, downloadFileName)
  461. defer func() {
  462. os.Remove(downloadFilePath)
  463. }()
  464. br.Ret = 200
  465. br.Success = true
  466. br.Msg = "导出成功"
  467. }
  468. // getChartVisitDetailCensusData 图表阅读详情统计数据
  469. func getChartVisitDetailCensusData(classifyId, order, pageSize, currentIndex int, sellerId, companyStatus, keyword string) (totalList, totalClassify int, list []*yb.ChartVisitDetailList, err error) {
  470. // 根据筛选项查询客户列表
  471. var condition string
  472. var pars []interface{}
  473. pars = append(pars, classifyId)
  474. if sellerId != "" {
  475. condition += ` AND p.seller_id IN (` + sellerId + `) `
  476. }
  477. if companyStatus != "" {
  478. statusArr := strings.Split(companyStatus, ",")
  479. var splitArr []string
  480. for _, v := range statusArr {
  481. splitArr = append(splitArr, `"`+v+`"`)
  482. }
  483. queryStatus := strings.Join(splitArr, ",")
  484. condition += ` AND p.status IN (` + queryStatus + `)`
  485. }
  486. if keyword != "" {
  487. keyword = "%" + keyword + "%"
  488. condition += ` AND (l.real_name LIKE ? OR c.company_name LIKE ?) `
  489. pars = append(pars, keyword, keyword)
  490. }
  491. // 分页
  492. var startSize int
  493. if pageSize <= 0 {
  494. pageSize = utils.PageSize20
  495. }
  496. if currentIndex <= 0 {
  497. currentIndex = 1
  498. }
  499. startSize = paging.StartIndex(currentIndex, pageSize)
  500. // 获取统计详情列表
  501. totalList, list, err = yb.GetChartVisitDetailPageList(condition, pars, order, startSize, pageSize)
  502. if err != nil {
  503. err = errors.New("获取统计详情列表失败, Err: " + err.Error())
  504. return
  505. }
  506. totalClassify, err = yb.GetClassifyChartTotalVisit(condition, pars)
  507. if err != nil {
  508. err = errors.New("获取分类阅读总人数失败, Err: " + err.Error())
  509. return
  510. }
  511. return
  512. }
  513. // getChartCompanyAuthCensusData 图库权限开通客户统计数据
  514. func getChartCompanyAuthCensusData(sellerId, companyStatus, keyword string, pageSize, currentIndex int) (totalUser int, totalItem yb.CountCompanyChartAuth, list []*yb.CompanyAuthCensusList, err error) {
  515. // 筛选条件
  516. var condition string
  517. var pars []interface{}
  518. if sellerId != "" {
  519. condition += ` AND d.seller_id IN (` + sellerId + `) `
  520. }
  521. if companyStatus != "" {
  522. statusArr := strings.Split(companyStatus, ",")
  523. var splitArr []string
  524. for _, v := range statusArr {
  525. splitArr = append(splitArr, `"`+v+`"`)
  526. }
  527. queryStatus := strings.Join(splitArr, ",")
  528. condition += ` AND d.status IN (` + queryStatus + `)`
  529. }
  530. if keyword != "" {
  531. keyword = "%" + keyword + "%"
  532. condition += ` AND b.real_name LIKE ? OR c.company_name LIKE ? `
  533. pars = append(pars, keyword, keyword)
  534. }
  535. // 分页
  536. var startSize int
  537. if pageSize <= 0 {
  538. pageSize = utils.PageSize20
  539. }
  540. if currentIndex <= 0 {
  541. currentIndex = 1
  542. }
  543. startSize = paging.StartIndex(currentIndex, pageSize)
  544. // 获取图库权限开通统计列表
  545. totalUser, list, err = yb.GetCompanyAuthCensusPageList(condition, pars, startSize, pageSize)
  546. if err != nil {
  547. err = errors.New("获取统计详情列表失败, Err: " + err.Error())
  548. return
  549. }
  550. totalItem, err = yb.GetCompanyAuthTotal(condition, pars)
  551. if err != nil {
  552. err = errors.New("获取分类阅读总人数失败, Err: " + err.Error())
  553. return
  554. }
  555. if len(list) > 0 {
  556. // 计算剩余天数
  557. for _, item := range list {
  558. startTime, timeErr := time.ParseInLocation(utils.FormatDateTime, item.StartTime, time.Local)
  559. if timeErr != nil {
  560. err = errors.New("开始时间转换失败, Err: " + timeErr.Error())
  561. return
  562. }
  563. endTime, timeErr := time.ParseInLocation(utils.FormatDateTime, item.EndTime, time.Local)
  564. if timeErr != nil {
  565. err = errors.New("结束时间转换失败, Err: " + timeErr.Error())
  566. return
  567. }
  568. diff := endTime.Sub(startTime) + 1
  569. item.StartTime = startTime.Format(utils.FormatDate)
  570. item.EndTime = endTime.Format(utils.FormatDate)
  571. item.RestDay = int(diff.Hours() / 24)
  572. }
  573. }
  574. return
  575. }