cygx_yanxuan_special.go 18 KB

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