活动开启通知
This commit is contained in:
parent
e3293d4313
commit
edc97360e5
@ -51,7 +51,8 @@ func (this *Activity) Start() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
timer := time.NewTicker(time.Second * 1)
|
timer := time.NewTicker(time.Second * 1)
|
||||||
this.LoadActivityData()
|
this.LoadActivityData("")
|
||||||
|
this.LoadActivityData("64ba8dc4510317d189b9624c")
|
||||||
go func() {
|
go func() {
|
||||||
locp:
|
locp:
|
||||||
for {
|
for {
|
||||||
@ -68,22 +69,64 @@ func (this *Activity) Start() (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Activity) LoadActivityData() {
|
func (this *Activity) LoadActivityData(id string) {
|
||||||
if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil {
|
if id == "" { // 查所有的
|
||||||
return
|
if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil {
|
||||||
} else {
|
return
|
||||||
this.hlock.Lock()
|
} else {
|
||||||
defer this.hlock.Unlock()
|
this.hlock.Lock()
|
||||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
defer this.hlock.Unlock()
|
||||||
for c.Next(context.Background()) {
|
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||||
hd := &pb.DBHuodong{}
|
for c.Next(context.Background()) {
|
||||||
if err = c.Decode(hd); err != nil {
|
hd := &pb.DBHuodong{}
|
||||||
this.module.Errorf("err:%v", err)
|
if err = c.Decode(hd); err != nil {
|
||||||
continue
|
this.module.Errorf("err:%v", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
this.activity[hd.Itype] = hd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var hd *pb.DBHuodong
|
||||||
|
this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(&hd)
|
||||||
|
|
||||||
|
this.hlock.Lock()
|
||||||
|
if this.activity == nil {
|
||||||
|
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||||
|
}
|
||||||
|
this.activity[hd.Itype] = hd
|
||||||
|
this.hlock.Unlock()
|
||||||
|
// rpc 通知
|
||||||
|
if configure.Now().Unix() <= hd.Etime && configure.Now().Unix() >= hd.Stime {
|
||||||
|
if err := this.service.RpcCall(
|
||||||
|
context.Background(),
|
||||||
|
comm.Service_Worker,
|
||||||
|
string(comm.Rpc_ActivityStar),
|
||||||
|
pb.RPCGeneralReqB1{
|
||||||
|
Param1: "starActivity",
|
||||||
|
Param2: []string{hd.Id},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if configure.Now().Unix() > hd.Etime {
|
||||||
|
if err := this.service.RpcCall(
|
||||||
|
context.Background(),
|
||||||
|
comm.Service_Worker,
|
||||||
|
string(comm.Rpc_ActivityOver),
|
||||||
|
pb.RPCGeneralReqB1{
|
||||||
|
Param1: "endActivity",
|
||||||
|
Param2: []string{hd.Id},
|
||||||
|
},
|
||||||
|
nil,
|
||||||
|
); err != nil {
|
||||||
|
this.module.Errorln(err)
|
||||||
}
|
}
|
||||||
this.activity[hd.Itype] = hd
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Activity) CheckActivityData() {
|
func (this *Activity) CheckActivityData() {
|
||||||
|
@ -98,8 +98,8 @@ func (this *Timer) getDBModelByUid(uid, tableName string) (model *db.DBModel, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 重新加载活动数据
|
// 重新加载活动数据
|
||||||
func (this *Timer) ReloadActivityData() {
|
func (this *Timer) ReloadActivityData(id string) {
|
||||||
this.activity.LoadActivityData()
|
this.activity.LoadActivityData(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 日志
|
// 日志
|
||||||
|
@ -45,5 +45,5 @@ func (this *Api_Comp) ActivityNotify(c *engine.Context) {
|
|||||||
Title: pb.ErrorCode_Success.ToString(),
|
Title: pb.ErrorCode_Success.ToString(),
|
||||||
}
|
}
|
||||||
// 通知更新活动
|
// 通知更新活动
|
||||||
this.module.modelweb.ReloadActivityData()
|
this.module.modelweb.ReloadActivityData(req.Id)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user