package logic import ( "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/init" "context" "fmt" "strconv" "strings" "time" "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/internal/svc" "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXSubscribe/rpc/type/bxsubscribe" "github.com/zeromicro/go-zero/core/logx" ) type GetSubSomeInfoLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetSubSomeInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSubSomeInfoLogic { return &GetSubSomeInfoLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } const ( SubFreeFlag = "fType" SubVipFlag = "vType" MemberFlag = "mType" EntnicheFlag = "eType" tsGuideFinished = 1 ) // 获取订阅推送相关信息 func (l *GetSubSomeInfoLogic) GetSubSomeInfo(in *bxsubscribe.SomeInfoReq) (*bxsubscribe.SomeInfoResp, error) { resp := &bxsubscribe.SomeInfoResp{ Data: &bxsubscribe.SomeInfo{ HasKey: false, IsInTSguide: false, IsExpire: 0, IsOnTail: 0, IsPassCount: false, OtherFlag: false, IsRead: false, Industry: nil, UserId: "", Subsetinfo: &bxsubscribe.SubSetInfo{}, }, } baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64) accountId, _ := strconv.ParseInt(in.AccountId, 10, 64) positionType, _ := strconv.ParseInt(in.PositionType, 10, 64) positionId, _ := strconv.ParseInt(in.PositionId, 10, 64) entId, _ := strconv.ParseInt(in.EntId, 10, 64) user := IC.Compatible.Middleground.PowerCheckCenter.Check(in.AppId, in.UserId, baseUserId, accountId, entId, positionType, positionId) //logx.Info("userInfo:", userInfo) //P278 身份切换,切换企业 userId从代理header 获取的值是 职位id,所以改成用base_user_id 进行查user表信息 //user, _ := model.NewSubscribePush(in.UserType).UserInfo(in.UserId) // //resp.Data.HasKey, resp.Data.Industry = model.GetKeySet(in.UserType, user, []string{}) todayNum := time.Unix(time.Now().Unix(), 1).Format("20060102") if user != nil { resp.Data.HasKey = user.Vip.GetHasKey() switch in.UserType { case SubFreeFlag: resp.Data.HasKey = user.Free.FreeHasKey case SubVipFlag: resp.Data.HasKey = user.Vip.HasKey case MemberFlag: resp.Data.HasKey = user.Member.HasKey case EntnicheFlag: resp.Data.HasKey = user.Entniche.HasKey } //超级订阅 if user.Vip.Status == 1 || common.IntAll(user.Vip.Status) == 2 { var threeRemind = int64(3 * 24 * 60 * 60) var twoRemind = int64(2 * 24 * 60 * 60) var oneRemind = int64(1 * 24 * 60 * 60) /*if (*user)["isread"] != nil { resp.Data.IsRead = (*user)["isread"].(bool) }*/ resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 2000 resp.Data.IsOnTail = user.Vip.Status _endtime := user.Vip.EndTime //是否到期 if common.Int64All(_endtime)-time.Now().Unix() < threeRemind && common.Int64All(_endtime)-time.Now().Unix() >= twoRemind { resp.Data.IsExpire = 3 //即将到期 } else if common.Int64All(_endtime)-time.Now().Unix() < twoRemind && common.Int64All(_endtime)-time.Now().Unix() >= oneRemind { resp.Data.IsExpire = 2 //即将到期 } else if common.Int64All(_endtime)-time.Now().Unix() < oneRemind && common.Int64All(_endtime)-time.Now().Unix() >= 0 { resp.Data.IsExpire = 1 //即将到期 } //判断首次用户是否推送的带有”其他“ t, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local) today_1 := t.Unix() today_2 := t.AddDate(0, 0, 1).Unix() //错误 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 { resp.Data.OtherFlag = true } } else { if user.Vip.Status <= 0 { resp.Data.IsExpire = 0 } else { resp.Data.IsOnTail = user.Vip.Status } resp.Data.IsPassCount = redis.GetInt("pushcache_2_a", "oncecount_"+todayNum+"_"+in.UserId) >= 150 } // 查询订阅信息中的关键词和向导查询 var field string switch in.UserType { case SubFreeFlag: field = "o_jy" resp.Data.Subsetinfo.Areacount = 1 // 地区数量 case SubVipFlag: field = "o_vipjy" resp.Data.Subsetinfo.Areacount = 1 // 后面查到再修改 case MemberFlag: field = "o_member_jy" resp.Data.Subsetinfo.Areacount = -1 case EntnicheFlag: field = "o_entniche" resp.Data.Subsetinfo.Areacount = -1 } data := IC.Compatible.Select(in.UserId, fmt.Sprintf(`{"%s":1,"i_ts_guide":1,"l_registedate":1}`, field)) if data != nil && len(*data) > 0 { subinfo, b := (*data)[field].(map[string]interface{}) if b && subinfo != nil { if area, ok := subinfo["o_area"].(map[string]interface{}); ok { resp.Data.Subsetinfo.Area = common.MapToJson(area) } if district, ok := subinfo["o_district"].(map[string]interface{}); ok { resp.Data.Subsetinfo.District = common.MapToJson(district) } switch in.UserType { case SubFreeFlag: resp.Data.Subsetinfo.Key = freegetsubKey(subinfo) // 判断有没有省份订阅包 o_buyset_p, o_buyset_p_b := subinfo["o_buyset_p"].(map[string]interface{}) if o_buyset_p != nil && o_buyset_p_b { resp.Data.Subsetinfo.Areacount += common.Int64All(o_buyset_p["areacount"]) } case SubVipFlag: o_buyset := common.ObjToMap(subinfo["o_buyset"]) if o_buyset != nil { resp.Data.Subsetinfo.Areacount = common.Int64All((*o_buyset)["areacount"]) } resp.Data.Subsetinfo.Key = paygetsubKey(subinfo) case MemberFlag: if common.Int64All(subinfo["i_areacount"]) > 0 { resp.Data.Subsetinfo.Areacount = common.Int64All(subinfo["i_areacount"]) // 单省版大会员 } resp.Data.Subsetinfo.Key = paygetsubKey(subinfo) case EntnicheFlag: resp.Data.Subsetinfo.Key = paygetsubKey(subinfo) } } registedate := common.Int64All((*data)["l_registedate"]) if in.UserType == SubFreeFlag || registedate > IC.C.GuideRegistedate { if common.Int64All((*data)["i_ts_guide"]) != tsGuideFinished { // 判断字段未完成 resp.Data.IsInTSguide = true } } } } return resp, nil } // 处理订阅词 func freegetsubKey(subinfo map[string]interface{}) (arr []string) { a_key, b := subinfo["a_key"].([]interface{}) if !b { return } for i := 0; i < len(a_key); i++ { a_keyi := common.ObjToMap(a_key[i]) if a_keyi != nil { a_keyiarr := (*a_keyi)["key"].([]interface{}) arr = append(arr, common.ObjToString(a_keyiarr[0])) } } return arr } func paygetsubKey(subinfo map[string]interface{}) (arr []string) { a_items, b := subinfo["a_items"].([]interface{}) if !b || len(a_items) == 0 { return } a_items0, b1 := a_items[0].(map[string]interface{}) if !b1 { return } a_key, b3 := a_items0["a_key"].([]interface{}) if a_key == nil || !b3 { return } for i := 0; i < len(a_key); i++ { a_keyi := common.ObjToMap(a_key[i]) if a_keyi != nil { if a_keyiarr, ok := (*a_keyi)["key"].([]interface{}); ok { s := strings.Join(common.ObjArrToStringArr(a_keyiarr), " ") if a_appendkeyiarr, ok := (*a_keyi)["appendkey"].([]interface{}); ok { s += " " + strings.Join(common.ObjArrToStringArr(a_appendkeyiarr), " ") } arr = append(arr, s) } } } return }