getsubsomeinfologic.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/redis"
  5. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init"
  6. "context"
  7. "fmt"
  8. "strconv"
  9. "time"
  10. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc"
  11. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetSubSomeInfoLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewGetSubSomeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubSomeInfoLogic {
  20. return &GetSubSomeInfoLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. const (
  27. SubFreeFlag = "fType"
  28. SubVipFlag = "vType"
  29. MemberFlag = "mType"
  30. EntnicheFlag = "eType"
  31. tsGuidefinished = 1
  32. )
  33. // 获取订阅推送相关信息
  34. func (l *GetSubSomeInfoLogic) GetSubSomeInfo(in *bxsubscribe.SomeInfoReq) (*bxsubscribe.SomeInfoResp, error) {
  35. resp := &bxsubscribe.SomeInfoResp{
  36. Data: &bxsubscribe.SomeInfo{
  37. HasKey: false,
  38. IsInTSguide: false,
  39. IsExpire: 0,
  40. IsOnTail: 0,
  41. IsPassCount: false,
  42. OtherFlag: false,
  43. IsRead: false,
  44. Industry: nil,
  45. UserId: "",
  46. },
  47. }
  48. baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64)
  49. accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
  50. positionType, _ := strconv.ParseInt(in.PositionType, 10, 64)
  51. positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
  52. entId, _ := strconv.ParseInt(in.EntId, 10, 64)
  53. user := IC.Compatible.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, baseUserId, accountId, entId, positionType, positionId)
  54. //logx.Info("userInfo:", userInfo)
  55. //P278 身份切换,切换企业 userId从代理header 获取的值是 职位id,所以改成用base_user_id 进行查user表信息
  56. //user, _ := model.NewSubscribePush(in.UserType).UserInfo(in.UserId)
  57. //
  58. //resp.Data.HasKey, resp.Data.Industry = model.GetKeySet(in.UserType, user, []string{})
  59. todayNum := time.Unix(time.Now().Unix(), 1).Format("20060102")
  60. if user != nil {
  61. resp.Data.HasKey = user.Vip.GetHasKey()
  62. switch in.UserType {
  63. case SubFreeFlag:
  64. resp.Data.HasKey = user.Free.FreeHasKey
  65. case SubVipFlag:
  66. resp.Data.HasKey = user.Vip.HasKey
  67. case MemberFlag:
  68. resp.Data.HasKey = user.Member.HasKey
  69. case EntnicheFlag:
  70. resp.Data.HasKey = user.Entniche.HasKey
  71. }
  72. //超级订阅
  73. if user.Vip.Status == 1 || common.IntAll(user.Vip.Status) == 2 {
  74. var threeRemind = int64(3 * 24 * 60 * 60)
  75. var twoRemind = int64(2 * 24 * 60 * 60)
  76. var oneRemind = int64(1 * 24 * 60 * 60)
  77. /*if (*user)["isread"] != nil {
  78. resp.Data.IsRead = (*user)["isread"].(bool)
  79. }*/
  80. resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 2000
  81. resp.Data.IsOnTail = user.Vip.Status
  82. _endtime := user.Vip.EndTime
  83. //是否到期
  84. if common.Int64All(_endtime)-time.Now().Unix() < threeRemind && common.Int64All(_endtime)-time.Now().Unix() >= twoRemind {
  85. resp.Data.IsExpire = 3 //即将到期
  86. } else if common.Int64All(_endtime)-time.Now().Unix() < twoRemind && common.Int64All(_endtime)-time.Now().Unix() >= oneRemind {
  87. resp.Data.IsExpire = 2 //即将到期
  88. } else if common.Int64All(_endtime)-time.Now().Unix() < oneRemind && common.Int64All(_endtime)-time.Now().Unix() >= 0 {
  89. resp.Data.IsExpire = 1 //即将到期
  90. }
  91. //判断首次用户是否推送的带有”其他“
  92. t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  93. today_1 := t.Unix()
  94. today_2 := t.AddDate(0, 0, 1).Unix()
  95. //错误
  96. if IC.BaseServiceMysql.CountBySql("select count(1) as count from push.pushsubscribe where isvip =1 and userid =? and buyerclass=? and (date between ? and ? )", common.InterfaceToStr(in.NewUserId), 93, today_1, today_2) > 0 {
  97. resp.Data.OtherFlag = true
  98. }
  99. } else {
  100. if user.Vip.Status <= 0 {
  101. resp.Data.IsExpire = 0
  102. } else {
  103. resp.Data.IsOnTail = user.Vip.Status
  104. }
  105. resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 150
  106. }
  107. // 查询订阅信息中的关键词和向导查询
  108. var field string
  109. switch in.UserType {
  110. case SubFreeFlag:
  111. field = "o_jy"
  112. case SubVipFlag:
  113. field = "o_vipjy"
  114. case MemberFlag:
  115. field = "o_member_jy"
  116. case EntnicheFlag:
  117. field = "o_entniche"
  118. }
  119. data := IC.Compatible.Select(in.UserId, fmt.Sprintf(`{"%s":1,"i_ts_guide":1,"l_registedate":1}`, field))
  120. if data != nil && len(*data) > 0 {
  121. subinfo, b := (*data)["o_jy"].(map[string]interface{})
  122. if b && subinfo != nil {
  123. resp.Data.Subsetinfo = common.MapToJson(subinfo)
  124. }
  125. registedate := common.Int64All((*data)["l_registedate"])
  126. if in.UserType == SubFreeFlag || registedate > IC.C.GuideRegistedate {
  127. if common.Int64All((*data)["i_ts_guide"]) != tsGuidefinished { // 判断字段未完成
  128. resp.Data.IsInTSguide = true
  129. }
  130. }
  131. }
  132. }
  133. return resp, nil
  134. }