getsubsomeinfologic.go 3.8 KB

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