123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430 |
- 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
- MgoUserId string
- }
- 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":
- if ratemode == 2 {
- if len(times) == 0 {
- return false
- }
- }
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.a_times", item): times,
- fmt.Sprintf("o_pushset.%s.i_ratemode", item): common.IntAll(ratemode),
- }
- case "message":
- set = map[string]interface{}{
- fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
- }
- default:
- set = map[string]interface{}{
- "o_pushset.i_interested": common.IntAll(interested),
- }
- }
- update := false
- if (setType == "message" && this.PositionType == 1) || 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{}{}
- o_msgPushSet := map[string]interface{}{}
- //
- ShowWx := false
- s_m_openid := ""
- pushSetMap, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1,"s_m_openid":1,"l_registedate",1}`)
- if pushSetMap != nil && len(*pushSetMap) > 0 {
- s_m_openid = common.InterfaceToStr((*pushSetMap)["s_m_openid"])
- o_msgPushSet, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
- }
- registedate := int64(0)
- if s_m_openid != "" {
- //微信是否关注处理
- subscribeList := &[]map[string]interface{}{}
- subscribeList, _ = IC.Mgo.Find(util.SUBSCRIBE, map[string]interface{}{"s_m_openid": s_m_openid}, `{"l_date":-1}`, `{"s_event":1"}`, true, -1, -1)
- if subscribeList != nil && len(*subscribeList) > 0 {
- s_event := common.InterfaceToStr((*subscribeList)[0]["s_event"])
- if s_event == "subscribe" {
- ShowWx = true
- }
- }
- }
- registedate = common.Int64All((*pushSetMap)["l_registedate"])
- if this.PositionType == 1 {
- 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.MgoUserId, 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(common.If(o_pushset["i_interested"] == nil, 1, common.Int64All(o_pushset["i_interested"]))),
- }
- } else {
- pushSet["interested"] = &bxsubscribe.PushSet{
- Interested: 1,
- }
- }
- //推送设置
- fool, o_subset := pushSetMontage(o_pushset["o_subset"], "o_subset", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_subset"] = o_subset
- }
- fool, o_week_report := pushSetMontage(o_pushset["o_week_report"], "o_week_report", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_week_report"] = o_week_report
- }
- fool, o_month_report := pushSetMontage(o_pushset["o_month_report"], "o_month_report", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_month_report"] = o_month_report
- }
- fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"], "o_newproject_forecast", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_newproject_forecast"] = o_newproject_forecast
- }
- //企业信息
- fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"], "o_entinfo", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_entinfo"] = o_entinfo
- }
- //项目关注
- fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"], "o_follow_project", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_follow_project"] = o_follow_project
- }
- //业主监控 P303
- fool, o_owner_monitor := pushSetMontage(o_pushset["o_owner_monitor"], "o_owner_monitor", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_owner_monitor"] = o_owner_monitor
- }
- //企业关注
- fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"], "o_follow_ent", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_follow_ent"] = o_follow_ent
- }
- //消息
- fool, o_msg_active := pushSetMontage(o_msgPushSet["o_msg_active"], "o_msg_active", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_active"] = o_msg_active
- }
- //消息服务
- fool, o_msg_service := pushSetMontage(o_msgPushSet["o_msg_service"], "o_msg_service", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_service"] = o_msg_service
- }
- //剑鱼学堂
- fool, o_msg_jyschool := pushSetMontage(o_msgPushSet["o_msg_jyschool"], "o_msg_jyschool", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_jyschool"] = o_msg_jyschool
- }
- fool, o_msg_business := pushSetMontage(o_msgPushSet["o_msg_business"], "o_msg_business", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_business"] = o_msg_business
- }
- //私信
- fool, o_msg_pending := pushSetMontage(o_msgPushSet["o_msg_pending"], "o_msg_business", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_pending"] = o_msg_pending
- }
- fool, o_msg_privateletter := pushSetMontage(o_msgPushSet["o_msg_privateletter"], "o_msg_privateletter", powerData, ShowWx, registedate)
- if fool {
- pushSet["o_msg_privateletter"] = o_msg_privateletter
- }
- return pushSet
- }
- func pushSetMontage(in interface{}, name string, powerData *pb.CheckResp, ShowWx bool, registedate int64) (bool, *bxsubscribe.PushSet) {
- data := common.ObjToMap(in)
- a_times := []string{}
- isMailShow := int64(1)
- isReturnMailShow := true
- if !(data == nil || len(*data) == 0) {
- if (*data)["a_times"] != nil {
- a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
- }
- }
- power := make(map[int]bool)
- for _, v := range powerData.Member.MemberPowerList {
- power[common.IntAll(v)] = true
- }
- returnData := &bxsubscribe.PushSet{}
- switch name {
- case "o_subset":
- if powerData.Free.IsFree {
- returnData = &bxsubscribe.PushSet{
- ATimes: []string{"每日上午、下午各推送1次"},
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
- IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: 2,
- IsWxShow: 1,
- INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
- }
- } else {
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: util.TimeMap[2],
- IApppush: 0,
- IApppushTip: 0,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- IMailpush: 0,
- IRatemode: 2,
- IsWxShow: 1,
- INomsgtip: 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, 0, (*data)["i_apppush"])),
- IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- 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,
- INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
- }
- if common.Int64All((*data)["i_ratemode"]) == 5 {
- returnData.ATimes = []string{"14:00"}
- }
- }
- }
- case "o_follow_project", "o_follow_ent":
- if powerData.Free.IsFree {
- returnData = &bxsubscribe.PushSet{
- ATimes: []string{"实时推送"},
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: 1,
- IsWxShow: 1,
- }
- } else if data == nil || len(*data) == 0 {
- a_times = append(a_times, "实时推送")
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- 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, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
- IsWxShow: 1,
- }
- }
- case "o_newproject_forecast":
- if powerData.Member.Status > 0 && power[9] {
- if data == nil || len(*data) == 0 {
- a_times = append(a_times, "实时推送")
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- 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, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
- IsWxShow: 0,
- }
- }
- } else {
- return false, nil
- }
- case "o_owner_monitor":
- //付费用户
- if !powerData.Free.IsFree {
- if data == nil || len(*data) == 0 {
- a_times = append(a_times, "实时推送")
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- 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, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
- IsWxShow: 1,
- }
- }
- } else {
- return false, nil
- }
- case "o_entinfo":
- if powerData.Member.Status > 0 && power[12] {
- if data == nil || len(*data) == 0 {
- a_times = append(a_times, "实时推送")
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- 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, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
- IsWxShow: 0,
- }
- }
- } else {
- return false, nil
- }
- case "o_week_report", "o_month_report":
- if powerData.Vip.Status > 0 || power[10] {
- if name == "o_week_report" {
- a_times = append(a_times, "每周推送 (周一 08:00)")
- } else {
- a_times = append(a_times, "每月推送 (1日 08:00)")
- }
- IsWxShow := int64(0)
- if powerData.Vip.Status > 0 {
- IsWxShow = int64(1)
- }
- if !power[10] {
- isMailShow = int64(0)
- }
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: a_times,
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- IMailpush: 0,
- IRatemode: 3,
- IsWxShow: IsWxShow,
- }
- } 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, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
- IRatemode: 3,
- IsWxShow: IsWxShow,
- }
- }
- } else {
- return false, nil
- }
- case "o_msg_active", "o_msg_service", "o_msg_jyschool", "o_msg_privateletter", "o_msg_business", "o_msg_pending":
- isReturnMailShow = false
- var isWXShow int64
- isWXShow = 1
- if name == "o_msg_active" {
- isWXShow = 0
- }
- iApppush := int64(0)
- iWxpush := int64(0)
- if registedate > IC.C.Registedate {
- iApppush = 1
- if ShowWx {
- iWxpush = 1
- }
- }
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- IApppush: iApppush,
- IWxpush: iWxpush,
- IsWxShow: isWXShow,
- }
- } else {
- returnData = &bxsubscribe.PushSet{
- IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, iApppush, (*data)["i_apppush"])),
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, iWxpush, (*data)["i_wxpush"])),
- IsWxShow: isWXShow,
- }
- }
- }
- if isReturnMailShow {
- returnData.IsMailShow = isMailShow
- }
- 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, ""
- }
|