cygx_yanxuan_special.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "time"
  9. )
  10. // SendReviewTemplateMsgAdmin 提交审核时给王芳,汪洋发消息
  11. func SendReviewTemplateMsgAdmin(specialId int) (err error) {
  12. defer func() {
  13. if err != nil {
  14. go utils.SendAlarmMsg("处理试用申请给王芳,汪洋发消息失败, ErrMsg: "+err.Error(), 3)
  15. }
  16. }()
  17. var configCode string
  18. //如果是研选的就推送给汪洋跟王芳,否则就推送给王芳
  19. configCode = utils.TPL_MSG_WANG_FANG_WANG_YANG
  20. cnf, e := models.GetConfigByCode(configCode)
  21. if e != nil {
  22. err = errors.New("GetConfigByCode, Err: " + e.Error() + configCode)
  23. return
  24. }
  25. openIdList, e := models.GetUserRecordListByMobile(4, cnf.ConfigValue)
  26. if e != nil && e.Error() != utils.ErrNoRow() {
  27. err = errors.New("GetUserRecordListByMobile, Err: " + e.Error() + cnf.ConfigValue)
  28. return err
  29. }
  30. specialItem, e := models.GetYanxuanSpecialItemById(specialId)
  31. if e != nil {
  32. err = errors.New("GetYanxuanSpecialFollowUserById, Err: " + e.Error())
  33. return
  34. }
  35. user, e := models.GetWxUserItemByUserId(specialItem.UserId)
  36. if e != nil {
  37. err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
  38. return err
  39. }
  40. var keyword1 string
  41. var keyword2 string
  42. var keyword3 string
  43. var keyword4 string
  44. var remark string
  45. keyword1 = specialItem.RealName + "【" + user.CompanyName + "】"
  46. keyword2 = user.Mobile
  47. keyword3 = time.Now().Format(utils.FormatDateTime)
  48. keyword4 = "研选专栏提交了内容待审核"
  49. openIdArr := make([]string, 0)
  50. for _, v := range openIdList {
  51. openIdArr = append(openIdArr, v.OpenId)
  52. }
  53. redirectUrl := ""
  54. redirectUrl = utils.WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL + strconv.Itoa(specialId)
  55. sendInfo := new(SendWxTemplate)
  56. sendInfo.Keyword1 = keyword1
  57. sendInfo.Keyword2 = keyword2
  58. sendInfo.Keyword3 = keyword3
  59. sendInfo.Keyword4 = keyword4
  60. sendInfo.Remark = remark
  61. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  62. sendInfo.RedirectUrl = redirectUrl
  63. sendInfo.RedirectTarget = 3
  64. sendInfo.Resource = strconv.Itoa(specialId)
  65. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  66. sendInfo.OpenIdArr = openIdArr
  67. err = PublicSendTemplateMsg(sendInfo)
  68. if err != nil {
  69. return
  70. }
  71. return
  72. }
  73. // 更新研选专栏 写入首页最新 cygx_resource_data 表
  74. func UpdateYanxuanSpecialResourceData(sourceId int) {
  75. var err error
  76. defer func() {
  77. if err != nil {
  78. go utils.SendAlarmMsg(fmt.Sprint("更新研选专栏失败ourceId: ", sourceId), 2)
  79. }
  80. }()
  81. var source = utils.CYGX_OBJ_YANXUANSPECIAL
  82. var condition string
  83. var pars []interface{}
  84. condition = ` AND status = 3 AND id = ? `
  85. pars = append(pars, sourceId)
  86. total, e := models.GetCygxYanxuanSpecialCount(condition, pars)
  87. if e != nil {
  88. err = errors.New("GetCygxYanxuanSpecialCount, Err: " + e.Error())
  89. return
  90. }
  91. //如果取消发布了就做删除处理
  92. if total == 0 {
  93. e = models.DeleteResourceData(sourceId, source)
  94. if e != nil {
  95. err = errors.New("DeleteResourceData, Err: " + e.Error())
  96. return
  97. }
  98. } else {
  99. //判断是否存在,如果不存在就新增,存在就更新
  100. totalData, e := models.GetCygxResourceDataBySourceAndIdCount(sourceId, source)
  101. if e != nil {
  102. err = errors.New("GetCygxReportSelectionBySourceAndId, Err: " + e.Error())
  103. return
  104. }
  105. publishDate := time.Now().Format(utils.FormatDateTime)
  106. item := new(models.CygxResourceData)
  107. item.SourceId = sourceId
  108. item.Source = source
  109. item.PublishDate = publishDate
  110. item.CreateTime = time.Now()
  111. if totalData == 0 {
  112. _, e := models.AddCygxResourceData(item)
  113. if e != nil {
  114. err = errors.New("AddCygxResourceData, Err: " + e.Error())
  115. return
  116. }
  117. } else {
  118. e = models.UpdateResourceDataByItem(item)
  119. if e != nil {
  120. err = errors.New("UpdateResourceDataByItem, Err: " + e.Error())
  121. return
  122. }
  123. }
  124. }
  125. return
  126. }
  127. // 获取研选专栏用户信息
  128. func GetYanxuanSpecialAuthorInfo(user *models.WxUserItem) (itemResp *models.SpecialAuthorCheckResp) {
  129. var err error
  130. defer func() {
  131. if err != nil {
  132. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetYanxuanSpecialAuthorInfo Err ", err, "userId", user.UserId), 2)
  133. }
  134. }()
  135. itemResp = new(models.SpecialAuthorCheckResp)
  136. var condition string
  137. condition += ` AND a.status = 1 `
  138. specialUser, e := models.GetYanxuanSpecialAuthor(user.UserId, user.UserId, condition)
  139. if e != nil && e.Error() != utils.ErrNoRow() {
  140. err = errors.New("GetYanxuanSpecialAuthor, Err: " + e.Error())
  141. return
  142. }
  143. if specialUser != nil {
  144. itemResp.IsAuthor = true
  145. itemResp.SpecialColumnId = specialUser.Id
  146. itemResp.HeadImg = specialUser.HeadImg
  147. //如果昵称 、专栏名称、简介 都不为空就表示信息完善
  148. if specialUser.SpecialName != "" && specialUser.Introduction != "" && specialUser.NickName != "" {
  149. itemResp.IsImproveInformation = true
  150. }
  151. }
  152. return
  153. }
  154. // 获取专栏用户最新的一篇文章信息
  155. func GetBestNewYanxuanSpecialByUserId(userIds []int) (mapResp map[int]*models.CygxYanxuanSpecialCenterAuthorResp) {
  156. lenArr := len(userIds)
  157. if lenArr == 0 {
  158. return
  159. }
  160. var err error
  161. defer func() {
  162. if err != nil {
  163. fmt.Println(err)
  164. go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户信息失败,GetBestNewYanxuanSpecialByUserId Err ", err, "userIds", userIds), 2)
  165. }
  166. }()
  167. var condition string
  168. var pars []interface{}
  169. condition += ` AND user_id IN (` + utils.GetOrmInReplace(lenArr) + `) AND status = 3 GROUP BY user_id ORDER BY publish_time DESC`
  170. pars = append(pars, userIds)
  171. list, e := models.GetYanxuanSpecialListBycondition(condition, pars, 0, lenArr)
  172. if e != nil && e.Error() != utils.ErrNoRow() {
  173. err = errors.New("GetYanxuanSpecialListBycondition, Err: " + e.Error())
  174. return
  175. }
  176. mapResp = make(map[int]*models.CygxYanxuanSpecialCenterAuthorResp, 0)
  177. for _, v := range list {
  178. item := new(models.CygxYanxuanSpecialCenterAuthorResp)
  179. item.UserId = v.UserId
  180. item.Id = v.Id
  181. item.Title = v.Title
  182. item.PublishTime = v.PublishTime
  183. mapResp[v.UserId] = item
  184. }
  185. return
  186. }