getsubsomeinfologic.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. resp.Data.Subsetinfo.Areacount = 1 // 地区数量
  115. case SubVipFlag:
  116. field = "o_vipjy"
  117. resp.Data.Subsetinfo.Areacount = 1 // 后面查到再修改
  118. case MemberFlag:
  119. field = "o_member_jy"
  120. resp.Data.Subsetinfo.Areacount = -1
  121. case EntnicheFlag:
  122. field = "o_entniche"
  123. resp.Data.Subsetinfo.Areacount = -1
  124. }
  125. data := IC.Compatible.Select(in.UserId, fmt.Sprintf(`{"%s":1,"i_ts_guide":1,"l_registedate":1}`, field))
  126. if data != nil && len(*data) > 0 {
  127. subinfo, b := (*data)[field].(map[string]interface{})
  128. if b && subinfo != nil {
  129. if area, ok := subinfo["o_area"].(map[string]interface{}); ok {
  130. resp.Data.Subsetinfo.Area = common.MapToJson(area)
  131. }
  132. if district, ok := subinfo["o_district"].(map[string]interface{}); ok {
  133. resp.Data.Subsetinfo.District = common.MapToJson(district)
  134. }
  135. switch in.UserType {
  136. case SubFreeFlag:
  137. resp.Data.Subsetinfo.Key = freegetsubKey(subinfo)
  138. // 判断有没有省份订阅包
  139. o_buyset_p, o_buyset_p_b := subinfo["o_buyset_p"].(map[string]interface{})
  140. if o_buyset_p != nil && o_buyset_p_b {
  141. areacount := common.Int64All(o_buyset_p["areacount"])
  142. if areacount > 0 {
  143. resp.Data.Subsetinfo.Areacount += areacount
  144. } else {
  145. resp.Data.Subsetinfo.Areacount = -1
  146. }
  147. if o_area_p, ok := subinfo["o_area_p"].(map[string]interface{}); ok {
  148. resp.Data.Subsetinfo.Area = common.MapToJson(o_area_p)
  149. }
  150. }
  151. case SubVipFlag:
  152. o_buyset := common.ObjToMap(subinfo["o_buyset"])
  153. if o_buyset != nil {
  154. resp.Data.Subsetinfo.Areacount = common.Int64All((*o_buyset)["areacount"])
  155. }
  156. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  157. case MemberFlag:
  158. if common.Int64All(subinfo["i_areacount"]) > 0 {
  159. resp.Data.Subsetinfo.Areacount = common.Int64All(subinfo["i_areacount"]) // 单省版大会员
  160. }
  161. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  162. case EntnicheFlag:
  163. resp.Data.Subsetinfo.Key = paygetsubKey(subinfo)
  164. }
  165. }
  166. registedate := common.Int64All((*data)["l_registedate"])
  167. if in.UserType == SubFreeFlag || registedate > IC.C.GuideRegistedate {
  168. if common.Int64All((*data)["i_ts_guide"]) != tsGuideFinished { // 判断字段未完成
  169. resp.Data.IsInTSguide = true
  170. }
  171. }
  172. }
  173. }
  174. return resp, nil
  175. }
  176. // 处理订阅词
  177. func freegetsubKey(subinfo map[string]interface{}) (arr []string) {
  178. a_key, b := subinfo["a_key"].([]interface{})
  179. if !b {
  180. return
  181. }
  182. for i := 0; i < len(a_key); i++ {
  183. a_keyi := common.ObjToMap(a_key[i])
  184. if a_keyi != nil {
  185. a_keyiarr := (*a_keyi)["key"].([]interface{})
  186. arr = append(arr, common.ObjToString(a_keyiarr[0]))
  187. }
  188. }
  189. return arr
  190. }
  191. func paygetsubKey(subinfo map[string]interface{}) (arr []string) {
  192. a_items, b := subinfo["a_items"].([]interface{})
  193. if !b || len(a_items) == 0 {
  194. return
  195. }
  196. a_items0, b1 := a_items[0].(map[string]interface{})
  197. if !b1 {
  198. return
  199. }
  200. a_key, b3 := a_items0["a_key"].([]interface{})
  201. if a_key == nil || !b3 {
  202. return
  203. }
  204. for i := 0; i < len(a_key); i++ {
  205. a_keyi := common.ObjToMap(a_key[i])
  206. if a_keyi != nil {
  207. if a_keyiarr, ok := (*a_keyi)["key"].([]interface{}); ok {
  208. s := strings.Join(common.ObjArrToStringArr(a_keyiarr), " ")
  209. if a_appendkeyiarr, ok := (*a_keyi)["appendkey"].([]interface{}); ok {
  210. s += " " + strings.Join(common.ObjArrToStringArr(a_appendkeyiarr), " ")
  211. }
  212. arr = append(arr, s)
  213. }
  214. }
  215. }
  216. return
  217. }