article.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. if v.CategoryId != "0" {
  236. list[k].LabelKeywordImgLink = utils.LABEL_ICO_11
  237. } else if v.ArticleTypeId > 0 {
  238. list[k].IsResearch = true
  239. if v.ArticleTypeId == 12 {
  240. list[k].LabelKeyword = "研选沙龙"
  241. list[k].LabelKeywordImgLink = utils.LABEL_ICO_6
  242. } else {
  243. list[k].LabelKeyword = "纪要"
  244. list[k].LabelKeywordImgLink = utils.LABEL_ICO_5
  245. }
  246. }
  247. }
  248. articleIds := make([]int, 0)
  249. for i := range list {
  250. articleIds = append(articleIds, list[i].ArticleId)
  251. }
  252. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  253. // 报告关联产业信息
  254. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  255. if len(articleIds) > 0 {
  256. var industryCond string
  257. var industryPars []interface{}
  258. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  259. industryPars = append(industryPars, articleIds)
  260. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  261. if e != nil {
  262. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  263. return
  264. }
  265. for i := range industryList {
  266. v := industryList[i]
  267. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  268. ArticleId: v.ArticleId,
  269. IndustrialManagementId: v.IndustrialManagementId,
  270. IndustryName: v.IndustryName,
  271. ChartPermissionId: v.ChartPermissionId,
  272. })
  273. }
  274. }
  275. for k, v := range list {
  276. if len(industryMap[v.ArticleId]) > 0 {
  277. list[k].List = industryMap[v.ArticleId]
  278. } else {
  279. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  280. }
  281. v.Pv = articleMapPv[v.ArticleId]
  282. if v.Pv > 999 {
  283. list[k].Pv = 999
  284. }
  285. }
  286. if len(list) == 0 {
  287. list = make([]*models.HomeArticle, 0)
  288. }
  289. items = list
  290. return
  291. }
  292. // 处理核心观点的展示规则
  293. func ArticleAnnotation(item *models.HomeArticle) (annotation string) {
  294. if item.ArticleId >= utils.SummaryArticleId {
  295. item.Annotation = YxArticleAnnotation(item)
  296. }
  297. if item.Annotation != "" {
  298. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  299. annotation = strings.Replace(item.Annotation, "&nbsp;", "", -1)
  300. } else {
  301. return
  302. }
  303. bodyText, _ := GetReportContentTextSubNew(annotation)
  304. if bodyText == "" {
  305. return
  306. }
  307. if annotation != "" {
  308. annotation = html.UnescapeString(annotation)
  309. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  310. docText := doc.Text()
  311. mapDoc := make(map[int]string)
  312. var mapSort []int
  313. p := doc.Find("p")
  314. p.Each(func(tk int, pd *goquery.Selection) {
  315. pdText := pd.Text()
  316. pdText = strings.Replace(pdText, " ", "", -1)
  317. if pdText != "" {
  318. textLen := strings.Index(docText, pdText)
  319. mapDoc[(strings.Index(docText, pdText))] = pdText
  320. mapSort = append(mapSort, textLen)
  321. }
  322. })
  323. li := doc.Find("li")
  324. li.Each(func(tk int, li *goquery.Selection) {
  325. liText := li.Text()
  326. liText = strings.Replace(liText, " ", "", -1)
  327. if liText != "" {
  328. textLen := strings.Index(docText, liText)
  329. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  330. mapSort = append(mapSort, textLen)
  331. }
  332. })
  333. ul := doc.Find("ul")
  334. ul.Each(func(tk int, ul *goquery.Selection) {
  335. ulText := ul.Text()
  336. ulText = strings.Replace(ulText, " ", "", -1)
  337. if ulText != "" {
  338. textLen := strings.Index(docText, ulText)
  339. mapDoc[(strings.Index(docText, ulText))] = ulText
  340. mapSort = append(mapSort, textLen)
  341. }
  342. })
  343. if len(mapSort) == 0 {
  344. return
  345. } else {
  346. //排序
  347. sort.Ints(mapSort)
  348. var annotationHtml string
  349. for _, vSort := range mapSort {
  350. for k, v := range mapDoc {
  351. if k == vSort && v != "" {
  352. annotationHtml += v + "<br>"
  353. }
  354. }
  355. }
  356. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  357. annotationHtml = "<p>" + annotationHtml + "</p>"
  358. annotation = annotationHtml
  359. }
  360. }
  361. return
  362. }
  363. // 处理核心观点的展示规则
  364. func AnnotationHtml(bodyText string) (annotation string) {
  365. if bodyText == "" {
  366. return
  367. }
  368. annotation = bodyText
  369. annotation = html.UnescapeString(annotation)
  370. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  371. docText := doc.Text()
  372. mapDoc := make(map[int]string)
  373. var mapSort []int
  374. p := doc.Find("p")
  375. p.Each(func(tk int, pd *goquery.Selection) {
  376. pdText := pd.Text()
  377. //pdText = strings.Replace(pdText, " ", "", -1)
  378. if pdText != "" {
  379. textLen := strings.Index(docText, pdText)
  380. mapDoc[(strings.Index(docText, pdText))] = pdText
  381. mapSort = append(mapSort, textLen)
  382. }
  383. })
  384. li := doc.Find("li")
  385. li.Each(func(tk int, li *goquery.Selection) {
  386. liText := li.Text()
  387. liText = strings.Replace(liText, " ", "", -1)
  388. if liText != "" {
  389. textLen := strings.Index(docText, liText)
  390. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  391. mapSort = append(mapSort, textLen)
  392. }
  393. })
  394. ul := doc.Find("ul")
  395. ul.Each(func(tk int, ul *goquery.Selection) {
  396. ulText := ul.Text()
  397. ulText = strings.Replace(ulText, " ", "", -1)
  398. if ulText != "" {
  399. textLen := strings.Index(docText, ulText)
  400. mapDoc[(strings.Index(docText, ulText))] = ulText
  401. mapSort = append(mapSort, textLen)
  402. }
  403. })
  404. section := doc.Find("section")
  405. section.Each(func(tk int, section *goquery.Selection) {
  406. sectionText := section.Text()
  407. sectionText = strings.Replace(sectionText, " ", "", -1)
  408. if sectionText != "" {
  409. textLen := strings.Index(docText, sectionText)
  410. mapDoc[(strings.Index(docText, sectionText))] = sectionText
  411. mapSort = append(mapSort, textLen)
  412. }
  413. })
  414. if len(mapSort) == 0 {
  415. return
  416. } else {
  417. //排序
  418. sort.Ints(mapSort)
  419. var annotationHtml string
  420. for _, vSort := range mapSort {
  421. for k, v := range mapDoc {
  422. if k == vSort && v != "" {
  423. annotationHtml += v + "<br>"
  424. }
  425. }
  426. }
  427. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  428. annotationHtml = "<p>" + annotationHtml + "</p>"
  429. annotation = annotationHtml
  430. }
  431. return
  432. }
  433. // 处理产品内测展示规则
  434. func ProductInteriorHtml(bodyText string) (annotation string) {
  435. if bodyText == "" {
  436. return
  437. }
  438. sliceBody := strings.Split(bodyText, "</p>")
  439. annotation, _ = GetReportContentTextSub(sliceBody[0])
  440. return
  441. }
  442. // 解析研选内容中的核心观点
  443. func YxArticleAnnotation(article *models.HomeArticle) (annotation string) {
  444. //如果不规范,就获取内容主体
  445. if strings.Count(article.Body, "<hr") == 0 {
  446. //如果内容不规范而且,还有图片,就把核心观点置空
  447. if article.BodyHtml != "" {
  448. return
  449. }
  450. annotation, _ = GetReportContentTextSub(article.Body)
  451. return
  452. }
  453. body := strings.ReplaceAll(article.Body, "<strong>", "")
  454. body = strings.ReplaceAll(body, "</strong>", "")
  455. body = strings.ReplaceAll(body, "</ol>", "</div>")
  456. body = strings.ReplaceAll(body, "<ol>", "<div>")
  457. body = strings.ReplaceAll(body, "</li>", "</p>")
  458. body = strings.ReplaceAll(body, "<li>", "<p>")
  459. re, _ := regexp.Compile("<strong.*?>")
  460. body = re.ReplaceAllString(body, "")
  461. reLi, _ := regexp.Compile("<li.*?>")
  462. body = reLi.ReplaceAllString(body, "")
  463. var plus int
  464. coreIndex := strings.Index(body, "核心观点:")
  465. plus = 15
  466. if coreIndex == -1 {
  467. coreIndex = strings.Index(body, "核心观点:")
  468. plus = 13
  469. }
  470. if coreIndex == -1 {
  471. coreIndex = strings.Index(body, "核心观点")
  472. plus = 12
  473. }
  474. if coreIndex == -1 {
  475. coreIndex = strings.Index(body, "核心结论:")
  476. plus = 15
  477. }
  478. if coreIndex == -1 {
  479. coreIndex = strings.Index(body, "核心结论:")
  480. plus = 13
  481. }
  482. if coreIndex == -1 {
  483. coreIndex = strings.Index(body, "核心结论")
  484. plus = 12
  485. }
  486. endIndex := strings.Index(body, "<hr")
  487. //如果有下划线跟核心观点就获取 核心观点~下划线之间的内容,如果没有就获取整个下划线的内容
  488. if endIndex != -1 {
  489. if coreIndex != -1 {
  490. body = body[coreIndex+plus : endIndex]
  491. } else {
  492. body = body[0:endIndex]
  493. }
  494. }
  495. annotation, _ = GetReportContentTextSub(body)
  496. return
  497. }
  498. // GetYxArticleIdMap 获取研选文章ID
  499. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  500. var err error
  501. defer func() {
  502. if err != nil {
  503. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  504. }
  505. }()
  506. var condition string
  507. var pars []interface{}
  508. condition = ` AND article_type_id > 0 `
  509. if len(articleIds) > 0 {
  510. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  511. pars = append(pars, articleIds)
  512. }
  513. articleList, e := models.GetArticleList(condition, pars)
  514. if e != nil {
  515. err = errors.New("GetArticleList, Err: " + e.Error())
  516. return
  517. }
  518. mapResp = make(map[int]bool, 0)
  519. for _, v := range articleList {
  520. mapResp[v.ArticleId] = true
  521. }
  522. return
  523. }
  524. // GetYanxuanArticleIds 获取研选文章ID
  525. func GetYanxuanArticleIds() (articleIds []int) {
  526. var err error
  527. defer func() {
  528. if err != nil {
  529. fmt.Println(err)
  530. go utils.SendAlarmMsg("获取研选文章ID GetYanxuanArticleIds,失败:"+err.Error(), 2)
  531. }
  532. }()
  533. var condition string
  534. var pars []interface{}
  535. condition = ` AND article_type_id > 0 `
  536. list, e := models.GetCygxCygxArticleIdList(condition, pars)
  537. if e != nil {
  538. err = errors.New("GetCygxCygxArticleIdList, Err: " + e.Error())
  539. return
  540. }
  541. for _, v := range list {
  542. articleIds = append(articleIds, v.ArticleId)
  543. }
  544. listGuShou, e := models.GetResourceDataListGuShou()
  545. if e != nil {
  546. err = errors.New("GetResourceDataListGuShou, Err: " + e.Error())
  547. return
  548. }
  549. for _, v := range listGuShou {
  550. articleIds = append(articleIds, v.SourceId)
  551. }
  552. return
  553. }
  554. // GetArticleDetailUserPower 处理用户查看报告详情的权限
  555. func GetArticleDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
  556. userId := user.UserId
  557. companyId := user.CompanyId
  558. //判断用户是否开通了个人研选权限
  559. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  560. if mfyxUserPermissionTotal == 1 {
  561. havePower = true
  562. return
  563. }
  564. //用户是否持有有效卡片
  565. userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
  566. fmt.Println("userCardTotal", userCardTotal)
  567. if userCardTotal == 1 {
  568. havePower = true
  569. return
  570. }
  571. //是否是权益客户
  572. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  573. if e != nil {
  574. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  575. return
  576. }
  577. if raiCount == 0 {
  578. return
  579. }
  580. productDetail, e := models.GetCompanyProductDetailByCompanyId(companyId, 2)
  581. if e != nil {
  582. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  583. return
  584. }
  585. // 永续客户无法查看研选权限
  586. if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
  587. return
  588. }
  589. permissionStr, e := models.GetCompanyPermission(companyId)
  590. if e != nil {
  591. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  592. return
  593. }
  594. if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  595. havePower = true
  596. return
  597. }
  598. return
  599. }