article.go 22 KB

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