getsubsomeinfologic.go 7.7 KB

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