yb_common.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/models/tables/company_product"
  5. "hongze/hongze_yb/models/tables/rddp/report"
  6. "hongze/hongze_yb/models/tables/rddp/report_chapter"
  7. "hongze/hongze_yb/models/tables/research_report_type"
  8. "hongze/hongze_yb/models/tables/yb_like"
  9. "hongze/hongze_yb/services/user"
  10. "hongze/hongze_yb/utils"
  11. "strings"
  12. )
  13. // GetReportIdReportChapterIdByOldReportId 根据老报告的ID查询对应的新报告ID
  14. func GetReportIdReportChapterIdByOldReportId(oldReportId, oldReportChapterId uint64) (reportId int, reportChapterId int, err error, errMsg string) {
  15. var reportNew *report.Report
  16. if oldReportChapterId >0 {
  17. //查询章节详情,根据章节类型ID和老报告ID,根据老报告ID,查询新报告ID,根据新报告ID和type_id 找到新的章节ID
  18. var oldReportChapter *research_report_type.ResearchReportTypeInfo
  19. var reportChapterNew *report_chapter.ReportChapter
  20. oldReportChapter, err = research_report_type.GetResearchReportTypeInfo(oldReportChapterId)
  21. if err != nil {
  22. errMsg = err.Error()
  23. err = errors.New("找不到报告章节")
  24. return
  25. }
  26. if oldReportChapter == nil {
  27. err = errors.New("找不到报告章节")
  28. return
  29. }
  30. if oldReportId != oldReportChapter.ResearchReportID {
  31. err = errors.New("报告ID和章节ID不一致")
  32. return
  33. }
  34. //判断是否是晨报或者周报的章节ID,双周报的章节ID不记录
  35. if oldReportChapter.TypeID == 0 {
  36. err = errors.New("只允许传晨报和周报的章节ID")
  37. return
  38. }
  39. reportNew, err = report.GetReportByOldReportId(oldReportChapter.ResearchReportID)
  40. if err != nil {
  41. errMsg = err.Error()
  42. //err = errors.New("找不到新版报告")
  43. return
  44. }
  45. if reportNew.Id <=0 {
  46. //err = errors.New("找不到新版报告")
  47. return
  48. }
  49. reportChapterNew, err = report_chapter.GetChapterByReportIdTypeId(reportNew.Id, oldReportChapter.TypeID)
  50. if err != nil {
  51. errMsg = err.Error()
  52. return
  53. }
  54. if reportChapterNew.ReportChapterId <= 0 {
  55. //err = errors.New("找不到新版章节")
  56. return
  57. }
  58. reportId = reportNew.Id
  59. reportChapterId = reportChapterNew.ReportChapterId
  60. return
  61. }else if oldReportId > 0 {
  62. // 查询新报告ID
  63. reportNew, err = report.GetReportByOldReportId(oldReportId)
  64. if err != nil {
  65. errMsg = err.Error()
  66. //err = errors.New("找不到新版报告")
  67. return
  68. }
  69. reportId = reportNew.Id
  70. return
  71. }
  72. return
  73. }
  74. // CheckReportExistByReportIdReportChapterId 评论和点赞时,校验传入的报告ID是否正确
  75. func CheckReportExistByReportIdReportChapterId(reportId, reportChapterId int)(err error, errMsg string) {
  76. reportInfo, err := report.GetByReportId(reportId)
  77. if err != nil {
  78. errMsg = err.Error()
  79. err = errors.New("查询报告出错")
  80. return
  81. }
  82. if reportInfo.Id <=0 {
  83. err = errors.New("报告不存在")
  84. return
  85. }
  86. if (reportInfo.ClassifyNameFirst == "晨报" || reportInfo.ClassifyNameFirst == "周报") && reportChapterId <=0 {
  87. err = errors.New("请输入报告章节ID")
  88. return
  89. }
  90. if reportChapterId > 0 {
  91. reportChapterInfo, tErr := report_chapter.GetTypeIdById(reportChapterId)
  92. if tErr != nil {
  93. errMsg = tErr.Error()
  94. err = errors.New("查询章节失败")
  95. return
  96. }
  97. if reportChapterInfo.ReportChapterId == 0 {
  98. err = errors.New("章节不存在或者未发布")
  99. return
  100. }
  101. if reportChapterInfo.ReportId != reportId {
  102. err = errors.New("章节ID和报告ID不匹配")
  103. return
  104. }
  105. }
  106. return
  107. }
  108. // CheckSimpleCompanyProduct 校验用户是否FICC产品的已购或者试用状态
  109. func CheckSimpleCompanyProduct(userinfo user.UserInfo) (err error, errMsg string){
  110. // 判断用户状态是否是正常和永续
  111. var productAuthOk bool
  112. companyProduct, err := company_product.GetByCompany2ProductId(userinfo.CompanyID, 1)
  113. if err == utils.ErrNoRow {
  114. err = nil
  115. }
  116. if err != nil {
  117. errMsg = err.Error()
  118. err = errors.New("查询用户购买产品出错")
  119. return
  120. }
  121. if companyProduct != nil {
  122. // 无FICC权限的客户不可见
  123. if companyProduct.CompanyProductID > 0 {
  124. // 已购或者试用用户可见
  125. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  126. productAuthOk = true
  127. }
  128. }
  129. }
  130. if !productAuthOk {
  131. err = errors.New("无权操作")
  132. return
  133. }
  134. return
  135. }
  136. func GetReportLikeByReportIdOldReportId(userId uint64,reportId, reportChapterId int, oldReportId, oldReportChapterId int) (likeNum int64, likeEnabled int8, err error) {
  137. // 根据老报告找到新报告的ID
  138. if reportId == 0 && oldReportId > 0{
  139. reportId, reportChapterId, err, _ = GetReportIdReportChapterIdByOldReportId(uint64(oldReportId), uint64(oldReportChapterId))
  140. }
  141. //查询总的点赞数
  142. if reportId > 0{
  143. likeNum, err = yb_like.GetLikeNumByReportId(reportId, reportChapterId)
  144. } else if oldReportId > 0{
  145. likeNum, err = yb_like.GetLikeNumByOldReportId(oldReportId, oldReportChapterId)
  146. }
  147. if err != nil {
  148. err = errors.New("查询点赞数出错")
  149. return
  150. }
  151. //查询用户对研报的点赞状态
  152. var likeItem *yb_like.YbLike
  153. if reportId > 0 {
  154. likeItem, err = yb_like.GetLikeByUserIdAndReportId(userId, reportId, reportChapterId)
  155. } else {
  156. likeItem, err = yb_like.GetLikeByUserIdAndOldReportId(userId, oldReportId, oldReportChapterId)
  157. }
  158. if err != nil {
  159. err = errors.New("查询用户点赞记录出错")
  160. return
  161. }
  162. likeEnabled = likeItem.Enabled
  163. return
  164. }