report.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. package logic
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/common"
  6. reportResp "hongze/hongze_open_api/models/response/report"
  7. "hongze/hongze_open_api/models/tables/chart_permission"
  8. "hongze/hongze_open_api/models/tables/chart_permission_chapter_mapping"
  9. "hongze/hongze_open_api/models/tables/chart_permission_search_key_word_mapping"
  10. "hongze/hongze_open_api/models/tables/company_product"
  11. "hongze/hongze_open_api/models/tables/company_report_permission"
  12. "hongze/hongze_open_api/models/tables/rddp/classify"
  13. "hongze/hongze_open_api/models/tables/rddp/report"
  14. "hongze/hongze_open_api/models/tables/rddp/report_chapter"
  15. "hongze/hongze_open_api/models/tables/report_chapter_type"
  16. "hongze/hongze_open_api/models/tables/wx_user"
  17. "hongze/hongze_open_api/services/company"
  18. "hongze/hongze_open_api/utils"
  19. "html"
  20. "net/url"
  21. "sort"
  22. "strconv"
  23. "strings"
  24. "time"
  25. )
  26. // GetReportList 获取报告列表
  27. func GetReportList(classifyId int, mobile, keyword string, startSize, pageSize int) (total int, list []*report.ReportList, err error, errMsg string) {
  28. //加密后的手机号
  29. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  30. errMsg = `获取失败`
  31. // 获取用户信息
  32. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  33. if err != nil {
  34. errMsg = "获取用户信息失败"
  35. return
  36. }
  37. productId := 1
  38. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  39. if err != nil {
  40. errMsg = "获取客户信息失败"
  41. return
  42. }
  43. //`is_suspend` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1:暂停,0:启用',
  44. if companyProduct.IsSuspend != 0 {
  45. errMsg = "客户状态异常"
  46. return
  47. }
  48. permissionList, err := company_report_permission.GetPermissionListByCompanyIdAndProductId(userInfo.CompanyId, productId)
  49. if err != nil {
  50. errMsg = "获取客户品种失败"
  51. return
  52. }
  53. if len(permissionList) == 0 {
  54. errMsg = "客户品种异常"
  55. return
  56. }
  57. //客户品种id列表
  58. permissionIdList := make([]int, 0)
  59. for _, v := range permissionList {
  60. permissionIdList = append(permissionIdList, v.ChartPermissionId)
  61. }
  62. // 获取分类信息
  63. classifyInfo, err := classify.GetClassify(classifyId)
  64. if err != nil {
  65. errMsg = "获取分类信息失败"
  66. return
  67. }
  68. var firstClassifyId, secondClassifyId int
  69. firstClassifyId = classifyInfo.ParentId
  70. secondClassifyId = classifyInfo.Id
  71. if classifyInfo.ParentId <= 0 {
  72. firstClassifyId = classifyInfo.Id
  73. secondClassifyId = 0
  74. }
  75. var condition string
  76. var pars []interface{}
  77. // 分类
  78. condition = ` AND state = 2 AND classify_id_first = ? AND classify_id_second = ? `
  79. pars = append(pars, firstClassifyId, secondClassifyId)
  80. //报告名称
  81. if keyword != "" {
  82. condition += ` AND title LIKE ? `
  83. pars = append(pars, `%`+keyword+`%`)
  84. }
  85. total, list, err = report.GetReportList(condition, pars, startSize, pageSize)
  86. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  87. nonceStr := common.GetRandString(10)
  88. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  89. for _, v := range list {
  90. if v.Stage > 0 {
  91. v.Title = fmt.Sprintf("【第%d期】%s", v.Stage, v.Title)
  92. }
  93. v.Title = fmt.Sprintf("%s(%s)", v.Title, v.CreateTime.Format(utils.FormatMonthDate))
  94. //跳转地址
  95. postData := make(map[string]string)
  96. reportId := strconv.Itoa(v.Id)
  97. parameter := "mobile=" + encryptMobile + "&report_id=" + reportId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  98. postData["mobile"] = encryptMobile
  99. postData["report_id"] = reportId
  100. postData["appid"] = utils.ReportAppid
  101. postData["nonce_str"] = nonceStr
  102. postData["timestamp"] = timeUnix
  103. sign := utils.GetSign(postData)
  104. v.HttpUrl = utils.ResearchReportUrl + "hzsl/report/new/detail?" + parameter + "&sign=" + sign
  105. }
  106. return
  107. }
  108. // GetReportDetail 获取报告详情
  109. func GetReportDetail(reportId int, mobile string) (reportDetail reportResp.ReportDetail, err error, errMsg string) {
  110. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  111. errMsg = `获取失败`
  112. // 获取用户信息
  113. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  114. if err != nil {
  115. errMsg = "获取用户信息失败"
  116. return
  117. }
  118. // 判断用户状态是否是正常和永续
  119. var productAuthOk bool
  120. productId := 1
  121. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  122. if err != nil {
  123. if err.Error() == utils.ErrNoRow() {
  124. err = nil
  125. } else {
  126. errMsg = err.Error()
  127. err = errors.New("查询用户购买产品出错")
  128. return
  129. }
  130. }
  131. if companyProduct != nil {
  132. // 无FICC权限的客户不可见
  133. if companyProduct.CompanyProductId > 0 {
  134. // 已购或者试用用户可见
  135. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  136. productAuthOk = true
  137. }
  138. }
  139. }
  140. reportInfo, err := report.GetById(reportId)
  141. if err != nil {
  142. errMsg = "获取报告失败"
  143. return
  144. }
  145. // `state` tinyint(2) DEFAULT '1' COMMENT '1:未发布,2:已发布',
  146. if reportInfo.State != 2 {
  147. errMsg = "报告未发布"
  148. err = errors.New("报告未发布")
  149. return
  150. }
  151. // 判断报告是否属于专栏报告
  152. firstClassify, e := classify.GetClassify(reportInfo.ClassifyIdFirst)
  153. if e != nil {
  154. errMsg = "报告异常"
  155. err = errors.New("报告一级分类有误")
  156. return
  157. }
  158. if firstClassify.IsShow != 1 {
  159. errMsg = "报告异常"
  160. err = errors.New("报告一级分类未发布")
  161. return
  162. }
  163. var authOk bool
  164. var permissionCheckInfo reportResp.PermissionCheckInfo
  165. var vaildWeekTypeIds []int
  166. if reportInfo.ClassifyNameFirst == "晨报" {
  167. authOk, permissionCheckInfo, err = CheckDayReportPermission(userInfo, productAuthOk)
  168. } else if reportInfo.ClassifyNameFirst == "周报" {
  169. authOk, permissionCheckInfo, vaildWeekTypeIds, err = CheckWeekReportPermission(userInfo, productAuthOk)
  170. } else {
  171. authOk, permissionCheckInfo, err = CheckReportPermission(userInfo, reportId, productAuthOk)
  172. }
  173. if err != nil {
  174. return
  175. }
  176. reportItem := reportResp.ReportItem{
  177. ReportId: reportInfo.Id,
  178. ClassifyNameFirst: reportInfo.ClassifyNameFirst,
  179. ClassifyNameSecond: reportInfo.ClassifyNameSecond,
  180. Title: reportInfo.Title,
  181. Abstract: reportInfo.Abstract,
  182. Author: reportInfo.Author,
  183. Frequency: reportInfo.Frequency,
  184. PublishTime: reportInfo.PublishTime,
  185. Stage: reportInfo.Stage,
  186. Content: html.UnescapeString(reportInfo.ContentSub),
  187. VideoUrl: "",
  188. VideoName: reportInfo.VideoName,
  189. VideoSize: reportInfo.VideoSize,
  190. VideoPlaySeconds: reportInfo.VideoPlaySeconds,
  191. VideoImg: "",
  192. ContentSub: "",
  193. BannerUrl: "",
  194. }
  195. if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
  196. reportItem.VideoName = reportInfo.Title
  197. }
  198. var reportTypeList []*reportResp.ReportChapterListItem
  199. if reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报" {
  200. //(晨报和周报的banner图)
  201. if reportInfo.ClassifyNameFirst == "晨报" {
  202. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  203. } else {
  204. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_week.jpg"
  205. }
  206. if authOk {
  207. reportTypeList, err, errMsg = GetChapterListByReport(reportInfo.ClassifyNameFirst, reportInfo.Id, vaildWeekTypeIds, reportInfo.CreateTime)
  208. if err != nil {
  209. return
  210. }
  211. }
  212. } else {
  213. // 音频播放条图片用分类图片
  214. reportItem.VideoImg = utils.HZ_DEFAULT_AVATAR
  215. permissionIds, tmpErr := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(reportItem.ClassifyNameSecond)
  216. if tmpErr != nil {
  217. errMsg = tmpErr.Error()
  218. err = errors.New("查询报告权限失败")
  219. return
  220. }
  221. if len(permissionIds) > 0 {
  222. chartPermission, tmpErr := chart_permission.GetListByIds(permissionIds)
  223. if tmpErr != nil {
  224. errMsg = tmpErr.Error()
  225. err = errors.New("查询品种信息失败")
  226. return
  227. }
  228. lenChart := len(chartPermission)
  229. for i := 0; i < lenChart; i++ {
  230. if chartPermission[i].YbImgUrl != "" {
  231. reportItem.VideoImg = utils.ALIYUN_YBIMG_HOST + chartPermission[i].YbImgUrl
  232. break
  233. }
  234. }
  235. }
  236. }
  237. //如果有权限则展示content
  238. //var likeNum int64
  239. //var likeEnabled int8
  240. if authOk {
  241. //go AddViewRecord(userinfo, reportInfo.Id, reportInfo.ClassifyNameFirst, 0)
  242. reportItem.Content = html.UnescapeString(reportInfo.Content)
  243. reportItem.VideoUrl = reportInfo.VideoUrl
  244. //查询点赞数
  245. //likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(userinfo.UserID, reportInfo.Id, 0,0,0)
  246. }
  247. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  248. nonceStr := common.GetRandString(10)
  249. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  250. for _, v := range reportTypeList {
  251. //跳转地址
  252. postData := make(map[string]string)
  253. reportChapterId := strconv.Itoa(v.ReportChapterId)
  254. parameter := "mobile=" + encryptMobile + "&report_chapter_id=" + reportChapterId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  255. postData["mobile"] = encryptMobile
  256. postData["report_chapter_id"] = reportChapterId
  257. postData["appid"] = utils.ReportAppid
  258. postData["nonce_str"] = nonceStr
  259. postData["timestamp"] = timeUnix
  260. sign := utils.GetSign(postData)
  261. v.HttpUrl = utils.ResearchReportUrl + "hzsl/report/new/chapter/detail?" + parameter + "&sign=" + sign
  262. }
  263. reportDetail.ReportInfo = reportItem
  264. reportDetail.ReportChapterList = reportTypeList
  265. reportDetail.PermissionCheck = permissionCheckInfo
  266. reportDetail.AuthOk = authOk
  267. //reportDetail.LikeNum = likeNum
  268. //reportDetail.LikeEnabled = likeEnabled
  269. reportDetail.ReportShowType = firstClassify.ShowType
  270. return
  271. }
  272. // GetChapterListByReport 根据报告获取章节列表
  273. func GetChapterListByReport(classifyNameFirst string, reportId int, validWeekTypeIds []int, reportCreateTime time.Time) (reportTypeList reportResp.ReportChapterList, err error, errMsg string) {
  274. defer func() {
  275. if err != nil {
  276. utils.FileLog.Critical(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg))
  277. }
  278. }()
  279. //查询有效的章节
  280. typeList, err := report_chapter_type.GetEffectTypes()
  281. if err != nil {
  282. errMsg = "章节类型查询出错"
  283. return
  284. }
  285. if len(typeList) == 0 {
  286. errMsg = "无有效的章节"
  287. err = errors.New("无有效的章节")
  288. return
  289. }
  290. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  291. var typeIds []int
  292. newTypeMap := make(map[int]bool)
  293. for _, v := range typeList {
  294. typeMap[v.ReportChapterTypeId] = v
  295. typeIds = append(typeIds, int(v.ReportChapterTypeId))
  296. }
  297. if classifyNameFirst == "周报" {
  298. for _, v := range validWeekTypeIds {
  299. newTypeMap[v] = true
  300. }
  301. }
  302. //获取所有当前研报的章节
  303. chapterList, err := report_chapter.GetListByReportId(reportId, classifyNameFirst)
  304. if err != nil {
  305. errMsg = "章节查询出错"
  306. return
  307. }
  308. if len(chapterList) == 0 {
  309. errMsg = "无有效章节"
  310. err = errors.New("无有效章节")
  311. return
  312. }
  313. for _, item := range chapterList {
  314. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  315. // 如果是周报只展示有权限的章节
  316. if classifyNameFirst == "周报" {
  317. if _, ok1 := newTypeMap[item.TypeId]; !ok1 {
  318. continue
  319. }
  320. }
  321. temp := new(reportResp.ReportChapterListItem)
  322. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  323. temp.ReportChapterId = item.ReportChapterId
  324. temp.TypeId = item.TypeId
  325. temp.TypeName = item.TypeName
  326. temp.Title = item.Title
  327. temp.Trend = item.Trend
  328. temp.ReportId = item.ReportId
  329. temp.Sort = typeItem.Sort
  330. temp.PublishTime = item.PublishTime
  331. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  332. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  333. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  334. reportTypeList = append(reportTypeList, temp)
  335. }
  336. }
  337. }
  338. if len(reportTypeList) > 0 {
  339. sort.Sort(reportTypeList)
  340. }
  341. return
  342. }
  343. // GetChapterDetail 获取章节详情
  344. func GetChapterDetail(mobile string, reportChapterId int) (reportChapterDetail reportResp.ReportChapterDetail, err error, errMsg string) {
  345. defer func() {
  346. if err != nil {
  347. utils.FileLog.Critical(fmt.Sprintf("GetChapterDetail: mobile=%s, err:%s, errMsg:%s", mobile, err.Error(), errMsg))
  348. }
  349. }()
  350. encryptMobile := string(utils.DesBase64Encrypt([]byte(mobile)))
  351. errMsg = `获取失败`
  352. // 获取用户信息
  353. userInfo, err := wx_user.GetWxUserByMobileCountryCode(mobile, "86")
  354. if err != nil {
  355. errMsg = "获取用户信息失败"
  356. return
  357. }
  358. var authOk bool
  359. var productAuthOk bool
  360. var chapterAuthOk bool
  361. var permissionCheckInfo reportResp.PermissionCheckInfo
  362. //查询客户信息(判断客户状态是否是正常和永续)
  363. productId := 1
  364. companyProduct, err := company_product.GetCompanyProductByCompanyIdAndProductId(userInfo.CompanyId, productId)
  365. if err != nil {
  366. if err.Error() == utils.ErrNoRow() {
  367. err = nil
  368. } else {
  369. errMsg = err.Error()
  370. err = errors.New("查询用户购买产品出错")
  371. return
  372. }
  373. }
  374. if companyProduct != nil {
  375. // 无FICC权限的客户不可见
  376. if companyProduct.CompanyProductId > 0 {
  377. // 已购或者试用用户可见
  378. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  379. productAuthOk = true
  380. }
  381. }
  382. }
  383. //章节分类
  384. typeIds, err := report_chapter_type.GetEffectTypeID()
  385. if err != nil {
  386. errMsg = err.Error()
  387. err = errors.New("章节类型查询出错")
  388. return
  389. }
  390. if len(typeIds) == 0 {
  391. err = errors.New("无有效的章节类型")
  392. return
  393. }
  394. reportChapter, err := report_chapter.GetContentById(reportChapterId, typeIds)
  395. if err != nil {
  396. errMsg = err.Error()
  397. err = errors.New("章节查询出错")
  398. return
  399. }
  400. if reportChapter.ReportChapterId == 0 {
  401. err = errors.New("章节不存在")
  402. return
  403. }
  404. //报告信息
  405. reportInfo, tErr := report.GetById(reportChapter.ReportId)
  406. if tErr != nil {
  407. errMsg = tErr.Error()
  408. err = errors.New("报告查询出错")
  409. return
  410. }
  411. if reportInfo.Id == 0 {
  412. err = errors.New("报告不存在")
  413. return
  414. }
  415. if reportInfo.ClassifyNameFirst == "周报" && reportChapter.IsEdit != 1 {
  416. err = errors.New("章节未编辑")
  417. return
  418. }
  419. //判断权限
  420. var reportChapterTypeIds []int
  421. if reportInfo.ClassifyNameFirst == "晨报" {
  422. authOk, permissionCheckInfo, err = CheckDayReportPermission(userInfo, productAuthOk)
  423. if err != nil && err.Error() != utils.ErrNoRow() {
  424. errMsg = err.Error()
  425. err = errors.New("权限查询出错")
  426. return
  427. }
  428. } else if reportInfo.ClassifyNameFirst == "周报" {
  429. authOk, permissionCheckInfo, reportChapterTypeIds, err = CheckWeekReportPermission(userInfo, productAuthOk)
  430. if err != nil && err.Error() != utils.ErrNoRow() {
  431. errMsg = err.Error()
  432. err = errors.New("权限查询出错")
  433. return
  434. }
  435. for _, v := range reportChapterTypeIds {
  436. if v == reportChapter.TypeId {
  437. chapterAuthOk = true
  438. }
  439. }
  440. authOk = chapterAuthOk
  441. }
  442. videoImgMap := map[string]string{
  443. "day": "report_list_chen.png",
  444. "week": "report_list_zhou.png",
  445. }
  446. reportChapterItem := reportResp.ReportChapterItem{
  447. ReportChapterId: reportChapter.ReportChapterId,
  448. ReportId: reportChapter.ReportId,
  449. Title: reportChapter.Title,
  450. Abstract: reportChapter.Abstract,
  451. TypeId: reportChapter.TypeId,
  452. TypeName: reportChapter.TypeName,
  453. Trend: "",
  454. ReportChapterTypeName: "",
  455. PublishTime: reportChapter.PublishTime,
  456. Content: "",
  457. ContentSub: html.UnescapeString(reportChapter.ContentSub),
  458. VideoUrl: "",
  459. VideoName: reportChapter.VideoName,
  460. VideoPlaySeconds: reportChapter.VideoPlaySeconds,
  461. VideoSize: reportChapter.VideoSize,
  462. VideoImg: utils.ALIYUN_YBIMG_HOST + videoImgMap[reportChapter.ReportType],
  463. Author: reportChapter.Author,
  464. Stage: reportChapter.Stage,
  465. ClassifyIdFirst: reportChapter.ClassifyIdFirst,
  466. ClassifyNameFirst: reportChapter.ClassifyNameFirst,
  467. }
  468. if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
  469. reportChapterItem.VideoName = reportChapter.Title
  470. }
  471. //var likeNum int64
  472. //var likeEnabled int8
  473. //底部菜单切换
  474. var chapterMenu []reportResp.ReportChapterMenu
  475. if authOk {
  476. reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
  477. reportChapterItem.VideoUrl = reportChapter.VideoUrl
  478. //底部菜单切换
  479. if reportInfo.ClassifyNameFirst == "周报" {
  480. chapterMenu, err = GetMenuChapter(reportInfo.Id, reportChapterTypeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime, encryptMobile)
  481. } else {
  482. chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime, encryptMobile)
  483. }
  484. //查询点赞数
  485. //likeNum,likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId,0,0)
  486. //go AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
  487. } else {
  488. reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
  489. }
  490. reportChapterDetail = reportResp.ReportChapterDetail{
  491. ReportChapterItem: reportChapterItem,
  492. ReportChapterMenuList: chapterMenu,
  493. AuthOk: authOk,
  494. PermissionCheck: permissionCheckInfo,
  495. //LikeNum: 0,
  496. //LikeEnabled: 0,
  497. }
  498. //reportChapterDetail.PermissionCheck = &permissionCheckInfo
  499. //reportChapterDetail.LikeNum = likeNum
  500. //reportChapterDetail.LikeEnabled = likeEnabled
  501. return
  502. }
  503. // GetMenuChapter 获取章节下面的菜单
  504. func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string, reportCreateTime time.Time, encryptMobile string) (reportTypeList reportResp.ReportChapterMenuList, err error) {
  505. //查询有效的章节
  506. typeList, tErr := report_chapter_type.GetEffectTypes()
  507. if tErr != nil {
  508. return
  509. }
  510. if len(typeList) == 0 {
  511. err = errors.New("无有效的章节")
  512. return
  513. }
  514. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  515. for _, v := range typeList {
  516. typeMap[v.ReportChapterTypeId] = v
  517. }
  518. //获取所有当前研报的章节
  519. chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
  520. if tErr != nil {
  521. return
  522. }
  523. encryptMobile = url.QueryEscape(encryptMobile) //转义 +
  524. nonceStr := common.GetRandString(10)
  525. timeUnix := strconv.FormatInt(time.Now().Unix(), 10)
  526. if len(chapterList) > 0 {
  527. for _, item := range chapterList {
  528. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  529. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  530. //typeItem.ReportChapterTypeId
  531. //跳转地址
  532. postData := make(map[string]string)
  533. reportChapterId := strconv.Itoa(item.ReportChapterId)
  534. parameter := "mobile=" + encryptMobile + "&report_chapter_id=" + reportChapterId + "&nonce_str=" + nonceStr + "&timestamp=" + timeUnix
  535. postData["mobile"] = encryptMobile
  536. postData["report_chapter_id"] = reportChapterId
  537. postData["appid"] = utils.ReportAppid
  538. postData["nonce_str"] = nonceStr
  539. postData["timestamp"] = timeUnix
  540. sign := utils.GetSign(postData)
  541. temp := reportResp.ReportChapterMenu{
  542. ReportChapterId: item.ReportChapterId,
  543. ReportId: item.ReportId,
  544. ReportChapterTypeName: typeItem.ReportChapterTypeName,
  545. ReportChapterTypeThumb: typeItem.YbBottomIcon,
  546. PcSelectedThumb: typeItem.PcSelectedImage,
  547. PcUnselectedThumb: typeItem.PcUnselectedImage,
  548. Sort: typeItem.Sort,
  549. HttpUrl: utils.ResearchReportUrl + "hzsl/report/new/chapter/detail?" + parameter + "&sign=" + sign,
  550. }
  551. reportTypeList = append(reportTypeList, temp)
  552. }
  553. }
  554. }
  555. }
  556. if len(reportTypeList) > 0 {
  557. sort.Sort(reportTypeList)
  558. }
  559. return
  560. }
  561. // CheckDayReportPermission 验证晨报的权限
  562. func CheckDayReportPermission(userInfo *wx_user.WxUser, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, err error) {
  563. if productAuthOk {
  564. authOk = true
  565. return
  566. }
  567. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), []int{})
  568. return
  569. }
  570. // CheckWeekReportPermission 验证周报的权限
  571. func CheckWeekReportPermission(userInfo *wx_user.WxUser, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, validTypeIds []int, err error) {
  572. var permissionIds []int
  573. var validPermissionIds []int //最后允许显示的章节
  574. if productAuthOk {
  575. permissionIds, err = chart_permission_chapter_mapping.GetPermissionIdsByWeek()
  576. if err != nil && err.Error() != utils.ErrNoRow() {
  577. return
  578. }
  579. }
  580. authOk, permissionCheckInfo, validPermissionIds, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), permissionIds)
  581. if err != nil {
  582. return
  583. }
  584. //返回可用的章节列表
  585. if len(validPermissionIds) > 0 {
  586. validTypeIds, err = chart_permission_chapter_mapping.GetReportChapterTypeIdsByPermissionIds(validPermissionIds, "week")
  587. }
  588. return
  589. }
  590. // CheckReportPermission 验证用户查看报告的权限
  591. func CheckReportPermission(userInfo *wx_user.WxUser, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo reportResp.PermissionCheckInfo, err error) {
  592. var permissionIds []int
  593. if productAuthOk {
  594. permissionIds, err = chart_permission_chapter_mapping.GetPermissionIdsByReportId(reportId, "rddp")
  595. if err != nil && err.Error() != utils.ErrNoRow() {
  596. return
  597. }
  598. }
  599. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyId, int(userInfo.UserId), permissionIds)
  600. return
  601. }