cygx_yanxuan_special.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_web_mfyx/models"
  6. "hongze/hongze_web_mfyx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息
  12. func SendWxMsgSpecialFollow(specialId int) (err error) {
  13. defer func() {
  14. if err != nil {
  15. go utils.SendAlarmMsg(fmt.Sprint("研选专栏有新内容审核通过时,给关注此专栏的客户发送模板消息失败", specialId, ", specialId", err.Error()), 2)
  16. }
  17. }()
  18. var first string
  19. var keyword1 string
  20. var keyword2 string
  21. var keyword3 string
  22. var keyword4 string
  23. var remark string
  24. followers, e := models.GetYanxuanSpecialFollowUserById(specialId)
  25. if e != nil {
  26. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  27. return
  28. }
  29. if len(followers) == 0 {
  30. return
  31. }
  32. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  33. if e != nil {
  34. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  35. return
  36. }
  37. var allInUserId string
  38. for _, v := range followers {
  39. allInUserId += strconv.Itoa(v) + ","
  40. }
  41. allInUserId = strings.TrimRight(allInUserId, ",")
  42. userList, err := models.GetWxUserListByUserIds(allInUserId)
  43. if err != nil && err.Error() != utils.ErrNoRow() {
  44. return err
  45. }
  46. mobile := ``
  47. for _, v := range userList {
  48. mobile += v.Mobile + ","
  49. }
  50. mobile = strings.TrimRight(mobile, ",")
  51. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  52. if e != nil {
  53. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  54. return
  55. }
  56. if len(openIdList) == 0 {
  57. return
  58. }
  59. //first =
  60. keyword1 = "研选专栏:" + specialItem.SpecialName
  61. keyword2 = "发布了新内容,点击查看详情"
  62. keyword3 = "-"
  63. //keyword4 = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  64. openIdArr := make([]string, 0)
  65. for _, v := range openIdList {
  66. openIdArr = append(openIdArr, v.OpenId)
  67. }
  68. redirectUrl := ""
  69. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  70. sendInfo := new(SendWxTemplate)
  71. sendInfo.First = first
  72. sendInfo.Keyword1 = keyword1
  73. sendInfo.Keyword2 = keyword2
  74. sendInfo.Keyword3 = keyword3
  75. sendInfo.Keyword4 = keyword4
  76. sendInfo.Remark = remark
  77. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  78. sendInfo.RedirectUrl = redirectUrl
  79. sendInfo.RedirectTarget = 3
  80. sendInfo.Resource = strconv.Itoa(specialId)
  81. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  82. sendInfo.OpenIdArr = openIdArr
  83. err = PublicSendTemplateMsg(sendInfo)
  84. if err != nil {
  85. return
  86. }
  87. return
  88. }
  89. // SendReviewTemplateMsgAdmin 提交审核时给王芳,葛琳发消息
  90. func SendReviewTemplateMsgAdmin(specialId int) (err error) {
  91. defer func() {
  92. if err != nil {
  93. go utils.SendAlarmMsg(fmt.Sprint("处理试用申请给王芳,汪洋发消息失败, specialId:", specialId, "ErrMsg", err.Error()), 2)
  94. }
  95. }()
  96. var configCode string
  97. //研选专栏修改之后给这些手机号推送审核模版消息
  98. configCode = utils.TPL_MSG_YAN_XUAN_SPECIAL_APPROVAL
  99. cnf, e := models.GetConfigByCode(configCode)
  100. if e != nil {
  101. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  102. return
  103. }
  104. openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue)
  105. if e != nil && e.Error() != utils.ErrNoRow() {
  106. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
  107. return err
  108. }
  109. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  110. if e != nil {
  111. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  112. return
  113. }
  114. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  115. if e != nil {
  116. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  117. return err
  118. }
  119. var keyword1 string
  120. var keyword2 string
  121. var keyword3 string
  122. var keyword4 string
  123. var remark string
  124. keyword1 = specialItem.RealName + "【" + user.CompanyName + "】"
  125. keyword2 = user.Mobile
  126. keyword3 = time.Now().Format(utils.FormatDateTime)
  127. keyword4 = "研选专栏提交了内容待审核"
  128. openIdArr := make([]string, 0)
  129. for _, v := range openIdList {
  130. openIdArr = append(openIdArr, v.OpenId)
  131. }
  132. redirectUrl := ""
  133. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
  134. sendInfo := new(SendWxTemplate)
  135. sendInfo.Keyword1 = keyword1
  136. sendInfo.Keyword2 = keyword2
  137. sendInfo.Keyword3 = keyword3
  138. sendInfo.Keyword4 = keyword4
  139. sendInfo.Remark = remark
  140. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  141. sendInfo.RedirectUrl = redirectUrl
  142. sendInfo.RedirectTarget = 3
  143. sendInfo.Resource = strconv.Itoa(specialId)
  144. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  145. sendInfo.OpenIdArr = openIdArr
  146. err = PublicSendTemplateMsg(sendInfo)
  147. if err != nil {
  148. return
  149. }
  150. return
  151. }
  152. // 研选专栏审核完成时,给提交人发送模板消息
  153. func SendWxMsgSpecialAuthor(specialId, status int) (err error) {
  154. defer func() {
  155. if err != nil {
  156. go utils.SendAlarmMsg(fmt.Sprint("研选专栏审核完成时,给提交人发送模板消息", specialId, ", specialId", err.Error()), 2)
  157. }
  158. }()
  159. var first string
  160. var keyword1 string
  161. var keyword2 string
  162. var keyword3 string
  163. var keyword4 string
  164. var remark string
  165. var redirectUrl string
  166. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  167. if e != nil {
  168. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  169. return
  170. }
  171. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  172. if e != nil {
  173. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  174. return err
  175. }
  176. openIdList, err := models.GetUserRecordListByMobile(4, user.Mobile)
  177. if err != nil && err.Error() != utils.ErrNoRow() {
  178. return err
  179. }
  180. keyword1 = "研选专栏内容审核"
  181. if status == 1 {
  182. keyword2 = "已通过审核,点击查看详情"
  183. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_DETAIL + strconv.Itoa(specialId)
  184. } else {
  185. keyword2 = "未通过审核,点击查看驳回原因"
  186. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_CENTER
  187. }
  188. keyword3 = "-"
  189. openIdArr := make([]string, 0)
  190. for _, v := range openIdList {
  191. openIdArr = append(openIdArr, v.OpenId)
  192. }
  193. sendInfo := new(SendWxTemplate)
  194. sendInfo.First = first
  195. sendInfo.Keyword1 = keyword1
  196. sendInfo.Keyword2 = keyword2
  197. sendInfo.Keyword3 = keyword3
  198. sendInfo.Keyword4 = keyword4
  199. sendInfo.Remark = remark
  200. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  201. sendInfo.RedirectUrl = redirectUrl
  202. sendInfo.RedirectTarget = 3
  203. sendInfo.Resource = strconv.Itoa(specialId)
  204. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  205. sendInfo.OpenIdArr = openIdArr
  206. err = PublicSendTemplateMsg(sendInfo)
  207. if err != nil {
  208. return
  209. }
  210. return
  211. }
  212. // 更新研选专栏 写入首页最新 cygx_resource_data 表
  213. func UpdateYanxuanSpecialResourceData(sourceId int) {
  214. var err error
  215. defer func() {
  216. if err != nil {
  217. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败ourceId: ", sourceId), 2)
  218. }
  219. }()
  220. var source = utils.CYGX_OBJ_YANXUANSPECIAL
  221. var condition string
  222. var pars []interface{}
  223. condition = ` AND status = 3 AND id = ? `
  224. pars = append(pars, sourceId)
  225. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  226. if e != nil {
  227. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  228. return
  229. }
  230. //如果取消发布了就做删除处理
  231. if total == 0 {
  232. e = models.DeleteResourceData(sourceId, source)
  233. if e != nil {
  234. err = errors.New("DeleteResourceData, Err: " + e.Error())
  235. return
  236. }
  237. } else {
  238. //判断是否存在,如果不存在就新增,存在就更新
  239. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  240. if e != nil {
  241. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  242. return
  243. }
  244. detail, e := models.GetYanxuanSpecialBySpecialId(sourceId)
  245. if e != nil {
  246. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  247. return
  248. }
  249. publishDate := time.Now().Format(utils.FormatDateTime)
  250. item := new(models.CygxResourceData)
  251. item.SourceId = sourceId
  252. item.Source = source
  253. item.PublishDate = publishDate
  254. item.CreateTime = time.Now()
  255. item.SearchTitle = detail.Title
  256. item.SearchContent = ""
  257. item.SearchOrderTime = publishDate
  258. item.ChartPermissionId = utils.CHART_PERMISSION_ID_YANXUAN
  259. if totalData == 0 {
  260. _, e := models.AddCygxResourceData(item)
  261. if e != nil {
  262. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  263. return
  264. }
  265. } else {
  266. e = models.UpdateResourceDataByItem(item)
  267. if e != nil {
  268. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  269. return
  270. }
  271. }
  272. }
  273. return
  274. }
  275. // 获取研选专栏用户信息
  276. func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (itemResp *models.SpecialAuthorCheckResp) {
  277. var err error
  278. defer func() {
  279. if err != nil {
  280. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
  281. }
  282. }()
  283. itemResp = new(models.SpecialAuthorCheckResp)
  284. var condition string
  285. condition += ` AND a.status = 1 `
  286. specialUser, e := models.GetYanxuanSpecialAuthor(user.UserId, user.UserId, condition)
  287. if e != nil && e.Error() != utils.ErrNoRow() {
  288. err = errors.New("GetYanxuanSpecialAuthor, Err: " + e.Error())
  289. return
  290. }
  291. if specialUser != nil {
  292. itemResp.IsAuthor = true
  293. itemResp.SpecialColumnId = specialUser.Id
  294. itemResp.HeadImg = specialUser.HeadImg
  295. //如果昵称 、专栏名称、简介 都不为空就表示信息完善
  296. if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
  297. itemResp.IsImproveInformation = true
  298. }
  299. }
  300. return
  301. }
  302. // 获取专栏用户最新的一篇文章信息
  303. func GetBestNewYanxuanSpecialByUserId(userIds []int) (mapResp map[int]*models.CygxYanxuanSpecialCenterAuthorResp) {
  304. lenArr := len(userIds)
  305. if lenArr == 0 {
  306. return
  307. }
  308. var err error
  309. defer func() {
  310. if err != nil {
  311. fmt.Println(err)
  312. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetBestNewYanxuanSpecialByUserId Err ", err, "userIds", userIds), 2)
  313. }
  314. }()
  315. var condition string
  316. var pars []interface{}
  317. condition += ` AND user_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND status = 3 GROUP BY user_id ORDER BY publish_time DESC`
  318. pars = append(pars, userIds)
  319. list, e := models.GetYanxuanSpecialListBycondition(condition, pars, 0, lenArr)
  320. if e != nil && e.Error() != utils.ErrNoRow() {
  321. err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
  322. return
  323. }
  324. mapResp = make(map[int]*models.CygxYanxuanSpecialCenterAuthorResp, 0)
  325. for _, v := range list {
  326. item := new(models.CygxYanxuanSpecialCenterAuthorResp)
  327. item.UserId = v.UserId
  328. item.Id = v.Id
  329. item.Title = v.Title
  330. item.PublishTime = v.PublishTime
  331. mapResp[v.UserId] = item
  332. }
  333. return
  334. }
  335. // 研选专栏审批记录
  336. func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, status int, reason string) {
  337. var err error
  338. defer func() {
  339. if err != nil {
  340. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
  341. }
  342. }()
  343. detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
  344. if e != nil {
  345. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  346. return
  347. }
  348. specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
  349. if e != nil {
  350. err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
  351. return
  352. }
  353. item := new(models.CygxYanxuanSpecialApprovalLog)
  354. item.UserId = detail.UserId
  355. item.Content = detail.Content
  356. item.Tags = detail.Tags
  357. item.ApprovalStatus = status
  358. item.ImgUrl = detail.ImgUrl
  359. item.DocUrl = detail.DocUrl
  360. item.Reason = reason
  361. item.Title = detail.Title
  362. item.Type = detail.Type
  363. item.CompanyTags = detail.CompanyTags
  364. item.IndustryTags = detail.IndustryTags
  365. item.YanxuanSpecialId = specialId
  366. item.AdminName = user.RealName
  367. item.AdminUserId = user.UserId
  368. item.SpecialName = specialAuthor.SpecialName
  369. item.NickName = specialAuthor.NickName
  370. item.CreateTime = time.Now()
  371. item.ModifyTime = time.Now()
  372. e = models.AddCygxYanxuanSpecialApprovalLog(item)
  373. if e != nil {
  374. err = errors.New("AddCygxYanxuanSpecialApprovalLog, Err: " + e.Error())
  375. return
  376. }
  377. return
  378. }
  379. // 更新文章收藏数量
  380. func UdpateYanxuanSpecialCollect(specialId int) {
  381. var err error
  382. defer func() {
  383. if err != nil {
  384. fmt.Println(err)
  385. go utils.SendAlarmMsg(fmt.Sprint("更新文章收藏数量失败,UdpateYanxuanSpecialCollect Err ", err, "specialId:", specialId), 2)
  386. }
  387. }()
  388. detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
  389. if e != nil {
  390. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  391. return
  392. }
  393. specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
  394. if e != nil {
  395. err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
  396. return
  397. }
  398. var condition string
  399. var pars []interface{}
  400. condition = " AND yanxuan_special_id = ? "
  401. pars = append(pars, specialId)
  402. //专栏被收藏的数量
  403. totalSpecial, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
  404. if e != nil {
  405. err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
  406. return
  407. }
  408. pars = make([]interface{}, 0)
  409. condition = " AND yanxuan_special_id IN (SELECT id FROM cygx_yanxuan_special AS a WHERE user_id = ?) "
  410. pars = append(pars, specialAuthor.UserId)
  411. //作者被收藏的数量
  412. totalAuthor, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
  413. if e != nil {
  414. err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
  415. return
  416. }
  417. //更新文章被收藏数量
  418. e = models.UpdateYanxuanSpecialarticleCollectNum(totalSpecial, specialId)
  419. if e != nil {
  420. err = errors.New("UpdateYanxuanSpecialarticleCollectNum, Err: " + e.Error())
  421. return
  422. }
  423. //更新作者文章被收藏数量
  424. e = models.UpdateYanxuanSpecialAuthorArticleCollectNum(totalAuthor, specialAuthor.UserId)
  425. if e != nil {
  426. err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNum, Err: " + e.Error())
  427. return
  428. }
  429. return
  430. }
  431. // 更新作者粉丝数量
  432. func UdpateYanxuanSpecialFansNum(specialUserIdId int) {
  433. var err error
  434. defer func() {
  435. if err != nil {
  436. fmt.Println(err)
  437. go utils.SendAlarmMsg(fmt.Sprint("更新作者粉丝数量失败,UdpateYanxuanSpecialFansNum Err ", err, "specialUserIdId", specialUserIdId), 2)
  438. }
  439. }()
  440. var condition string
  441. var pars []interface{}
  442. condition = " AND follow_user_id = ? "
  443. pars = append(pars, specialUserIdId)
  444. //作者粉丝数量
  445. total, e := models.GetCygxYanxuanSpecialFollowCount(condition, pars)
  446. if e != nil {
  447. err = errors.New("GetCygxYanxuanSpecialFollowCount, Err: " + e.Error())
  448. return
  449. }
  450. e = models.UpdateYanxuanSpecialAuthorFansNum(total, specialUserIdId)
  451. if e != nil {
  452. err = errors.New("UpdateYanxuanSpecialAuthorFansNum, Err: " + e.Error())
  453. return
  454. }
  455. return
  456. }
  457. // UdpateYanxuanSpecialauthorArticleNum 更新作者发布文章的数量
  458. func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
  459. var err error
  460. defer func() {
  461. if err != nil {
  462. fmt.Println(err)
  463. go utils.SendAlarmMsg(fmt.Sprint("更新作者发布文章的数量失败,UdpateYanxuanSpecialauthorArticleNum Err ", err, "userId", authoruserId), 2)
  464. }
  465. }()
  466. var condition string
  467. var pars []interface{}
  468. condition = ` AND status = 3 AND user_id = ? `
  469. pars = append(pars, authoruserId)
  470. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  471. if e != nil {
  472. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  473. return
  474. }
  475. e = models.UdpateYanxuanSpecialauthorArticleNum(total, authoruserId)
  476. if e != nil {
  477. err = errors.New("UdpateYanxuanSpecialauthorArticleNum, Err: " + e.Error())
  478. return
  479. }
  480. return
  481. }
  482. // GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏
  483. func GetYanxuanSpecialCollectMap(userId int) (mapResp map[int]bool, err error) {
  484. defer func() {
  485. if err != nil {
  486. go utils.SendAlarmMsg("GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏失败 ErrMsg:"+err.Error(), 2)
  487. }
  488. }()
  489. list, e := models.GetCygxYanxuanSpecialCollectByUser(userId)
  490. if e != nil && e.Error() != utils.ErrNoRow() {
  491. err = errors.New("根据用户ID获取所有文章收藏,GetCygxYanxuanSpecialCollectByUser " + e.Error())
  492. return
  493. }
  494. mapResp = make(map[int]bool, 0)
  495. if len(list) > 0 {
  496. for _, v := range list {
  497. mapResp[v.YanxuanSpecialId] = true
  498. }
  499. }
  500. return
  501. }
  502. // GetYanxuanSpecialDetailUserPower 处理用户查看研选专栏详情的权限
  503. func GetYanxuanSpecialDetailUserPower(user *models.WxUserItem) (havePower bool, err error) {
  504. if user.UserId == 0 {
  505. havePower = true
  506. return
  507. }
  508. //研选专栏是否需要校验权限
  509. detailChart, e := models.GetConfigByCode("yanxuan_special_power_check")
  510. if e != nil {
  511. err = errors.New("GetConfigByCode, Err: " + e.Error())
  512. return
  513. }
  514. //如果没有开启校验,直接返回true
  515. if detailChart.ConfigValue == "0" {
  516. havePower = true
  517. return
  518. }
  519. //判断用户是否开通了个人研选权限
  520. userId := user.UserId
  521. companyId := user.CompanyId
  522. //判断用户是否开通了个人研选权限
  523. mfyxUserPermissionTotal := GetMfyxUserPermissionTotal(userId)
  524. if mfyxUserPermissionTotal == 1 {
  525. havePower = true
  526. return
  527. }
  528. //用户是否持有有效卡片
  529. userCardTotal := GetCygxOrderUserCardTotal(user.Mobile)
  530. if userCardTotal == 1 {
  531. havePower = true
  532. return
  533. }
  534. //是否是权益客户
  535. raiCount, e := models.GetCompanyProductCount(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  536. if e != nil {
  537. err = errors.New("GetCompanyProductCount, Err: " + e.Error())
  538. return
  539. }
  540. if raiCount == 0 {
  541. return
  542. }
  543. productDetail, e := models.GetCompanyProductDetailByCompanyId(companyId, 2)
  544. if e != nil {
  545. err = errors.New("GetCompanyProductDetailByCompanyId, Err: " + e.Error())
  546. return
  547. }
  548. // 永续客户无法查看研选权限
  549. if productDetail.Status == utils.COMPANY_STATUS_FOREVER {
  550. return
  551. }
  552. permissionStr, e := models.GetCompanyPermission(companyId)
  553. if e != nil {
  554. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  555. return
  556. }
  557. if strings.Contains(permissionStr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  558. havePower = true
  559. return
  560. }
  561. return
  562. }
  563. // GetYanxuanSpecialMessageLikeMap 根据用户ID获取所有留言点赞的信息
  564. func GetYanxuanSpecialMessageLikeMap(userId int) (mapResp map[int]bool) {
  565. if userId < 1 {
  566. return
  567. }
  568. var err error
  569. defer func() {
  570. if err != nil {
  571. //fmt.Println(err)
  572. go utils.SendAlarmMsg("GetYanxuanSpecialMessageLikeMap 根据用户ID获取所有留言点赞的信息失败 ErrMsg:"+err.Error(), 2)
  573. }
  574. }()
  575. list, e := models.GetCygxYanxuanSpecialMessageLikeByUser(userId)
  576. if e != nil && e.Error() != utils.ErrNoRow() {
  577. err = errors.New("根据用户ID获取所有留言点赞,GetCygxYanxuanSpecialMessageLikeByUser " + e.Error())
  578. return
  579. }
  580. mapResp = make(map[int]bool, 0)
  581. if len(list) > 0 {
  582. for _, v := range list {
  583. mapResp[v.MessageId] = true
  584. }
  585. }
  586. return
  587. }
  588. // GetYanxuanSpecialLikeMap 根据用户ID获取所有专栏点赞的信息
  589. func GetYanxuanSpecialLikeMap(userId int) (mapResp map[int]bool) {
  590. if userId < 1 {
  591. return
  592. }
  593. var err error
  594. defer func() {
  595. if err != nil {
  596. //fmt.Println(err)
  597. go utils.SendAlarmMsg("GetYanxuanSpecialMessageLikeMap 根据用户ID获取所有留言点赞的信息失败 ErrMsg:"+err.Error(), 2)
  598. }
  599. }()
  600. list, e := models.GetCygxYanxuanSpecialSpecialLikeByUser(userId)
  601. if e != nil && e.Error() != utils.ErrNoRow() {
  602. err = errors.New("根据用户ID获取所有文章收藏,GetCygxYanxuanSpecialSpecialLikeByUser " + e.Error())
  603. return
  604. }
  605. mapResp = make(map[int]bool, 0)
  606. if len(list) > 0 {
  607. for _, v := range list {
  608. mapResp[v.YanxuanSpecialId] = true
  609. }
  610. }
  611. return
  612. }