getsubsomeinfologic.go 4.3 KB

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