123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- 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":
- 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),
- }
- 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{}{}
- //
- ShowWx := false
- s_m_openid := ""
- pushSetMap, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1,"s_m_openid":1}`)
- if pushSetMap != nil && len(*pushSetMap) > 0 {
- s_m_openid = common.InterfaceToStr((*pushSetMap)["s_m_openid"])
- }
- 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
- }
- }
- }
- 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.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(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)
- if fool {
- pushSet["o_subset"] = o_subset
- }
- fool, o_week_report := pushSetMontage(o_pushset["o_week_report"], "o_week_report", powerData, ShowWx)
- if fool {
- pushSet["o_week_report"] = o_week_report
- }
- fool, o_month_report := pushSetMontage(o_pushset["o_month_report"], "o_month_report", powerData, ShowWx)
- if fool {
- pushSet["o_month_report"] = o_month_report
- }
- fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"], "o_newproject_forecast", powerData, ShowWx)
- if fool {
- pushSet["o_newproject_forecast"] = o_newproject_forecast
- }
- fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"], "o_entinfo", powerData, ShowWx)
- if fool {
- pushSet["o_entinfo"] = o_entinfo
- }
- fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"], "o_follow_project", powerData, ShowWx)
- if fool {
- pushSet["o_follow_project"] = o_follow_project
- }
- fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"], "o_follow_ent", powerData, ShowWx)
- if fool {
- pushSet["o_follow_ent"] = o_follow_ent
- }
- return pushSet
- }
- func pushSetMontage(in interface{}, name string, powerData *pb.CheckResp, ShowWx bool) (bool, *bxsubscribe.PushSet) {
- data := common.ObjToMap(in)
- a_times := []string{}
- isMailShow := int64(1)
- 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: 1,
- IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
- IMailpush: 0,
- IRatemode: 2,
- IsWxShow: 1,
- }
- } else {
- if data == nil || len(*data) == 0 {
- returnData = &bxsubscribe.PushSet{
- ATimes: util.TimeMap[2],
- IApppush: 1,
- IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
- 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, 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,
- }
- if common.Int64All((*data)["i_ratemode"]) == 5 {
- returnData.ATimes = []string{"14:00"}
- }
- }
- }
- 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: 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: 1,
- IsWxShow: 1,
- }
- }
- case "o_newproject_forecast":
- a_times = append(a_times, "实时推送")
- if powerData.Member.Status > 0 && power[9] {
- 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: 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: 1,
- IsWxShow: 0,
- }
- }
- } else {
- return false, nil
- }
- case "o_entinfo":
- a_times = append(a_times, "实时推送")
- if powerData.Member.Status > 0 && power[12] {
- 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: 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: 1,
- 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, "每周推送 (周五 09:00)")
- } else {
- a_times = append(a_times, "每月推送 (28日 09: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
- }
- }
- 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, ""
- }
|