cygx_yanxuan_special.go 20 KB

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