cygx_yanxuan_special.go 20 KB

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