getsubsomeinfologic.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. "strings"
  10. "time"
  11. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc"
  12. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe"
  13. "github.com/zeromicro/go-zero/core/logx"
  14. )
  15. type GetSubSomeInfoLogic struct {
  16. ctx context.Context
  17. svcCtx *svc.ServiceContext
  18. logx.Logger
  19. }
  20. func NewGetSubSomeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubSomeInfoLogic {
  21. return &GetSubSomeInfoLogic{
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. Logger: logx.WithContext(ctx),
  25. }
  26. }
  27. const (
  28. SubFreeFlag = "fType"
  29. SubVipFlag = "vType"
  30. MemberFlag = "mType"
  31. EntnicheFlag = "eType"
  32. tsGuidefinished = 1
  33. )
  34. // 获取订阅推送相关信息
  35. func (l *GetSubSomeInfoLogic) GetSubSomeInfo(in *bxsubscribe.SomeInfoReq) (*bxsubscribe.SomeInfoResp, error) {
  36. resp := &bxsubscribe.SomeInfoResp{
  37. Data: &bxsubscribe.SomeInfo{
  38. HasKey: false,
  39. IsInTSguide: false,
  40. IsExpire: 0,
  41. IsOnTail: 0,
  42. IsPassCount: false,
  43. OtherFlag: false,
  44. IsRead: false,
  45. Industry: nil,
  46. UserId: "",
  47. Subsetinfo: &bxsubscribe.SubSetInfo{},
  48. },
  49. }
  50. baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64)
  51. accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
  52. positionType, _ := strconv.ParseInt(in.PositionType, 10, 64)
  53. positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
  54. entId, _ := strconv.ParseInt(in.EntId, 10, 64)
  55. user := IC.Compatible.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, baseUserId, accountId, entId, positionType, positionId)
  56. //logx.Info("userInfo:", userInfo)
  57. //P278 身份切换,切换企业 userId从代理header 获取的值是 职位id,所以改成用base_user_id 进行查user表信息
  58. //user, _ := model.NewSubscribePush(in.UserType).UserInfo(in.UserId)
  59. //
  60. //resp.Data.HasKey, resp.Data.Industry = model.GetKeySet(in.UserType, user, []string{})
  61. todayNum := time.Unix(time.Now().Unix(), 1).Format("20060102")
  62. if user != nil {
  63. resp.Data.HasKey = user.Vip.GetHasKey()
  64. switch in.UserType {
  65. case SubFreeFlag:
  66. resp.Data.HasKey = user.Free.FreeHasKey
  67. case SubVipFlag:
  68. resp.Data.HasKey = user.Vip.HasKey
  69. case MemberFlag:
  70. resp.Data.HasKey = user.Member.HasKey
  71. case EntnicheFlag:
  72. resp.Data.HasKey = user.Entniche.HasKey
  73. }
  74. //超级订阅
  75. if user.Vip.Status == 1 || common.IntAll(user.Vip.Status) == 2 {
  76. var threeRemind = int64(3 * 24 * 60 * 60)
  77. var twoRemind = int64(2 * 24 * 60 * 60)
  78. var oneRemind = int64(1 * 24 * 60 * 60)
  79. /*if (*user)["isread"] != nil {
  80. resp.Data.IsRead = (*user)["isread"].(bool)
  81. }*/
  82. resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 2000
  83. resp.Data.IsOnTail = user.Vip.Status
  84. _endtime := user.Vip.EndTime
  85. //是否到期
  86. if common.Int64All(_endtime)-time.Now().Unix() < threeRemind && common.Int64All(_endtime)-time.Now().Unix() >= twoRemind {
  87. resp.Data.IsExpire = 3 //即将到期
  88. } else if common.Int64All(_endtime)-time.Now().Unix() < twoRemind && common.Int64All(_endtime)-time.Now().Unix() >= oneRemind {
  89. resp.Data.IsExpire = 2 //即将到期
  90. } else if common.Int64All(_endtime)-time.Now().Unix() < oneRemind && common.Int64All(_endtime)-time.Now().Unix() >= 0 {
  91. resp.Data.IsExpire = 1 //即将到期
  92. }
  93. //判断首次用户是否推送的带有”其他“
  94. t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local)
  95. today_1 := t.Unix()
  96. today_2 := t.AddDate(0, 0, 1).Unix()
  97. //错误
  98. 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 {
  99. resp.Data.OtherFlag = true
  100. }
  101. } else {
  102. if user.Vip.Status <= 0 {
  103. resp.Data.IsExpire = 0
  104. } else {
  105. resp.Data.IsOnTail = user.Vip.Status
  106. }
  107. resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 150
  108. }
  109. // 查询订阅信息中的关键词和向导查询
  110. var field string
  111. switch in.UserType {
  112. case SubFreeFlag:
  113. field = "o_jy"
  114. case SubVipFlag:
  115. field = "o_vipjy"
  116. case MemberFlag:
  117. field = "o_member_jy"
  118. case EntnicheFlag:
  119. field = "o_entniche"
  120. }
  121. data := IC.Compatible.Select(in.UserId, fmt.Sprintf(`{"%s":1,"i_ts_guide":1,"l_registedate":1}`, field))
  122. if data != nil && len(*data) > 0 {
  123. subinfo, b := (*data)[field].(map[string]interface{})
  124. if b && subinfo != nil {
  125. if area, ok := subinfo["o_area"].(map[string]interface{}); ok {
  126. resp.Data.Subsetinfo.Area = common.MapToJson(area)
  127. }
  128. if district, ok := subinfo["o_district"].(map[string]interface{}); ok {
  129. resp.Data.Subsetinfo.District = common.MapToJson(district)
  130. }
  131. switch in.UserType {
  132. case SubFreeFlag:
  133. resp.Data.Subsetinfo.Areacount = 1 // 地区数量
  134. resp.Data.Subsetinfo.Key = freegetsubKey(subinfo)
  135. case SubVipFlag:
  136. o_buyset := common.ObjToMap(subinfo["o_buyset"])
  137. if o_buyset != nil {
  138. resp.Data.Subsetinfo.Areacount = common.Int64All((*o_buyset)["areacount"])
  139. }
  140. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  141. case MemberFlag:
  142. resp.Data.Subsetinfo.Areacount = -1
  143. if common.Int64All(subinfo["i_areacount"]) > 0 {
  144. resp.Data.Subsetinfo.Areacount = common.Int64All(subinfo["i_areacount"]) // 单省版大会员
  145. }
  146. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  147. case EntnicheFlag:
  148. resp.Data.Subsetinfo.Areacount = -1
  149. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  150. }
  151. }
  152. registedate := common.Int64All((*data)["l_registedate"])
  153. if in.UserType == SubFreeFlag || registedate > IC.C.GuideRegistedate {
  154. if common.Int64All((*data)["i_ts_guide"]) != tsGuidefinished { // 判断字段未完成
  155. resp.Data.IsInTSguide = true
  156. }
  157. }
  158. }
  159. }
  160. return resp, nil
  161. }
  162. // 处理订阅词
  163. func freegetsubKey(subinfo map[string]interface{}) (arr []string) {
  164. a_key, b := subinfo["a_key"].([]interface{})
  165. if !b {
  166. return
  167. }
  168. for i := 0; i < len(a_key); i++ {
  169. a_keyi := common.ObjToMap(a_key[i])
  170. if a_keyi != nil {
  171. a_keyiarr := (*a_keyi)["key"].([]interface{})
  172. arr = append(arr, common.ObjToString(a_keyiarr[0]))
  173. }
  174. }
  175. return arr
  176. }
  177. func paygetsubKey(subinfo map[string]interface{}) (arr []string) {
  178. a_items, b := subinfo["a_items"].([]interface{})
  179. if !b || len(a_items) == 0 {
  180. return
  181. }
  182. a_items0, b1 := a_items[0].(map[string]interface{})
  183. if !b1 {
  184. return
  185. }
  186. a_key, b3 := a_items0["a_key"].([]interface{})
  187. if a_key == nil || !b3 {
  188. return
  189. }
  190. for i := 0; i < len(a_key); i++ {
  191. a_keyi := common.ObjToMap(a_key[i])
  192. if a_keyi != nil {
  193. if a_keyiarr, ok := (*a_keyi)["key"].([]interface{}); ok {
  194. s := strings.Join(common.ObjArrToStringArr(a_keyiarr), " ")
  195. if a_appendkeyiarr, ok := (*a_keyi)["appendkey"].([]interface{}); ok {
  196. s += " " + strings.Join(common.ObjArrToStringArr(a_appendkeyiarr), " ")
  197. }
  198. arr = append(arr, s)
  199. }
  200. }
  201. }
  202. return
  203. }