article.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/PuerkitoBio/goquery"
  6. "hongze/hongze_web_mfyx/models"
  7. "hongze/hongze_web_mfyx/utils"
  8. "html"
  9. "regexp"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. )
  14. func FixArticleImgUrl(body string) (contentSub string, err error) {
  15. r := strings.NewReader(string(body))
  16. doc, err := goquery.NewDocumentFromReader(r)
  17. if err != nil {
  18. fmt.Println(err)
  19. }
  20. doc.Find("img").Each(func(i int, s *goquery.Selection) {
  21. src, _ := s.Attr("src")
  22. if i == 0 && src != "" {
  23. contentSub = src
  24. }
  25. })
  26. return
  27. }
  28. func GetReportContentTextSub(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(body, "Powered by Froala Editor", "", -1)
  41. contentSub = strings.Replace(body, "PoweredbyFroalaEditor", "", -1)
  42. contentSub = strings.Replace(body, " ", "", -1)
  43. return
  44. }
  45. func GetReportContentTextArticleBody(content string) (contentSub string) {
  46. contentSub = html.UnescapeString(content)
  47. contentSub = strings.Replace(contentSub, "<p data-f-id=\"pbf\" style=\"text-align: center; font-size: 14px; margin-top: 30px; opacity: 0.65; font-family: sans-serif;\">Powered by <a href=\"https://www.froala.com/wysiwyg-editor?pb=1\" title=\"Froala Editor\">Froala Editor</a></p>", "", -1)
  48. contentSub = strings.Replace(contentSub, "pre", "div", -1)
  49. return
  50. }
  51. // HandleArticleCategoryImg 预处理文章的封面图片
  52. func HandleArticleCategoryImg(list []*models.ArticleListResp, user *models.WxUserItem) (items []*models.ArticleListResp, err error) {
  53. //研选的五张图片
  54. detailResearch, e := models.GetConfigByCode("category_research_img_url")
  55. if e != nil {
  56. err = errors.New("获取研选的五张图片失败" + e.Error())
  57. return
  58. }
  59. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  60. //对应分类的所图片
  61. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  62. if err != nil {
  63. err = errors.New("获取对应分类的所图片失败" + err.Error())
  64. return
  65. }
  66. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  67. mapCategoryUrl := make(map[string]string)
  68. var categoryId string
  69. var imgUrlChart string
  70. for _, v := range categoryUrlList {
  71. vslice := strings.Split(v, "_")
  72. categoryId = vslice[0]
  73. imgUrlChart = vslice[len(vslice)-1]
  74. mapCategoryUrl[categoryId] = imgUrlChart
  75. }
  76. mapChartPerssion := make(map[string]string)
  77. reportMappingList, err := models.GetReportMappingStrategyAll()
  78. if err != nil {
  79. err = errors.New("GetReportMappingStrategyAll err" + err.Error())
  80. return
  81. }
  82. for _, v := range reportMappingList {
  83. mapChartPerssion[strconv.Itoa(v.CategoryId)] = v.ChartPermissionName
  84. }
  85. for k, v := range list {
  86. if list[k].Annotation == "" {
  87. imgurl, _ := FixArticleImgUrl(html.UnescapeString(list[k].Body))
  88. if imgurl != "" {
  89. list[k].BodyImg = imgurl
  90. }
  91. }
  92. item := list[k]
  93. //如果文章一开始的内容是图片,优先展示第一张图片
  94. //newBody, _ := GetReportContentTextSubByarticle(item.Body, item.Annotation, item.ArticleId)
  95. list[k].Resource = item.Resource
  96. list[k].Annotation = ArticleAnnotation(item)
  97. list[k].Body = ""
  98. list[k].Abstract, _ = GetReportContentTextSub(v.Abstract)
  99. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  100. list[k].ChartPermissionName = mapChartPerssion[v.CategoryId]
  101. //如果是研选系列的任意取五张图片的中的一张
  102. if v.CategoryId == "0" || v.ArticleId >= utils.SummaryArticleId {
  103. knum := v.ArticleId % 5
  104. list[k].ImgUrlPc = researchList[knum]
  105. } else {
  106. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  107. }
  108. if list[k].ArticleId < utils.SummaryArticleId {
  109. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  110. list[k].IsNeedJump = true
  111. }
  112. list[k].Source = 1
  113. //添加行业默认图片
  114. if v.ImgUrlPc == "" {
  115. if v.ChartPermissionName == utils.YI_YAO_NAME {
  116. list[k].ImgUrlPc = utils.YI_YAO_OTHER_IMG
  117. } else if v.ChartPermissionName == utils.XIAO_FEI_NAME {
  118. list[k].ImgUrlPc = utils.XIAO_FEI_OTHER_IMG
  119. } else if v.ChartPermissionName == utils.KE_JI_NAME {
  120. list[k].ImgUrlPc = utils.KE_JI_OTHER_IMG
  121. } else if v.ChartPermissionName == utils.ZHI_ZAO_NAME {
  122. list[k].ImgUrlPc = utils.ZHI_ZAO_OTHER_IMG
  123. }
  124. }
  125. if v.ArticleTypeId > 0 {
  126. list[k].IsResearch = true
  127. }
  128. //是不是研选报告
  129. if v.ArticleTypeId > 0 {
  130. list[k].IsResearch = true
  131. if v.ArticleTypeId == 12 {
  132. list[k].LabelKeywordImgLink = utils.LABEL_ICO_6
  133. } else {
  134. list[k].LabelKeywordImgLink = utils.LABEL_ICO_5
  135. }
  136. } else {
  137. list[k].LabelKeywordImgLink = utils.LABEL_ICO_4
  138. list[k].SpecialColumnId = v.DepartmentId
  139. }
  140. }
  141. articleIds := make([]int, 0)
  142. var articleIdsSpecialArr []int // 研选专栏ID
  143. for _, v := range list {
  144. if v.IsSpecial == 0 {
  145. articleIds = append(articleIds, v.ArticleId)
  146. } else {
  147. articleIdsSpecialArr = append(articleIdsSpecialArr, v.ArticleId)
  148. }
  149. }
  150. // 报告关联产业信息
  151. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  152. if len(articleIds) > 0 {
  153. var industryCond string
  154. var industryPars []interface{}
  155. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  156. industryPars = append(industryPars, articleIds)
  157. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  158. if e != nil {
  159. err = errors.New("GetIndustrialListByarticleId" + e.Error())
  160. return
  161. }
  162. for i := range industryList {
  163. v := industryList[i]
  164. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  165. ArticleId: v.ArticleId,
  166. IndustrialManagementId: v.IndustrialManagementId,
  167. IndustryName: v.IndustryName,
  168. ChartPermissionId: v.ChartPermissionId,
  169. })
  170. }
  171. }
  172. //// 处理文章收藏字段
  173. //mapCollect, e := GetUserAticleCollectMap(user)
  174. //if e != nil {
  175. // err = errors.New("GetUserAticleCollectMap" + e.Error())
  176. // return
  177. //}
  178. //var articleIds []int
  179. //for _, v := range list {
  180. // articleIds = append(articleIds, v.ArticleId)
  181. //}
  182. articleMapPv := GetArticleHistoryByArticleId(articleIds) //文章Pv
  183. articleCollectMap, _ := GetCygxArticleCollectMap(user.UserId) //用户收藏的文章
  184. articleCollectNumMap, _ := GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
  185. articleCollectYanxuanSpecialMap, _ := GetYanxuanSpecialCollectMap(user.UserId) //用户收藏的研选专栏
  186. yanxuanSpecialPv := GetYanxuanSpecialRecordByYanxuanSpecialId(articleIdsSpecialArr) //研选专栏Pv
  187. for k, v := range list {
  188. if len(industryMap[v.ArticleId]) > 0 {
  189. list[k].List = industryMap[v.ArticleId]
  190. } else {
  191. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  192. }
  193. //if _, ok := mapCollect[v.ArticleId]; ok {
  194. // list[k].IsCollect = true
  195. //}
  196. if v.IsSpecial == 0 {
  197. list[k].Pv = articleMapPv[v.ArticleId]
  198. list[k].IsCollect = articleCollectMap[v.ArticleId]
  199. list[k].CollectNum = articleCollectNumMap[v.ArticleId]
  200. } else {
  201. v.IsCollect = articleCollectYanxuanSpecialMap[v.ArticleId]
  202. v.Pv = yanxuanSpecialPv[v.ArticleId]
  203. }
  204. }
  205. if len(list) == 0 {
  206. list = make([]*models.ArticleListResp, 0)
  207. }
  208. items = list
  209. return
  210. }
  211. // HandleArticleStock 处理报告关联的个股标签
  212. func HandleArticleStock(stock string) (items []*models.ComapnyNameResp) {
  213. sliceSubjects := strings.Split(stock, "/")
  214. if len(sliceSubjects) > 0 {
  215. for _, vSubject := range sliceSubjects {
  216. sliceKuohao := strings.Split(vSubject, "(") //过滤括号
  217. sliceXiahuaxian := strings.Split(sliceKuohao[0], "-") //过滤下划线
  218. subject := sliceXiahuaxian[0]
  219. items = append(items, &models.ComapnyNameResp{ComapnyName: subject})
  220. }
  221. }
  222. return
  223. }
  224. // GetSpecialArticleDetailUserPower 处理用户查看专项调研文章详情的权限
  225. func GetSpecialArticleDetailUserPower(user *models.WxUserItem, articleInfo *models.ArticleDetail) (havePower bool, err error) {
  226. userType, _, e := GetUserType(user.CompanyId)
  227. if e != nil {
  228. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  229. return
  230. }
  231. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  232. if userType == 1 || userType == 2 {
  233. havePower = true
  234. return
  235. }
  236. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  237. if e != nil {
  238. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  239. return
  240. }
  241. reportMapDetail, e := models.GetdetailByCategoryIdPush(articleInfo.CategoryId)
  242. if e != nil {
  243. err = errors.New("GetdetailByCategoryIdPush, Err: " + e.Error())
  244. return
  245. }
  246. if reportMapDetail == nil {
  247. err = errors.New("GetdetailByCategoryIdP,获取详情失败, Err: ")
  248. return
  249. }
  250. //如果没有对应的升级权限,则返回
  251. if !strings.Contains(permissionStr, reportMapDetail.ChartPermissionName) {
  252. return
  253. } else {
  254. havePower = true
  255. }
  256. return
  257. }
  258. func GetReportContentTextSubNew(content string) (contentSub string, err error) {
  259. content = html.UnescapeString(content)
  260. doc, errdoc := goquery.NewDocumentFromReader(strings.NewReader(content))
  261. if errdoc != nil {
  262. err = errdoc
  263. return
  264. }
  265. docText := doc.Text()
  266. bodyRune := []rune(docText)
  267. bodyRuneLen := len(bodyRune)
  268. body := string(bodyRune[:bodyRuneLen])
  269. contentSub = body
  270. contentSub = strings.Replace(contentSub, "Powered by Froala Editor", "", -1)
  271. contentSub = strings.Replace(contentSub, " ", "", -1)
  272. 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)
  273. return
  274. }
  275. // 处理核心观点的展示规则
  276. func ArticleAnnotation(item *models.ArticleListResp) (annotation string) {
  277. if item.ArticleId >= utils.SummaryArticleId {
  278. item.Annotation = YxArticleAnnotation(item)
  279. }
  280. if item.Annotation != "" {
  281. annotation = strings.Replace(item.Annotation, "<br>", "", -1)
  282. } else {
  283. return
  284. }
  285. bodyText, _ := GetReportContentTextSubNew(annotation)
  286. if bodyText == "" {
  287. return
  288. }
  289. if annotation != "" {
  290. annotation = html.UnescapeString(annotation)
  291. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  292. docText := doc.Text()
  293. mapDoc := make(map[int]string)
  294. mapSortRepeat := make(map[string]string)
  295. var mapSort []int
  296. p := doc.Find("p")
  297. p.Each(func(tk int, pd *goquery.Selection) {
  298. pdText := pd.Text()
  299. pdText = strings.Replace(pdText, " ", "", -1)
  300. if pdText != "" {
  301. textLen := strings.Index(docText, pdText)
  302. if mapSortRepeat[strconv.Itoa(textLen)] == "" {
  303. mapDoc[(strings.Index(docText, pdText))] = pdText
  304. mapSort = append(mapSort, textLen)
  305. mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
  306. }
  307. }
  308. })
  309. li := doc.Find("li")
  310. li.Each(func(tk int, li *goquery.Selection) {
  311. liText := li.Text()
  312. liText = strings.Replace(liText, " ", "", -1)
  313. if liText != "" {
  314. textLen := strings.Index(docText, liText)
  315. if mapSortRepeat[strconv.Itoa(textLen)] == "" {
  316. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  317. mapSort = append(mapSort, textLen)
  318. mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
  319. }
  320. }
  321. })
  322. ul := doc.Find("ul")
  323. ul.Each(func(tk int, ul *goquery.Selection) {
  324. ulText := ul.Text()
  325. ulText = strings.Replace(ulText, " ", "", -1)
  326. if ulText != "" {
  327. textLen := strings.Index(docText, ulText)
  328. if mapSortRepeat[strconv.Itoa(textLen)] == "" {
  329. mapDoc[(strings.Index(docText, ulText))] = ulText
  330. mapSort = append(mapSort, textLen)
  331. mapSortRepeat[strconv.Itoa(textLen)] = strconv.Itoa(textLen)
  332. }
  333. }
  334. })
  335. if len(mapSort) == 0 {
  336. return
  337. } else {
  338. //排序
  339. sort.Ints(mapSort)
  340. var annotationHtml string
  341. for _, vSort := range mapSort {
  342. for k, v := range mapDoc {
  343. if k == vSort && v != "" {
  344. annotationHtml += v + "<br>"
  345. }
  346. }
  347. }
  348. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  349. annotationHtml = "<p>" + annotationHtml + "</p>"
  350. annotation = annotationHtml
  351. }
  352. }
  353. return
  354. }
  355. // 处理核心观点的展示规则
  356. func AnnotationHtml(bodyText string) (annotation string) {
  357. if bodyText == "" {
  358. return
  359. }
  360. annotation = bodyText
  361. annotation = html.UnescapeString(annotation)
  362. doc, _ := goquery.NewDocumentFromReader(strings.NewReader(annotation))
  363. docText := doc.Text()
  364. mapDoc := make(map[int]string)
  365. var mapSort []int
  366. p := doc.Find("p")
  367. p.Each(func(tk int, pd *goquery.Selection) {
  368. pdText := pd.Text()
  369. pdText = strings.Replace(pdText, " ", "", -1)
  370. if pdText != "" {
  371. textLen := strings.Index(docText, pdText)
  372. if textLen >= 0 {
  373. mapDoc[(strings.Index(docText, pdText))] = pdText
  374. mapSort = append(mapSort, textLen)
  375. }
  376. }
  377. })
  378. li := doc.Find("li")
  379. li.Each(func(tk int, li *goquery.Selection) {
  380. liText := li.Text()
  381. liText = strings.Replace(liText, " ", "", -1)
  382. if liText != "" {
  383. textLen := strings.Index(docText, liText)
  384. mapDoc[(strings.Index(docText, liText))] = strconv.Itoa(tk+1) + "." + liText
  385. mapSort = append(mapSort, textLen)
  386. }
  387. })
  388. ul := doc.Find("ul")
  389. ul.Each(func(tk int, ul *goquery.Selection) {
  390. ulText := ul.Text()
  391. ulText = strings.Replace(ulText, " ", "", -1)
  392. if ulText != "" {
  393. textLen := strings.Index(docText, ulText)
  394. mapDoc[(strings.Index(docText, ulText))] = ulText
  395. mapSort = append(mapSort, textLen)
  396. }
  397. })
  398. if len(mapSort) == 0 {
  399. return
  400. } else {
  401. //排序
  402. sort.Ints(mapSort)
  403. var annotationHtml string
  404. for _, vSort := range mapSort {
  405. for k, v := range mapDoc {
  406. if k == vSort && v != "" {
  407. annotationHtml += v + "<br>"
  408. }
  409. }
  410. }
  411. annotationHtml = strings.TrimRight(annotationHtml, "<br>")
  412. annotationHtml = "<p>" + annotationHtml + "</p>"
  413. annotation = annotationHtml
  414. }
  415. return
  416. }
  417. // 解析研选内容中的核心观点
  418. func YxArticleAnnotation(article *models.ArticleListResp) (annotation string) {
  419. //如果不规范,就获取内容主体
  420. if strings.Count(article.Body, "<hr") == 0 {
  421. //如果内容不规范而且,还有图片,就把核心观点置空
  422. if article.BodyImg != "" {
  423. return
  424. }
  425. annotation, _ = GetReportContentTextSub(article.Body)
  426. return
  427. }
  428. body := strings.ReplaceAll(article.Body, "<strong>", "")
  429. body = strings.ReplaceAll(body, "</strong>", "")
  430. body = strings.ReplaceAll(body, "</ol>", "</div>")
  431. body = strings.ReplaceAll(body, "<ol>", "<div>")
  432. body = strings.ReplaceAll(body, "</li>", "</p>")
  433. body = strings.ReplaceAll(body, "<li>", "<p>")
  434. re, _ := regexp.Compile("<strong.*?>")
  435. body = re.ReplaceAllString(body, "")
  436. reLi, _ := regexp.Compile("<li.*?>")
  437. body = reLi.ReplaceAllString(body, "")
  438. var plus int
  439. coreIndex := strings.Index(body, "核心观点:")
  440. plus = 15
  441. if coreIndex == -1 {
  442. coreIndex = strings.Index(body, "核心观点:")
  443. plus = 13
  444. }
  445. if coreIndex == -1 {
  446. coreIndex = strings.Index(body, "核心观点")
  447. plus = 12
  448. }
  449. if coreIndex == -1 {
  450. coreIndex = strings.Index(body, "核心结论:")
  451. plus = 15
  452. }
  453. if coreIndex == -1 {
  454. coreIndex = strings.Index(body, "核心结论:")
  455. plus = 13
  456. }
  457. if coreIndex == -1 {
  458. coreIndex = strings.Index(body, "核心结论")
  459. plus = 12
  460. }
  461. endIndex := strings.Index(body, "<hr")
  462. if coreIndex != -1 && endIndex != -1 {
  463. body = body[coreIndex+plus : endIndex]
  464. }
  465. annotation = body
  466. return
  467. }
  468. // 获取研选类型的文章分类Id
  469. func GetYanXuanArticleTypeIds() (articleTypeIds string, err error) {
  470. var condition string
  471. condition = " AND is_show_yanx = 1 "
  472. listType, e := models.GetCygxArticleTypeListCondition(condition)
  473. if e != nil {
  474. err = errors.New("GetCygxArticleTypeListCondition, Err: " + e.Error())
  475. return
  476. }
  477. for _, v := range listType {
  478. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  479. }
  480. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  481. if articleTypeIds == "" {
  482. err = errors.New("研选分类ID不能为空")
  483. return
  484. }
  485. return
  486. }
  487. // 用户报告操作行为,模板消息推送
  488. func ArticleUserRemind(user *models.WxUserItem, articleDetail *models.ArticleDetail, source int) (err error) {
  489. defer func() {
  490. if err != nil {
  491. go utils.SendAlarmMsg("同步策略平台阅读数据失败", 2)
  492. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "GetCeLueArticlePv ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  493. }
  494. }()
  495. countUser, err := models.GetUserRemind(user.UserId)
  496. if err != nil {
  497. return err
  498. }
  499. if countUser == 0 {
  500. return err
  501. }
  502. var sourceMsg string
  503. if source == 1 {
  504. sourceMsg = "阅读报告"
  505. } else {
  506. sourceMsg = "收藏报告"
  507. }
  508. //获取销售手机号
  509. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  510. if err != nil && err.Error() != utils.ErrNoRow() {
  511. return err
  512. }
  513. if sellerItemQy != nil {
  514. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  515. if e != nil {
  516. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  517. return
  518. }
  519. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  520. openIdList, err := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  521. if err != nil {
  522. return err
  523. }
  524. var keyword1 string
  525. var keyword2 string
  526. keyword1 = articleDetail.Title
  527. keyword2 = fmt.Sprint("互动:", sourceMsg, ",", user.RealName, "--", user.CompanyName)
  528. SendWxMsgWithArticleUserRemind(keyword1, keyword2, openIdList, articleDetail.ArticleId)
  529. }
  530. return
  531. }
  532. // GetAiQianYanArtilceList 获取AI前沿几篇文章
  533. func GetAiQianYanArtilceList(startSize, pageSize int) (items []*models.HomeArticle, total int, err error) {
  534. defer func() {
  535. if err != nil {
  536. go utils.SendAlarmMsg("获取AI前沿几篇文章失败"+err.Error(), 2)
  537. }
  538. }()
  539. var condition string
  540. var pars []interface{}
  541. condition += ` AND title LIKE '%AI前沿%' AND publish_status = 1 ORDER BY publish_date DESC `
  542. articleList, e := models.GetCygxCygxArticleList(condition, pars, startSize, pageSize)
  543. if e != nil {
  544. err = errors.New("GetCygxCygxArticleList, Err: " + e.Error())
  545. return
  546. }
  547. total, e = models.GetCygxArticleCount(condition, pars)
  548. if e != nil {
  549. err = errors.New("GetCygxArticleCount, Err: " + e.Error())
  550. return
  551. }
  552. for _, v := range articleList {
  553. item := new(models.HomeArticle)
  554. item.ArticleId = v.ArticleId
  555. item.Title = v.Title
  556. item.Abstract = v.Abstract
  557. item.Annotation = v.Annotation
  558. item.PublishDate = v.PublishDate
  559. item.CategoryId = strconv.Itoa(v.CategoryId)
  560. item.Body = v.Body
  561. items = append(items, item)
  562. }
  563. return
  564. }
  565. // GetYxArticleIdMap 获取研选文章ID
  566. func GetYxArticleIdMap(articleIds []int) (mapResp map[int]bool) {
  567. var err error
  568. defer func() {
  569. if err != nil {
  570. go utils.SendAlarmMsg("获取研选文章ID失败,GetYxArticleIdMap"+err.Error(), 2)
  571. }
  572. }()
  573. var condition string
  574. var pars []interface{}
  575. condition = ` AND article_type_id > 0 `
  576. if len(articleIds) > 0 {
  577. condition += ` AND article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  578. pars = append(pars, articleIds)
  579. }
  580. articleList, e := models.GetArticleList(condition, pars)
  581. if e != nil {
  582. err = errors.New("GetArticleList, Err: " + e.Error())
  583. return
  584. }
  585. mapResp = make(map[int]bool, 0)
  586. for _, v := range articleList {
  587. mapResp[v.ArticleId] = true
  588. }
  589. return
  590. }
  591. // GetYanxuanArticleIds 获取研选文章ID
  592. func GetYanxuanArticleIds() (articleIds []int) {
  593. var err error
  594. defer func() {
  595. if err != nil {
  596. fmt.Println(err)
  597. go utils.SendAlarmMsg("获取研选文章ID GetYanxuanArticleIds,失败:"+err.Error(), 2)
  598. }
  599. }()
  600. var condition string
  601. var pars []interface{}
  602. condition = ` AND article_type_id > 0 `
  603. list, e := models.GetCygxCygxArticleIdList(condition, pars)
  604. if e != nil {
  605. err = errors.New("GetCygxCygxArticleIdList, Err: " + e.Error())
  606. return
  607. }
  608. for _, v := range list {
  609. articleIds = append(articleIds, v.ArticleId)
  610. }
  611. return
  612. }
  613. // 获取报告分享图片
  614. func GetArticleShareImg(articleId int) (shareImg string) {
  615. var err error
  616. defer func() {
  617. if err != nil {
  618. fmt.Println(err)
  619. go utils.SendAlarmMsg(fmt.Sprint("获取活动分享封面图片失败 GetArticleShareImg Err:", err.Error(), "活动ID:", articleId), 2)
  620. }
  621. }()
  622. imgDetail, e := models.CygxCygxArticleDataDetail(articleId)
  623. if e != nil && e.Error() != utils.ErrNoRow() {
  624. err = errors.New("CygxCygxArticleDataDetail, Err: " + e.Error())
  625. return
  626. }
  627. if imgDetail != nil {
  628. shareImg = imgDetail.Cover
  629. } else {
  630. shareImg = utils.YANXUAN_ARTICLE_SHARE_IMG
  631. }
  632. return
  633. }
  634. // GetArticleDetailUserPower 处理用户查看报告详情的权限
  635. func GetArticleDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
  636. userId := user.UserId
  637. companyId := user.CompanyId
  638. //判断用户是否开通了个人研选权限
  639. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  640. if mfyxUserPermissionTotal == 1 {
  641. havePower = true
  642. return
  643. }
  644. //用户是否持有有效卡片
  645. userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
  646. if userCardTotal == 1 {
  647. havePower = true
  648. return
  649. }
  650. //是否是权益客户
  651. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  652. if e != nil {
  653. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  654. return
  655. }
  656. if raiCount == 0 {
  657. return
  658. }
  659. productDetail, e := models.GetCompanyProductDetailByCompanyId(companyId, 2)
  660. if e != nil {
  661. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  662. return
  663. }
  664. // 永续客户无法查看研选权限
  665. if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
  666. return
  667. }
  668. permissionStr, e := models.GetCompanyPermission(companyId)
  669. if e != nil {
  670. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  671. return
  672. }
  673. if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  674. havePower = true
  675. return
  676. }
  677. return
  678. }