article.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/PuerkitoBio/goquery"
  6. "hongze/hongze_mfyx/models"
  7. "hongze/hongze_mfyx/utils"
  8. "html"
  9. "regexp"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. )
  14. func GetReportContentTextSub(content string) (contentSub string, err error) {
  15. content = html.UnescapeString(content)
  16. doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
  17. docText := doc.Text()
  18. bodyRune := []rune(docText)
  19. bodyRuneLen := len(bodyRune)
  20. if bodyRuneLen > 200 {
  21. bodyRuneLen = 200
  22. }
  23. body := string(bodyRune[:bodyRuneLen])
  24. contentSub = body
  25. contentSub = strings.Replace(body, "Powered by Froala Editor", "", -1)
  26. return
  27. }
  28. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  29. content = html.UnescapeString(content)
  30. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
  31. if errdoc != nil {
  32. err = errdoc
  33. return
  34. }
  35. docText := doc.Text()
  36. bodyRune := []rune(docText)
  37. bodyRuneLen := len(bodyRune)
  38. body := string(bodyRune[:bodyRuneLen])
  39. contentSub = body
  40. contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
  41. contentSub = strings.Replace(contentSub, " ", "", -1)
  42. contentSub = strings.Replace(contentSub, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sanered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  43. return
  44. }
  45. func FixArticleImgUrl(body string) (contentSub string, err error) {
  46. r := strings.NewReader(string(body))
  47. doc, err := goquery.NewDocumentFromReader(r)
  48. if err != nil {
  49. fmt.Println(err)
  50. }
  51. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  52. src, _ := s.Attr("src")
  53. if i == 0 && src != "" {
  54. contentSub = src
  55. }
  56. })
  57. return
  58. }
  59. // UserViewRedisData 阅读数据
  60. type UserViewRedisData struct {
  61. Mobile string `json:"mobile"`
  62. Email string `json:"email"`
  63. RealName string `json:"real_name"`
  64. CompanyName string `json:"company_name"`
  65. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  66. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  67. CompanyId int `json:"company_id" description:"客户id"`
  68. UserId int `json:"user_id" description:"用户id"`
  69. ReportId int `json:"report_id" description:"报告id"`
  70. StopTime int `json:"stop_time" description:"停留时间"`
  71. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  72. OutId int `json:"out_id" description:"记录ID"`
  73. }
  74. type ReportViewRecord struct {
  75. Id int `orm:"column(id);pk"`
  76. //UserId int `json:"user_id" description:"用户ID"`
  77. //ReportId int `description:"报告id"`
  78. //Mobile string `description:"手机号"`
  79. //Email string `description:"邮箱"`
  80. //RealName string `description:"用户实际姓名"`
  81. //CompanyName string `description:"公司名称"`
  82. //CreateTime time.Time `description:"创建时间"`
  83. //StopTime int `json:"stop_time" description:"停留时间"`
  84. //ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  85. //OutId int `json:"out_id" description:"记录ID"`
  86. Mobile string `json:"mobile"`
  87. Email string `json:"email"`
  88. RealName string `json:"real_name"`
  89. CompanyName string `json:"company_name"`
  90. ViewTime string `json:"view_time" description:"阅读时间,格式:2022-02-17 13:06:13"`
  91. ProductId int `json:"product_id" description:"报告所属产品,ficc:1,权益:2"`
  92. CompanyId int `json:"company_id" description:"客户id"`
  93. UserId int `json:"user_id" description:"用户id"`
  94. ReportId int `json:"report_id" description:"报告id"`
  95. StopTime int `json:"stop_time" description:"停留时间"`
  96. ReportChapterId int `json:"report_chapter_id" description:"章节ID"`
  97. OutId int `json:"out_id" description:"章节ID"`
  98. }
  99. // PushViewRecordNewRedisData 阅读数据加入到redis
  100. func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId int) bool {
  101. data := &UserViewRedisData{
  102. Mobile: reportViewRecord.Mobile,
  103. UserId: reportViewRecord.UserId,
  104. Email: reportViewRecord.Email,
  105. RealName: reportViewRecord.RealName,
  106. CompanyName: reportViewRecord.CompanyName,
  107. ViewTime: reportViewRecord.ViewTime,
  108. ProductId: 2,
  109. CompanyId: companyId,
  110. ReportId: reportViewRecord.ReportId,
  111. StopTime: reportViewRecord.StopTime,
  112. ReportChapterId: reportViewRecord.ReportChapterId,
  113. OutId: reportViewRecord.OutId,
  114. }
  115. if utils.Re == nil {
  116. err := utils.Rc.LPush(utils.CACHE_KEY_USER_VIEW, data)
  117. if err != nil {
  118. fmt.Println("PushViewRecordNewRedisData LPush Err:" + err.Error())
  119. }
  120. return true
  121. }
  122. return false
  123. }
  124. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  125. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  126. userType, _, e := GetUserType(user.CompanyId)
  127. if e != nil {
  128. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  129. return
  130. }
  131. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  132. if userType == 1 || userType == 2 {
  133. havePower = true
  134. return
  135. }
  136. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  137. if e != nil {
  138. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  139. return
  140. }
  141. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  142. if e != nil {
  143. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  144. return
  145. }
  146. if reportMapDetail == nil {
  147. err = errors.New("GetdetailByCategoryIdP,获取详情失败, ")
  148. return
  149. }
  150. fmt.Println(permissionStr)
  151. //如果没有对应的升级权限,则返回
  152. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  153. return
  154. } else {
  155. havePower = true
  156. }
  157. return
  158. }
  159. // HandleArticleCategoryImg 预处理文章的封面图片
  160. func HandleArticleCategoryImg(list []*models.HomeArticle) (items []*models.HomeArticle, err error) {
  161. //研选的五张图片
  162. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  163. if e != nil {
  164. err = errors.New("获取研选的五张图片失败" + e.Error())
  165. return
  166. }
  167. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  168. //对应分类的所图片
  169. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  170. if err != nil {
  171. err = errors.New("获取对应分类的所图片失败" + err.Error())
  172. return
  173. }
  174. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  175. mapCategoryUrl := make(map[string]string)
  176. var categoryId string
  177. var imgUrlChart string
  178. for _, v := range categoryUrlList {
  179. vslice := strings.Split(v, "_")
  180. categoryId = vslice[0]
  181. imgUrlChart = vslice[len(vslice)-1]
  182. mapCategoryUrl[categoryId] = imgUrlChart
  183. }
  184. mapChartPerssion := make(map[string]string)
  185. reportMappingList, err := models.GetReportMappingStrategyAll()
  186. if err != nil {
  187. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  188. return
  189. }
  190. for _, v := range reportMappingList {
  191. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  192. }
  193. for k, v := range list {
  194. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  195. item := list[k]
  196. //如果文章一开始的内容是图片,优先展示第一张图片
  197. if list[k].Annotation == "" {
  198. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  199. if imgurl != "" {
  200. list[k].BodyHtml = imgurl
  201. }
  202. }
  203. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  204. list[k].Annotation = ArticleAnnotation(item)
  205. list[k].Body = ""
  206. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  207. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  208. //如果是研选系列的任意取五张图片的中的一张
  209. if v.CategoryId == "0" || v.ArticleId > utils.SummaryArticleId {
  210. knum := v.ArticleId % 5
  211. list[k].ImgUrlPc = researchList[knum]
  212. } else {
  213. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  214. }
  215. list[k].ArticleResponse = 4 // 默认展示核心观点
  216. //ArticleResponse int `description:"报告类型 0:啥也不是,1研选报告,2:研选纪要,3:研选沙龙,4;核心观点"`
  217. if list[k].ArticleId >= utils.SummaryArticleId {
  218. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  219. list[k].IsNeedJump = true
  220. list[k].ArticleResponse = 1
  221. }
  222. list[k].Source = 1
  223. //添加行业默认图片
  224. if v.ImgUrlPc == "" {
  225. if v.ChartPermissionName == utils.YI_YAO_NAME {
  226. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  227. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  228. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  229. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  230. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  231. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  232. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  233. }
  234. }
  235. //是不是研选报告
  236. if v.ArticleTypeId > 0 {
  237. list[k].IsResearch = true
  238. if v.ArticleTypeId == 12 {
  239. list[k].LabelKeyword = "研选沙龙"
  240. list[k].LabelKeywordImgLink = utils.LABEL_ICO_6
  241. } else {
  242. list[k].LabelKeyword = "纪要"
  243. list[k].LabelKeywordImgLink = utils.LABEL_ICO_5
  244. }
  245. }
  246. }
  247. articleIds := make([]int, 0)
  248. for i := range list {
  249. articleIds = append(articleIds, list[i].ArticleId)
  250. }
  251. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  252. // 报告关联产业信息
  253. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  254. if len(articleIds) > 0 {
  255. var industryCond string
  256. var industryPars []interface{}
  257. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  258. industryPars = append(industryPars, articleIds)
  259. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  260. if e != nil {
  261. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  262. return
  263. }
  264. for i := range industryList {
  265. v := industryList[i]
  266. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  267. ArticleId: v.ArticleId,
  268. IndustrialManagementId: v.IndustrialManagementId,
  269. IndustryName: v.IndustryName,
  270. ChartPermissionId: v.ChartPermissionId,
  271. })
  272. }
  273. }
  274. for k, v := range list {
  275. if len(industryMap[v.ArticleId]) > 0 {
  276. list[k].List = industryMap[v.ArticleId]
  277. } else {
  278. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  279. }
  280. v.Pv = articleMapPv[v.ArticleId]
  281. if v.Pv > 999 {
  282. list[k].Pv = 999
  283. }
  284. }
  285. if len(list) == 0 {
  286. list = make([]*models.HomeArticle, 0)
  287. }
  288. items = list
  289. return
  290. }
  291. // 处理核心观点的展示规则
  292. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  293. if item.ArticleId >= utils.SummaryArticleId {
  294. item.Annotation = YxArticleAnnotation(item)
  295. }
  296. if item.Annotation != "" {
  297. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  298. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  299. } else {
  300. return
  301. }
  302. bodyText, _ := GetReportContentTextSubNew(annotation)
  303. if bodyText == "" {
  304. return
  305. }
  306. if annotation != "" {
  307. annotation = html.UnescapeString(annotation)
  308. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  309. docText := doc.Text()
  310. mapDoc := make(map[int]string)
  311. var mapSort []int
  312. p := doc.Find("p")
  313. p.Each(func(tk int, pd *goquery.Selection) {
  314. pdText := pd.Text()
  315. pdText = strings.Replace(pdText, " ", "", -1)
  316. if pdText != "" {
  317. textLen := strings.Index(docText, pdText)
  318. mapDoc[(strings.Index(docText, pdText))] = pdText
  319. mapSort = append(mapSort, textLen)
  320. }
  321. })
  322. li := doc.Find("li")
  323. li.Each(func(tk int, li *goquery.Selection) {
  324. liText := li.Text()
  325. liText = strings.Replace(liText, " ", "", -1)
  326. if liText != "" {
  327. textLen := strings.Index(docText, liText)
  328. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  329. mapSort = append(mapSort, textLen)
  330. }
  331. })
  332. ul := doc.Find("ul")
  333. ul.Each(func(tk int, ul *goquery.Selection) {
  334. ulText := ul.Text()
  335. ulText = strings.Replace(ulText, " ", "", -1)
  336. if ulText != "" {
  337. textLen := strings.Index(docText, ulText)
  338. mapDoc[(strings.Index(docText, ulText))] = ulText
  339. mapSort = append(mapSort, textLen)
  340. }
  341. })
  342. if len(mapSort) == 0 {
  343. return
  344. } else {
  345. //排序
  346. sort.Ints(mapSort)
  347. var annotationHtml string
  348. for _, vSort := range mapSort {
  349. for k, v := range mapDoc {
  350. if k == vSort && v != "" {
  351. annotationHtml += v + "<br>"
  352. }
  353. }
  354. }
  355. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  356. annotationHtml = "<p>" + annotationHtml + "</p>"
  357. annotation = annotationHtml
  358. }
  359. }
  360. return
  361. }
  362. // 处理核心观点的展示规则
  363. func AnnotationHtml(bodyText string) (annotation string) {
  364. if bodyText == "" {
  365. return
  366. }
  367. annotation = bodyText
  368. annotation = html.UnescapeString(annotation)
  369. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  370. docText := doc.Text()
  371. mapDoc := make(map[int]string)
  372. var mapSort []int
  373. p := doc.Find("p")
  374. p.Each(func(tk int, pd *goquery.Selection) {
  375. pdText := pd.Text()
  376. //pdText = strings.Replace(pdText, " ", "", -1)
  377. if pdText != "" {
  378. textLen := strings.Index(docText, pdText)
  379. mapDoc[(strings.Index(docText, pdText))] = pdText
  380. mapSort = append(mapSort, textLen)
  381. }
  382. })
  383. li := doc.Find("li")
  384. li.Each(func(tk int, li *goquery.Selection) {
  385. liText := li.Text()
  386. liText = strings.Replace(liText, " ", "", -1)
  387. if liText != "" {
  388. textLen := strings.Index(docText, liText)
  389. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  390. mapSort = append(mapSort, textLen)
  391. }
  392. })
  393. ul := doc.Find("ul")
  394. ul.Each(func(tk int, ul *goquery.Selection) {
  395. ulText := ul.Text()
  396. ulText = strings.Replace(ulText, " ", "", -1)
  397. if ulText != "" {
  398. textLen := strings.Index(docText, ulText)
  399. mapDoc[(strings.Index(docText, ulText))] = ulText
  400. mapSort = append(mapSort, textLen)
  401. }
  402. })
  403. section := doc.Find("section")
  404. section.Each(func(tk int, section *goquery.Selection) {
  405. sectionText := section.Text()
  406. sectionText = strings.Replace(sectionText, " ", "", -1)
  407. if sectionText != "" {
  408. textLen := strings.Index(docText, sectionText)
  409. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  410. mapSort = append(mapSort, textLen)
  411. }
  412. })
  413. if len(mapSort) == 0 {
  414. return
  415. } else {
  416. //排序
  417. sort.Ints(mapSort)
  418. var annotationHtml string
  419. for _, vSort := range mapSort {
  420. for k, v := range mapDoc {
  421. if k == vSort && v != "" {
  422. annotationHtml += v + "<br>"
  423. }
  424. }
  425. }
  426. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  427. annotationHtml = "<p>" + annotationHtml + "</p>"
  428. annotation = annotationHtml
  429. }
  430. return
  431. }
  432. // 处理产品内测展示规则
  433. func ProductInteriorHtml(bodyText string) (annotation string) {
  434. if bodyText == "" {
  435. return
  436. }
  437. sliceBody := strings.Split(bodyText, "</p>")
  438. annotation, _ = GetReportContentTextSub(sliceBody[0])
  439. return
  440. }
  441. // 解析研选内容中的核心观点
  442. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  443. //如果不规范,就获取内容主体
  444. if strings.Count(article.Body, "<hr") == 0 {
  445. //如果内容不规范而且,还有图片,就把核心观点置空
  446. if article.BodyHtml != "" {
  447. return
  448. }
  449. annotation, _ = GetReportContentTextSub(article.Body)
  450. return
  451. }
  452. body := strings.ReplaceAll(article.Body, "<strong>", "")
  453. body = strings.ReplaceAll(body, "</strong>", "")
  454. body = strings.ReplaceAll(body, "</ol>", "</div>")
  455. body = strings.ReplaceAll(body, "<ol>", "<div>")
  456. body = strings.ReplaceAll(body, "</li>", "</p>")
  457. body = strings.ReplaceAll(body, "<li>", "<p>")
  458. re, _ := regexp.Compile("<strong.*?>")
  459. body = re.ReplaceAllString(body, "")
  460. reLi, _ := regexp.Compile("<li.*?>")
  461. body = reLi.ReplaceAllString(body, "")
  462. var plus int
  463. coreIndex := strings.Index(body, "核心观点:")
  464. plus = 15
  465. if coreIndex == -1 {
  466. coreIndex = strings.Index(body, "核心观点:")
  467. plus = 13
  468. }
  469. if coreIndex == -1 {
  470. coreIndex = strings.Index(body, "核心观点")
  471. plus = 12
  472. }
  473. if coreIndex == -1 {
  474. coreIndex = strings.Index(body, "核心结论:")
  475. plus = 15
  476. }
  477. if coreIndex == -1 {
  478. coreIndex = strings.Index(body, "核心结论:")
  479. plus = 13
  480. }
  481. if coreIndex == -1 {
  482. coreIndex = strings.Index(body, "核心结论")
  483. plus = 12
  484. }
  485. endIndex := strings.Index(body, "<hr")
  486. //如果有下划线跟核心观点就获取 核心观点~下划线之间的内容,如果没有就获取整个下划线的内容
  487. if endIndex != -1 {
  488. if coreIndex != -1 {
  489. body = body[coreIndex+plus : endIndex]
  490. } else {
  491. body = body[0:endIndex]
  492. }
  493. }
  494. annotation, _ = GetReportContentTextSub(body)
  495. return
  496. }
  497. // GetYxArticleIdMap 获取研选文章ID
  498. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  499. var err error
  500. defer func() {
  501. if err != nil {
  502. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  503. }
  504. }()
  505. var condition string
  506. var pars []interface{}
  507. condition = ` AND article_type_id > 0 `
  508. if len(articleIds) > 0 {
  509. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  510. pars = append(pars, articleIds)
  511. }
  512. articleList, e := models.GetArticleList(condition, pars)
  513. if e != nil {
  514. err = errors.New("GetArticleList, Err: " + e.Error())
  515. return
  516. }
  517. mapResp = make(map[int]bool, 0)
  518. for _, v := range articleList {
  519. mapResp[v.ArticleId] = true
  520. }
  521. return
  522. }
  523. // GetYanxuanArticleIds 获取研选文章ID
  524. func GetYanxuanArticleIds() (articleIds []int) {
  525. var err error
  526. defer func() {
  527. if err != nil {
  528. fmt.Println(err)
  529. go utils.SendAlarmMsg("获取研选文章ID GetYanxuanArticleIds,失败:"+err.Error(), 2)
  530. }
  531. }()
  532. var condition string
  533. var pars []interface{}
  534. condition = ` AND article_type_id > 0 `
  535. list, e := models.GetCygxCygxArticleIdList(condition, pars)
  536. if e != nil {
  537. err = errors.New("GetCygxCygxArticleIdList, Err: " + e.Error())
  538. return
  539. }
  540. for _, v := range list {
  541. articleIds = append(articleIds, v.ArticleId)
  542. }
  543. return
  544. }
  545. // GetArticleDetailUserPower 处理用户查看报告详情的权限
  546. func GetArticleDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
  547. userId := user.UserId
  548. companyId := user.CompanyId
  549. //判断用户是否开通了个人研选权限
  550. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  551. if mfyxUserPermissionTotal == 1 {
  552. havePower = true
  553. return
  554. }
  555. //用户是否持有有效卡片
  556. userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
  557. fmt.Println("userCardTotal", userCardTotal)
  558. if userCardTotal == 1 {
  559. havePower = true
  560. return
  561. }
  562. //是否是权益客户
  563. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  564. if e != nil {
  565. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  566. return
  567. }
  568. if raiCount == 0 {
  569. return
  570. }
  571. productDetail, e := models.GetCompanyProductDetailByCompanyId(companyId, 2)
  572. if e != nil {
  573. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  574. return
  575. }
  576. // 永续客户无法查看研选权限
  577. if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
  578. return
  579. }
  580. permissionStr, e := models.GetCompanyPermission(companyId)
  581. if e != nil {
  582. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  583. return
  584. }
  585. if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  586. havePower = true
  587. return
  588. }
  589. return
  590. }