diff --git a/modules/sys/module.go b/modules/sys/module.go index c1cb24dd3..3d22699e1 100644 --- a/modules/sys/module.go +++ b/modules/sys/module.go @@ -171,7 +171,10 @@ func (this *ModuleSys) GMOpenAllCondition(uid string) { return } for _, v := range opencfg.GetDataList() { - list.Cond[v.Id] = 2 + if v.ActivateType != 1 { // 跳过手动激活类型 + list.Cond[v.Id] = 2 + } + } this.modelSys.ChangeOpenCondData(uid, map[string]interface{}{ "cond": list.Cond, diff --git a/modules/timer/activity.go b/modules/timer/activity.go index b50fffa9a..0f6b4d457 100644 --- a/modules/timer/activity.go +++ b/modules/timer/activity.go @@ -53,7 +53,7 @@ func (this *Activity) Start() (err error) { return } timer := time.NewTicker(time.Second * 1) - this.LoadActivityData("") + this.LoadActivityData() go func() { locp: @@ -70,72 +70,63 @@ func (this *Activity) Start() (err error) { //cron.AddFunc("0 0 0 ? * MON", this.TimerSeason) return } - -func (this *Activity) LoadActivityData(id string) { - if id == "" { // 查所有的 - if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err == nil { - var ( - szEnd []string // 活动结束 - szStart []string // 有活动开启 - ) - this.hlock.Lock() - this.curActivity = make(map[pb.HdType]*pb.DBHuodong) - this.delActivity = make(map[pb.HdType]*pb.DBHuodong) - this.futureActivity = make(map[pb.HdType]*pb.DBHuodong) - defer this.hlock.Unlock() - for c.Next(context.Background()) { - hd := &pb.DBHuodong{} - if err = c.Decode(hd); err != nil { - this.module.Errorf("err:%v", err) - continue - } - if hd.Etime <= configure.Now().Unix() { - this.delActivity[hd.Itype] = hd - szEnd = append(szEnd, hd.Id) - } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { - this.curActivity[hd.Itype] = hd - szStart = append(szStart, hd.Id) - } else { - this.futureActivity[hd.Itype] = hd - } - } - if len(szEnd) > 0 { - this.NotifyActivityOver(szEnd) - } - if len(szStart) > 0 { - this.NotifyActivityStart(szStart) - } - } - } else { - var hd *pb.DBHuodong - if err := this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(&hd); err != nil { - return - } - if hd.Etime <= configure.Now().Unix() { // 活动结束 - this.NotifyActivityOver([]string{hd.Id}) - } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { - this.NotifyActivityStart([]string{hd.Id}) - } - this.hlock.Lock() - // 删除内存中 - if _, ok := this.curActivity[hd.Itype]; ok { - delete(this.curActivity, hd.Itype) - } - if _, ok := this.delActivity[hd.Itype]; ok { - delete(this.delActivity, hd.Itype) - } - if _, ok := this.futureActivity[hd.Itype]; ok { - delete(this.futureActivity, hd.Itype) - } - if hd.Etime <= configure.Now().Unix() { // 活动结束 - this.delActivity[hd.Itype] = hd - } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { - this.curActivity[hd.Itype] = hd - } else { - this.futureActivity[hd.Itype] = hd - } - defer this.hlock.Unlock() +func (this *Activity) ReLoadActivityData(id string) { + var hd *pb.DBHuodong + if err := this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(&hd); err != nil { + return } + if hd.Etime <= configure.Now().Unix() { // 活动结束 + this.NotifyActivityOver([]string{hd.Id}) + } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { + this.NotifyActivityStart([]string{hd.Id}) + } + this.hlock.Lock() + // 删除内存中 + if _, ok := this.curActivity[hd.Itype]; ok { + delete(this.curActivity, hd.Itype) + } + if _, ok := this.delActivity[hd.Itype]; ok { + delete(this.delActivity, hd.Itype) + } + if _, ok := this.futureActivity[hd.Itype]; ok { + delete(this.futureActivity, hd.Itype) + } + if hd.Etime <= configure.Now().Unix() { // 活动结束 + this.delActivity[hd.Itype] = hd + } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { + this.curActivity[hd.Itype] = hd + } else { + this.futureActivity[hd.Itype] = hd + } + defer this.hlock.Unlock() +} + +func (this *Activity) LoadActivityData() { + + if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err == nil { + + this.hlock.Lock() + this.curActivity = make(map[pb.HdType]*pb.DBHuodong) + this.delActivity = make(map[pb.HdType]*pb.DBHuodong) + this.futureActivity = make(map[pb.HdType]*pb.DBHuodong) + defer this.hlock.Unlock() + for c.Next(context.Background()) { + hd := &pb.DBHuodong{} + if err = c.Decode(hd); err != nil { + this.module.Errorf("err:%v", err) + continue + } + if hd.Etime <= configure.Now().Unix() { + this.delActivity[hd.Itype] = hd + } else if hd.Etime > configure.Now().Unix() && hd.Stime < configure.Now().Unix() { + this.curActivity[hd.Itype] = hd + } else { + this.futureActivity[hd.Itype] = hd + } + } + + } + } func (this *Activity) NotifyActivityOver(szEnd []string) { @@ -167,6 +158,7 @@ func (this *Activity) NotifyActivityStart(szStart []string) { this.module.Errorln(err) } } + func (this *Activity) CheckActivityData() { var ( szEnd []string // 活动结束 diff --git a/modules/timer/module.go b/modules/timer/module.go index 2042cda44..28f4eaae9 100644 --- a/modules/timer/module.go +++ b/modules/timer/module.go @@ -101,7 +101,7 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er // 重新加载活动数据 func (this *Timer) ReloadActivityData(id string) { - this.activity.LoadActivityData(id) + this.activity.ReLoadActivityData(id) } // 日志