活动优化
This commit is contained in:
parent
dc3039dad9
commit
6828f035aa
@ -518,8 +518,8 @@ const ( //Rpc
|
||||
|
||||
Rpc_Activity core.Rpc_Key = "Rpc_Activity"
|
||||
|
||||
Rpc_ActivityOver core.Rpc_Key = "Rpc_ActivityOver" //活动结束
|
||||
Rpc_ActivityStar core.Rpc_Key = "Rpc_ActivityStar" //活动开启
|
||||
Rpc_ActivityOver core.Rpc_Key = "Rpc_ActivityOver" //活动结束
|
||||
Rpc_ActivityStart core.Rpc_Key = "Rpc_ActivityStart" //活动开启
|
||||
|
||||
RPC_XXLOffLine core.Rpc_Key = "RPC_XXLOffLine" //三消离线
|
||||
|
||||
|
@ -586,10 +586,8 @@ type (
|
||||
}
|
||||
|
||||
IActivity interface {
|
||||
GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err error) // 通过活动id 获取活动信息
|
||||
GetAllHdInfo() (hdList map[pb.HdType]*pb.DBHuodong) // 获取所有活动信息
|
||||
GetHdInfoByItype(itype pb.HdType) (result *pb.DBHuodong, err error) //
|
||||
|
||||
// 庆典活动
|
||||
HDCelebration(session IUserSession, systemtype int32, bosstype int32) bool
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ func (this *apiComp) GetHdDataCheck(session comm.IUserSession, req *pb.ActivityG
|
||||
// 活动活动
|
||||
func (this *apiComp) GetHdData(session comm.IUserSession, req *pb.ActivityGetHdDataReq) (errdata *pb.ErrorData) {
|
||||
|
||||
result := this.module.GetHdData(session, req.Oid)
|
||||
result := this.module.GetHdData(session, req.Oid) // 不用
|
||||
session.SendMsg(string(this.module.GetType()), "gethddata", &pb.ActivityGetHdDataResp{
|
||||
Data: result,
|
||||
})
|
||||
|
@ -38,6 +38,7 @@ func (this *apiComp) GetReward(session comm.IUserSession, req *pb.ActivityGetRew
|
||||
}
|
||||
return
|
||||
}
|
||||
// 接口需要修改
|
||||
if activity, err = this.module.modelhdList.getHdListByHdId(req.Oid); err == nil {
|
||||
curTime := configure.Now().Unix()
|
||||
if activity.Stime > curTime || curTime > activity.Etime { //不在活动时间范围内
|
||||
|
@ -122,7 +122,7 @@ func (this *Activity) Start() (err error) {
|
||||
}
|
||||
}
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_ActivityOver), this.Rpc_ActivityOver)
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_ActivityStar), this.Rpc_ActivityStar)
|
||||
this.service.RegisterFunctionName(string(comm.Rpc_ActivityStart), this.Rpc_ActivityStart)
|
||||
|
||||
return
|
||||
}
|
||||
@ -197,12 +197,6 @@ func (this *Activity) GetHdInfoByItype(itype pb.HdType) (result *pb.DBHuodong, e
|
||||
return
|
||||
}
|
||||
|
||||
// 通过活动ID查找
|
||||
func (this *Activity) GetHdInfoByHdId(oid string) (result *pb.DBHuodong, err error) {
|
||||
result, err = this.modelhdList.getHdListByHdId(oid)
|
||||
return
|
||||
}
|
||||
|
||||
// 统计庆典活动完成情况
|
||||
func (this *Activity) HDCelebration(session comm.IUserSession, systemtype int32, bosstype int32) bool {
|
||||
bDouble := false // 是否开启双倍奖励
|
||||
@ -296,6 +290,7 @@ func (this *Activity) HDCelebration(session comm.IUserSession, systemtype int32,
|
||||
return bDouble
|
||||
}
|
||||
|
||||
// 接口废弃
|
||||
func (this *Activity) GetHdData(session comm.IUserSession, oids []string) (result []*pb.DBActivityData) {
|
||||
var (
|
||||
activity *pb.DBHuodong
|
||||
@ -355,9 +350,9 @@ func (this *Activity) GetHdData(session comm.IUserSession, oids []string) (resul
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Activity) Rpc_Activity(ctx context.Context, args string, reply *pb.EmptyResp) (err error) {
|
||||
this.Debug("Rpc_ActivityOver",
|
||||
log.Field{Key: "args", Value: args},
|
||||
func (this *Activity) Rpc_Activity(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.EmptyResp) (err error) {
|
||||
this.Debug("Rpc_Activity",
|
||||
log.Field{Key: "args", Value: req.Param1},
|
||||
)
|
||||
this.modelhdList.LoadActivityData()
|
||||
return
|
||||
@ -405,8 +400,8 @@ func (this *Activity) Rpc_ActivityOver(ctx context.Context, args *pb.RPCGeneralR
|
||||
|
||||
// 活动开启通知
|
||||
|
||||
func (this *Activity) Rpc_ActivityStar(ctx context.Context, args *pb.RPCGeneralReqB1, reply *pb.EmptyResp) (err error) {
|
||||
this.Debug("Rpc_ActivityStar",
|
||||
func (this *Activity) Rpc_ActivityStart(ctx context.Context, args *pb.RPCGeneralReqB1, reply *pb.EmptyResp) (err error) {
|
||||
this.Debug("Rpc_ActivityStart",
|
||||
log.Field{Key: "args", Value: args.String()},
|
||||
)
|
||||
var (
|
||||
@ -416,7 +411,7 @@ func (this *Activity) Rpc_ActivityStar(ctx context.Context, args *pb.RPCGeneralR
|
||||
|
||||
for _, v := range szOverActivity {
|
||||
hd := &pb.DBHuodong{}
|
||||
if err := this.modelhdList.DB.FindOne(core.SqlTable(this.modelhdList.TableName), bson.M{"_id": v}).Decode(hd); err != nil {
|
||||
if err := this.modelhdList.DB.FindOne(core.SqlTable(this.modelhdList.TableName), bson.M{"_id": v}).Decode(hd); err == nil {
|
||||
switch hd.Itype {
|
||||
case pb.HdType_HdTypeWarorder, pb.HdType_SupplyWarOrder, pb.HdType_MoondreamWarOrder:
|
||||
this.warorder.ActivityOpenNotice(hd)
|
||||
@ -443,3 +438,63 @@ func (this *Activity) Rpc_ActivityStar(ctx context.Context, args *pb.RPCGeneralR
|
||||
this.Debug("szOverActivity", log.Field{Key: "args", Value: szOverActivity})
|
||||
return
|
||||
}
|
||||
|
||||
// 通过活动类型获取活动信息
|
||||
func (this *Activity) GetHdDataByHdType(session comm.IUserSession, itype pb.HdType) (result []*pb.DBActivityData) {
|
||||
var (
|
||||
activity *pb.DBHuodong
|
||||
err error
|
||||
list *pb.DBActivityData
|
||||
)
|
||||
curTime := configure.Now().Unix()
|
||||
|
||||
if activity, err = this.GetHdInfoByItype(itype); err != nil {
|
||||
this.Errorln(err)
|
||||
return
|
||||
}
|
||||
if activity.Stime > curTime || curTime > activity.Etime { // 不在活动范围内数据不给活动记录数据
|
||||
return
|
||||
}
|
||||
id := activity.Id
|
||||
list, _ = this.modelhdData.getHddataByOid(session.GetUserId(), id)
|
||||
// 获取开服庆典活动
|
||||
if activity.Itype == pb.HdType_HdCelebration {
|
||||
if list, err = this.modelhdData.getHddataByOid(session.GetUserId(), id); err == nil {
|
||||
if list.Lasttime < configure.Now().Unix() || list.Val == 0 { // 不是今天重置
|
||||
list.Gotarr = make(map[int32]int32)
|
||||
update := make(map[string]interface{})
|
||||
|
||||
update["gotarr"] = list.Gotarr
|
||||
var maxday int32
|
||||
_days := this.configure.GetHDCelebrationData()
|
||||
for _, v := range _days { // 开启循环
|
||||
maxday += v
|
||||
}
|
||||
var pos int32
|
||||
_sub := int32((configure.Now().Unix() - activity.Stime) / (24 * 3600))
|
||||
|
||||
for index, v := range _days {
|
||||
find := false
|
||||
for i := 0; i < int(v); i++ {
|
||||
pos++
|
||||
if _sub%maxday+1 == pos {
|
||||
list.Val = int32(index) + 1 // 计算val 值
|
||||
update["val"] = list.Val
|
||||
find = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if find { // 找到剩余的天数
|
||||
list.Lasttime = activity.Stime + int64(_sub+pos%v+1)*24*3600
|
||||
update["lasttime"] = list.Lasttime
|
||||
break
|
||||
}
|
||||
}
|
||||
this.modelhdData.ModifyActivityList(session.GetUserId(), list.Id, update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = append(result, list)
|
||||
return
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ import (
|
||||
type Activity struct {
|
||||
cbase.ModuleBase
|
||||
modules.MCompModel
|
||||
service base.IRPCXService
|
||||
module *Timer
|
||||
cTimerObj *timewheel.Task
|
||||
closeSignal chan struct{}
|
||||
hlock sync.RWMutex
|
||||
activity map[pb.HdType]*pb.DBHuodong
|
||||
service base.IRPCXService
|
||||
module *Timer
|
||||
cTimerObj *timewheel.Task
|
||||
closeSignal chan struct{}
|
||||
hlock sync.RWMutex
|
||||
curActivity map[pb.HdType]*pb.DBHuodong // 正在进行的活动
|
||||
delActivity map[pb.HdType]*pb.DBHuodong // 已经过期的活动
|
||||
futureActivity map[pb.HdType]*pb.DBHuodong // 即将要开启的活动过期的活动
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
@ -71,105 +73,125 @@ func (this *Activity) Start() (err error) {
|
||||
|
||||
func (this *Activity) LoadActivityData(id string) {
|
||||
if id == "" { // 查所有的
|
||||
if c, err := this.DB.Find(core.SqlTable(this.TableName), bson.M{}); err != nil {
|
||||
return
|
||||
} else {
|
||||
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()
|
||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||
for c.Next(context.Background()) {
|
||||
hd := &pb.DBHuodong{}
|
||||
if err = c.Decode(hd); err != nil {
|
||||
this.module.Errorf("err:%v", err)
|
||||
continue
|
||||
}
|
||||
this.activity[hd.Itype] = hd
|
||||
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
|
||||
this.DB.FindOne(core.SqlTable(this.TableName), bson.M{"_id": id}).Decode(&hd)
|
||||
|
||||
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 this.activity == nil {
|
||||
this.activity = make(map[pb.HdType]*pb.DBHuodong)
|
||||
// 删除内存中
|
||||
if _, ok := this.curActivity[hd.Itype]; ok {
|
||||
delete(this.curActivity, hd.Itype)
|
||||
}
|
||||
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 _, ok := this.delActivity[hd.Itype]; ok {
|
||||
delete(this.delActivity, hd.Itype)
|
||||
}
|
||||
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)
|
||||
}
|
||||
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) NotifyActivityOver(szEnd []string) {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityOver),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "endActivity",
|
||||
Param2: szEnd,
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *Activity) NotifyActivityStart(szStart []string) {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityStart),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "startActivity",
|
||||
Param2: szStart,
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
}
|
||||
func (this *Activity) CheckActivityData() {
|
||||
var (
|
||||
szEnd []string // 活动结束
|
||||
szStar []string // 有活动开启
|
||||
szEnd []string // 活动结束
|
||||
szStart []string // 有活动开启
|
||||
)
|
||||
this.hlock.RLock()
|
||||
for _, v := range this.activity {
|
||||
this.hlock.Lock()
|
||||
defer this.hlock.Unlock()
|
||||
for _, v := range this.curActivity {
|
||||
if v.Etime == configure.Now().Unix() { // 有活动结束
|
||||
szEnd = append(szEnd, v.Id)
|
||||
}
|
||||
if v.Stime == configure.Now().Unix() { // 有活动结束
|
||||
szStar = append(szStar, v.Id)
|
||||
delete(this.curActivity, v.Itype)
|
||||
this.delActivity[v.Itype] = v
|
||||
}
|
||||
}
|
||||
for _, v := range this.futureActivity {
|
||||
if v.Stime >= configure.Now().Unix() { // 有活动结束
|
||||
szStart = append(szStart, v.Id)
|
||||
delete(this.futureActivity, v.Itype)
|
||||
this.curActivity[v.Itype] = v
|
||||
}
|
||||
}
|
||||
this.hlock.RUnlock()
|
||||
if len(szEnd) > 0 {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityOver),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "endActivity",
|
||||
Param2: szEnd,
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
this.NotifyActivityOver(szEnd)
|
||||
}
|
||||
if len(szStar) > 0 {
|
||||
if err := this.service.RpcCall(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_ActivityStar),
|
||||
pb.RPCGeneralReqB1{
|
||||
Param1: "starActivity",
|
||||
Param2: szStar,
|
||||
},
|
||||
nil,
|
||||
); err != nil {
|
||||
this.module.Errorln(err)
|
||||
}
|
||||
if len(szStart) > 0 {
|
||||
this.NotifyActivityStart(szStart)
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ func (this *UiGame) Init(service core.IService, module core.IModule, options cor
|
||||
return
|
||||
}
|
||||
this.service = service.(base.IRPCXService)
|
||||
this.hdlist = make(map[pb.HdType]*pb.DBHuodong)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -27,18 +27,19 @@ func (this *Api_Comp) ActivityNotify(c *engine.Context) {
|
||||
c.JSON(http.StatusOK, &Respond{Code: errdata.Code, Message: errdata.Message, Data: data})
|
||||
}()
|
||||
|
||||
if _, err = this.module.service.RpcGo(
|
||||
_, err = this.module.service.RpcGo(
|
||||
context.Background(),
|
||||
comm.Service_Worker,
|
||||
string(comm.Rpc_Activity),
|
||||
req.Id, nil); err != nil {
|
||||
pb.RPCGeneralReqA1{
|
||||
Param1: req.Id,
|
||||
},
|
||||
nil)
|
||||
if err != nil {
|
||||
this.module.Errorln(err)
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_RpcFuncExecutionError,
|
||||
Title: pb.ErrorCode_RpcFuncExecutionError.ToString(),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
errdata = &pb.ErrorData{
|
||||
Code: pb.ErrorCode_Success,
|
||||
Title: pb.ErrorCode_Success.ToString(),
|
||||
|
Loading…
Reference in New Issue
Block a user