123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "hongze/hongze_cygx/models"
- "hongze/hongze_cygx/models/company"
- "hongze/hongze_cygx/models/rai_serve"
- "hongze/hongze_cygx/utils"
- "time"
- )
- //权益服务统计
- // Redis对列消息中的结构体
- type RaiServeBillRedis struct {
- Content string `comment:"服务内容说明"`
- UserId int `comment:"用户ID"`
- ComapnyId int `comment:"公司ID"`
- SourceId int `comment:"来源ID"`
- Source string `comment:"来源"`
- RegisterPlatform int `comment:"来源 1小程序,2:网页"`
- ViewTime time.Time `comment:"浏览时间"`
- }
- // 权益服务统计添加到Redis队列中
- func CygxRaiServeBillRedisAdd(content, source string, userId, comapnyId, sourceId, registerPlatform int, viewTime time.Time) (err error) {
- defer func() {
- if err != nil {
- fmt.Println(err)
- msg := fmt.Sprint("source:", source, "userId:", userId, "sourceId", sourceId)
- go utils.SendAlarmMsg("权益服务统计添加到Redis队列中,写入Redis队列消息失败 CygxRaiServeBillRedisAdd:"+err.Error()+msg, 2)
- }
- }()
- log := &rai_serve.RaiServeBillRedis{Content: content, Source: source, UserId: userId, ComapnyId: comapnyId, SourceId: sourceId, RegisterPlatform: registerPlatform, ViewTime: viewTime}
- if utils.Re == nil {
- err := utils.Rc.LPush(utils.CYGX_RAI_SERVE_BILL_KEY, log)
- if err != nil {
- fmt.Println("RaiServeBillRedis LPush Err:" + err.Error())
- }
- }
- return
- }
- //func init() {
- // CygxRaiServeBillRedisAddReduce()
- //}
- // CygxRaiServeBillRedisAddReduce 处理权益服务统计
- func CygxRaiServeBillRedisAddReduce() (err error) {
- for {
- //SourceType int `description:"1:报名、 2:取消报名、3:活动编辑、4:活动发布,取消发布、5:活动到会。"`
- utils.Rc.Brpop(utils.CYGX_RAI_SERVE_BILL_KEY, func(b []byte) {
- var log rai_serve.RaiServeBillRedis
- if err := json.Unmarshal(b, &log); err != nil {
- fmt.Println("json unmarshal wrong!")
- go utils.SendAlarmMsg("处理权益服务统计Redis队列消息失败:"+err.Error()+string(b), 2)
- }
- //如果不是共享给 权益服务组的,则不处理
- taotalRaiServe, err := company.GetCompanyProductAaiServeCount(log.ComapnyId, utils.RAI_SERVE_GROUP_ID)
- if err != nil {
- go utils.SendAlarmMsg("处理权益服务统计Redis队列消息失败:GetCompanyProductAaiServeCount"+err.Error()+string(b), 2)
- }
- fmt.Println("taotaRaiServe", taotalRaiServe)
- if taotalRaiServe == 0 {
- return
- }
- //如果已经有记录了就不处理
- taotalSource, err := rai_serve.GetCygxRaiServeBillCountByUserAndSource(log.UserId, log.SourceId, log.Source)
- if err != nil {
- go utils.SendAlarmMsg("处理权益服务统计Redis队列消息失败:GetCygxRaiServeBillCountByUserAndSource"+err.Error()+string(b), 2)
- }
- if taotalSource > 0 {
- return
- }
- switch log.Source {
- case utils.CYGX_OBJ_YANXUANSPECIAL: //研选专栏阅读记录处理
- go RaiServeBillRedisAddReduceByYanxuanspecial(log)
- fmt.Println("研选专栏阅读记录处理")
- break
- default:
- fmt.Println(string(b))
- go utils.SendAlarmMsg("处理研选活动扣点处理Redis队列消息失败:"+string(b), 2)
- }
- })
- }
- }
- // 处理权益服务统计->研选阅读记录
- func RaiServeBillRedisAddReduceByYanxuanspecial(log rai_serve.RaiServeBillRedis) (err error) {
- source := log.Source
- userId := log.UserId
- sourceId := log.SourceId
- defer func() {
- if err != nil {
- go utils.SendAlarmMsg("用户报名活动扣点,处理Redis队列消息失败:"+err.Error()+fmt.Sprint("source:", source, "userId:", userId, "sourceId", sourceId), 2)
- }
- }()
- wxUser, e := models.GetWxUserItemByUserId(userId)
- if e != nil {
- err = errors.New("GetWxUserItemByUserId, Err: " + e.Error())
- return
- }
- item := new(rai_serve.CygxRaiServeBill)
- item.Content = log.Content
- item.ServeTypeId = 5
- item.ServeTypeName = "阅读uv"
- item.UserId = wxUser.UserId
- item.Mobile = wxUser.Mobile
- item.Email = wxUser.Email
- item.CompanyId = wxUser.CompanyId
- item.CompanyName = wxUser.CompanyName
- item.RealName = wxUser.RealName
- item.RegisterPlatform = log.RegisterPlatform
- item.ServeCount = 0.5
- if wxUser.IsMaker == 1 {
- item.IsKp = wxUser.IsMaker
- item.ServeCount = item.ServeCount * 3
- }
- item.SourceId = log.SourceId
- item.Source = log.Source
- item.CreateTime = time.Now()
- item.ViewTime = log.ViewTime
- err = rai_serve.AddCygxRaiServeBill(item)
- return
- }
|