123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- package service
- import (
- "app.yhyue.com/moapp/jybase/common"
- "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
- "fmt"
- IC "jyBXSubscribe/rpc/init"
- "jyBXSubscribe/rpc/type/bxsubscribe"
- "jyBXSubscribe/rpc/util"
- "regexp"
- )
- type PushSetService struct {
- UserId string //mongodb 的用户id
- PositionType int64
- EntId int64
- EntUserId int64
- BaseUserId int64
- AccountId int64
- PositionId int64
- }
- func (this *PushSetService) Update(item, setType, pushType string, ratemode, pushValue, interested int64, times []string) bool {
- set := map[string]interface{}{}
- switch setType {
- case "pushRoute":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
- }
- break
- case "a_times":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.a_times", item): times,
- fmt.Sprintf("o_pushset.%s.i_ratemode", item): common.IntAll(ratemode),
- }
- default:
- set = map[string]interface{}{
- "o_pushset.i_interested": common.IntAll(interested),
- }
- }
- update := false
- if this.PositionType == 0 {
- update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
- "$set": set,
- })
- } else {
- update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
- "$set": set,
- }, true, false)
- }
- return update
- }
- func (this *PushSetService) Find() map[string]*bxsubscribe.PushSet {
- pushSetMap := &map[string]interface{}{}
- if this.PositionType == 0 {
- pushSetMap, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1}`)
- } else {
- pushSetMap, _ = IC.Mgo.FindOne(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId})
- }
- pushSet := map[string]*bxsubscribe.PushSet{}
- //用户权益获取
- powerData := IC.Middleground.PowerCheckCenter.Check("10000", this.UserId, this.BaseUserId, this.AccountId, this.EntId, this.PositionType, this.PositionId)
- o_pushset := map[string]interface{}{}
- if pushSetMap != nil && len(*pushSetMap) > 0 {
- o_pushset, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
- }
- if o_pushset != nil {
- pushSet["interested"] = &bxsubscribe.PushSet{
- Interested: common.Int64All(o_pushset["i_interested"]),
- }
- }
- fool, o_subset := pushSetMontage(o_pushset["o_subset"], "o_subset", powerData)
- if fool {
- pushSet["o_subset"] = o_subset
- }
- fool, o_week_report := pushSetMontage(o_pushset["o_week_report"], "o_week_report", powerData)
- if fool {
- pushSet["o_week_report"] = o_week_report
- }
- fool, o_month_report := pushSetMontage(o_pushset["o_month_report"], "o_month_report", powerData)
- if fool {
- pushSet["o_month_report"] = o_month_report
- }
- fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"], "o_newproject_forecast", powerData)
- if fool {
- pushSet["o_newproject_forecast"] = o_newproject_forecast
- }
- fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"], "o_entinfo", powerData)
- if fool {
- pushSet["o_entinfo"] = o_entinfo
- }
- fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"], "o_follow_project", powerData)
- if fool {
- pushSet["o_follow_project"] = o_follow_project
- }
- fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"], "o_follow_ent", powerData)
- if fool {
- pushSet["o_follow_ent"] = o_follow_ent
- }
- return pushSet
- }
- func pushSetMontage(in interface{}, name string, powerData *pb.CheckResp) (bool, *bxsubscribe.PushSet) {
- data := common.ObjToMap(in)
- a_times := []string{}
- if !(data == nil || len(*data) == 0) {
- if (*data)["a_times"] != nil {
- a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
- }
- }
- returnData := &bxsubscribe.PushSet{}
- switch name {
- case "o_subset":
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: util.TimeMap[2],
- IApppush: 1,
- IWxpush: 1,
- IMailpush: 0,
- IRatemode: 2,
- IsWxShow: 1,
- }
- } else {
- returnData = &bxsubscribe.PushSet{
- ATimes: common.If((*data)["i_ratemode"] == nil, util.TimeMap[2], a_times).([]string),
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, 1, (*data)["i_wxpush"])),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 2, (*data)["i_ratemode"])),
- IsWxShow: 1,
- }
- }
- case "o_follow_project", "o_follow_ent":
- a_times = append(a_times, "实时推送")
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: 1,
- IMailpush: 0,
- IRatemode: 1,
- IsWxShow: 1,
- }
- } else {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, 1, (*data)["i_wxpush"])),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: 1,
- IsWxShow: 1,
- }
- }
- case "o_entinfo", "o_newproject_forecast":
- a_times = append(a_times, "实时推送")
- if powerData.Member.Status > 0 {
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: 1,
- IMailpush: 0,
- IRatemode: 1,
- IsWxShow: 0,
- }
- } else {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, 1, (*data)["i_wxpush"])),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: 1,
- IsWxShow: 0,
- }
- }
- } else {
- return false, nil
- }
- case "o_week_report", "o_month_report":
- power := make(map[int]bool)
- for _, v := range powerData.Member.MemberPowerList {
- power[common.IntAll(v)] = true
- }
- if powerData.Vip.Status > 0 || power[10] {
- if name == "o_week_report" {
- a_times = append(a_times, "每周推送 (周五:09:00)")
- } else {
- a_times = append(a_times, "每月推送 (28日09:00)")
- }
- IsWxShow := int64(0)
- if powerData.Vip.Status > 0 {
- IsWxShow = int64(1)
- }
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: 1,
- IMailpush: 0,
- IRatemode: 3,
- IsWxShow: IsWxShow,
- }
- } else {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: common.Int64All((*data)["i_apppush"]),
- IWxpush: common.Int64All((*data)["i_wxpush"]),
- IMailpush: common.Int64All((*data)["i_mailpush"]),
- IRatemode: 3,
- IsWxShow: IsWxShow,
- }
- }
- } else {
- return false, nil
- }
- }
- return true, returnData
- }
- func (this *PushSetService) SetUser(mail string) (bool, string) {
- var emailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
- if !emailPattern.MatchString(mail) {
- return false, "邮箱格式不正确"
- }
- set := map[string]interface{}{
- "o_pushset.s_email": mail,
- }
- update := false
- if this.PositionType == 0 {
- update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
- "$set": set,
- })
- } else {
- update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
- "$set": set,
- }, true, false)
- IC.MainMysql.UpdateOrDeleteBySql(`update entniche_user set mail=? where id=? and ent_id=?`, mail, this.EntUserId, this.EntId)
- }
- return update, ""
- }
|