cygx_yanxuan_special.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_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("更新研选专栏失败sourceId: ", sourceId, "ErrMsg", err.Error()), 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 := detail.PublishTime
  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) (isAuthor, isImproveInformation bool) {
  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. var condition string
  284. condition += ` AND a.status = 1 `
  285. specialUser, e := models.GetYanxuanSpecialAuthor(user.UserId, user.UserId, condition)
  286. if e != nil && e.Error() != utils.ErrNoRow() {
  287. err = errors.New("GetYanxuanSpecialAuthor, Err: " + e.Error())
  288. return
  289. }
  290. if specialUser != nil {
  291. isAuthor = true
  292. //如果昵称 、专栏名称、简介 都不为空就表示信息完善
  293. if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
  294. isImproveInformation = true
  295. }
  296. }
  297. return
  298. }
  299. // 获取专栏用户最新的一篇文章信息
  300. func GetBestNewYanxuanSpecialByUserId(userIds []int) (mapResp map[int]*models.CygxYanxuanSpecialCenterAuthorResp) {
  301. lenArr := len(userIds)
  302. if lenArr == 0 {
  303. return
  304. }
  305. var err error
  306. defer func() {
  307. if err != nil {
  308. fmt.Println(err)
  309. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetBestNewYanxuanSpecialByUserId Err ", err, "userIds", userIds), 2)
  310. }
  311. }()
  312. var condition string
  313. var pars []interface{}
  314. condition += ` AND a.publish_time = ( SELECT max( b.publish_time ) FROM cygx_yanxuan_special b WHERE a.user_id = b.user_id AND b.STATUS = 3 ) AND user_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND a.status = 3 GROUP BY user_id ORDER BY publish_time DESC`
  315. pars = append(pars, userIds)
  316. list, e := models.GetYanxuanSpecialListBycondition(condition, pars, 0, lenArr)
  317. if e != nil && e.Error() != utils.ErrNoRow() {
  318. err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
  319. return
  320. }
  321. mapResp = make(map[int]*models.CygxYanxuanSpecialCenterAuthorResp, 0)
  322. for _, v := range list {
  323. item := new(models.CygxYanxuanSpecialCenterAuthorResp)
  324. item.UserId = v.UserId
  325. item.Id = v.Id
  326. item.Title = v.Title
  327. item.PublishTime = v.PublishTime
  328. mapResp[v.UserId] = item
  329. }
  330. return
  331. }
  332. // 研选专栏审批记录
  333. func AddAddCygxYanxuanSpecialApprovalLog(user *models.WxUserItem, specialId, status int, reason string) {
  334. var err error
  335. defer func() {
  336. if err != nil {
  337. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
  338. }
  339. }()
  340. detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
  341. if e != nil {
  342. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  343. return
  344. }
  345. specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
  346. if e != nil {
  347. err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
  348. return
  349. }
  350. item := new(models.CygxYanxuanSpecialApprovalLog)
  351. item.UserId = detail.UserId
  352. item.Content = detail.Content
  353. item.Tags = detail.Tags
  354. item.ApprovalStatus = status
  355. item.ImgUrl = detail.ImgUrl
  356. item.DocUrl = detail.DocUrl
  357. item.Reason = reason
  358. item.Title = detail.Title
  359. item.Type = detail.Type
  360. item.CompanyTags = detail.CompanyTags
  361. item.IndustryTags = detail.IndustryTags
  362. item.YanxuanSpecialId = specialId
  363. item.AdminName = user.RealName
  364. item.AdminUserId = user.UserId
  365. item.SpecialName = specialAuthor.SpecialName
  366. item.NickName = specialAuthor.NickName
  367. item.CreateTime = time.Now()
  368. item.ModifyTime = time.Now()
  369. e = models.AddCygxYanxuanSpecialApprovalLog(item)
  370. if e != nil {
  371. err = errors.New("AddCygxYanxuanSpecialApprovalLog, Err: " + e.Error())
  372. return
  373. }
  374. return
  375. }
  376. // 更新文章收藏数量
  377. func UdpateYanxuanSpecialCollect(specialId int) {
  378. var err error
  379. defer func() {
  380. if err != nil {
  381. fmt.Println(err)
  382. go utils.SendAlarmMsg(fmt.Sprint("更新文章收藏数量失败,UdpateYanxuanSpecialCollect Err ", err, "specialId:", specialId), 2)
  383. }
  384. }()
  385. detail, e := models.GetYanxuanSpecialBySpecialId(specialId)
  386. if e != nil {
  387. err = errors.New("GetYanxuanSpecialBySpecialId, Err: " + e.Error())
  388. return
  389. }
  390. specialAuthor, e := models.GetCygxYanxuanSpecialAuthorByUserId(detail.UserId)
  391. if e != nil {
  392. err = errors.New("GetCygxYanxuanSpecialAuthorByUserId, Err: " + e.Error())
  393. return
  394. }
  395. var condition string
  396. var pars []interface{}
  397. condition = " AND yanxuan_special_id = ? "
  398. pars = append(pars, specialId)
  399. //专栏被收藏的数量
  400. totalSpecial, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
  401. if e != nil {
  402. err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
  403. return
  404. }
  405. pars = make([]interface{}, 0)
  406. condition = " AND yanxuan_special_id IN (SELECT id FROM cygx_yanxuan_special AS a WHERE user_id = ?) "
  407. pars = append(pars, specialAuthor.UserId)
  408. //作者被收藏的数量
  409. totalAuthor, e := models.GetCygxYanxuanSpecialCollectCount(condition, pars)
  410. if e != nil {
  411. err = errors.New("GetCygxYanxuanSpecialCollectCount, Err: " + e.Error())
  412. return
  413. }
  414. //更新文章被收藏数量
  415. e = models.UpdateYanxuanSpecialarticleCollectNum(totalSpecial, specialId)
  416. if e != nil {
  417. err = errors.New("UpdateYanxuanSpecialarticleCollectNum, Err: " + e.Error())
  418. return
  419. }
  420. //更新作者文章被收藏数量
  421. e = models.UpdateYanxuanSpecialAuthorArticleCollectNum(totalAuthor, specialAuthor.UserId)
  422. if e != nil {
  423. err = errors.New("UpdateYanxuanSpecialAuthorArticleCollectNum, Err: " + e.Error())
  424. return
  425. }
  426. return
  427. }
  428. // 更新作者粉丝数量
  429. func UdpateYanxuanSpecialFansNum(specialUserIdId int) {
  430. var err error
  431. defer func() {
  432. if err != nil {
  433. fmt.Println(err)
  434. go utils.SendAlarmMsg(fmt.Sprint("更新作者粉丝数量失败,UdpateYanxuanSpecialFansNum Err ", err, "specialUserIdId", specialUserIdId), 2)
  435. }
  436. }()
  437. var condition string
  438. var pars []interface{}
  439. condition = " AND follow_user_id = ? "
  440. pars = append(pars, specialUserIdId)
  441. //作者粉丝数量
  442. total, e := models.GetCygxYanxuanSpecialFollowCount(condition, pars)
  443. if e != nil {
  444. err = errors.New("GetCygxYanxuanSpecialFollowCount, Err: " + e.Error())
  445. return
  446. }
  447. e = models.UpdateYanxuanSpecialAuthorFansNum(total, specialUserIdId)
  448. if e != nil {
  449. err = errors.New("UpdateYanxuanSpecialAuthorFansNum, Err: " + e.Error())
  450. return
  451. }
  452. return
  453. }
  454. // UdpateYanxuanSpecialauthorArticleNum 更新作者发布文章的数量
  455. func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
  456. var err error
  457. defer func() {
  458. if err != nil {
  459. fmt.Println(err)
  460. go utils.SendAlarmMsg(fmt.Sprint("更新作者发布文章的数量失败,UdpateYanxuanSpecialauthorArticleNum Err ", err, "userId", authoruserId), 2)
  461. }
  462. }()
  463. var condition string
  464. var pars []interface{}
  465. condition = ` AND status = 3 AND user_id = ? `
  466. pars = append(pars, authoruserId)
  467. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  468. if e != nil {
  469. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  470. return
  471. }
  472. e = models.UdpateYanxuanSpecialauthorArticleNum(total, authoruserId)
  473. if e != nil {
  474. err = errors.New("UdpateYanxuanSpecialauthorArticleNum, Err: " + e.Error())
  475. return
  476. }
  477. return
  478. }
  479. // 获取作者列表朋友圈分享封面图
  480. func GetSpecialAuthorListMomentsImg() (imgUrl string) {
  481. var err error
  482. //time.Sleep(3*time.Second) // 有时候同时添加多个活动,延迟三秒
  483. defer func() {
  484. if err != nil {
  485. fmt.Println("err:", err)
  486. go utils.SendAlarmMsg("获取作者列表朋友圈分享封面图,GetSpecialAuthorListMomentsImg Err:"+err.Error(), 3)
  487. }
  488. }()
  489. configCode := "special_author_list_moments_img"
  490. detailConfig, e := models.GetConfigByCode(configCode)
  491. if e != nil {
  492. err = errors.New("GetConfigByCode 获取作者列表朋友圈分享封面图, Err: " + e.Error())
  493. return
  494. }
  495. imgUrl = detailConfig.ConfigValue
  496. fmt.Println(imgUrl)
  497. return
  498. }
  499. //func init() {
  500. // GetSpecialAuthorListMomentsImg()
  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. }