测试数据

This commit is contained in:
meixiongfeng 2023-05-22 19:08:34 +08:00
parent 58b0b993a8
commit dfb6f29b5c
6 changed files with 160 additions and 15 deletions

View File

@ -326,6 +326,8 @@ const ( //Rpc
RPC_ParkourCancelMatch core.Rpc_Key = "RPC_ParkourCancelMatch" //取消匹配
RPC_ParkourMatchSucc core.Rpc_Key = "RPC_ParkourMatchSucc" //匹配成功
RPC_ParkourTrusteeship core.Rpc_Key = "RPC_ParkourTrusteeship" //捕羊大赛托管
Rpc_ModuleCaravanSettlement core.Rpc_Key = "Rpc_ModuleCaravanSettlement" //商队比赛结算信息
)
// 事件类型定义处

View File

@ -37,6 +37,7 @@ type (
Imail interface {
SendMailByCid(session IUserSession, cid string, res []*pb.UserAssets) bool
SendNewMail(mail *pb.DBMailData, uid ...string) bool // 批量发送邮件 支持跨服
SendMailByUID(uid string, cid string, res []*cfg.Gameatn) bool
IReddot
}
//道具背包接口

View File

@ -14,6 +14,7 @@ const (
game_caravan_reward = "game_caravanreward.json"
game_caravan_thing = "game_caravanthing.json"
game_caravan_event = "game_caravanevent.json"
game_caravan_rank = "game_caravanrank.json"
)
///配置管理基础组件
@ -31,6 +32,7 @@ func (this *configureComp) Init(service core.IService, module core.IModule, comp
this.LoadConfigure(game_caravan_reward, cfg.NewGameCaravanReward)
this.LoadConfigure(game_caravan_thing, cfg.NewGameCaravanThing)
this.LoadConfigure(game_caravan_event, cfg.NewGameCaravanEvent)
this.LoadConfigure(game_caravan_rank, cfg.NewGameCaravanRank)
return
}
@ -158,3 +160,26 @@ func (this *configureComp) GetCityRefreshTime() int32 {
}
return 0
}
// 赛季结束获得奖励
func (this *configureComp) GetCaravanReward() (reward []*cfg.GameCaravanRewardData) {
if v, err := this.GetConfigure(game_caravan_reward); err == nil {
if configure, ok := v.(*cfg.GameCaravanReward); ok {
reward = configure.GetDataList()
}
} else {
log.Errorf("get GetCaravanInitCity conf err:%v", err)
}
return
}
func (this *configureComp) GetCaravanRank(index int32) (reward *cfg.GameCaravanRankData) {
if v, err := this.GetConfigure(game_caravan_rank); err == nil {
if configure, ok := v.(*cfg.GameCaravanRank); ok {
reward = configure.Get(index)
}
} else {
log.Errorf("get GetCaravanInitCity conf err:%v", err)
}
return
}

View File

@ -1,7 +1,9 @@
package caravan
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
@ -10,6 +12,10 @@ import (
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"math"
"time"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
type Caravan struct {
@ -17,7 +23,8 @@ type Caravan struct {
modelCaravan *modelCaravan
api *apiComp
configure *configureComp
service core.IService
service base.IRPCXService
mail comm.Imail
}
func NewModule() core.IModule {
@ -30,7 +37,18 @@ func (this *Caravan) GetType() core.M_Modules {
func (this *Caravan) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options)
this.service = service
this.service = service.(base.IRPCXService)
return
}
func (this *Caravan) Start() (err error) {
err = this.ModuleBase.Start()
var module core.IModule
this.mail = module.(comm.Imail)
if module, err = this.service.GetModule(comm.ModuleChat); err != nil {
return
}
this.service.RegisterFunctionName(string(comm.Rpc_ModuleCaravanSettlement), this.Rpc_ModuleCaravanSettlement)
return
}
@ -329,3 +347,31 @@ func (this *Caravan) TestFunc(session comm.IUserSession) {
IsBuy: true,
})
}
// 赛季结算
func (this *Caravan) Rpc_ModuleCaravanSettlement(ctx context.Context, args *pb.EmptyReq, reply *pb.EmptyResp) {
sTime := time.Now()
var rankIndex int32
if _data, err := this.modelCaravan.DB.Find(comm.TableUser, bson.M{}, options.Find().SetSort(bson.M{"merchantmoney": -1}).SetLimit(comm.MaxRankList)); err == nil {
for _data.Next(context.TODO()) {
rankIndex++
temp := &pb.DBUser{}
if err = _data.Decode(temp); err == nil {
c := this.configure.GetCaravanRank(rankIndex)
if c != nil {
this.mail.SendMailByUID(temp.Uid, "xxx", c.Reward) // 等配置
}
}
}
}
Query := bson.M{}
Query["merchantmoney"] = 0
_, err := this.modelCaravan.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true)
if err != nil {
this.Errorf("UpdateMany error: %v", err)
}
this.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds())
return
}

View File

@ -6,6 +6,7 @@ import (
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
"time"
@ -216,3 +217,63 @@ func (this *Mail) CheckMaxMail(session comm.IUserSession) bool {
}
return true
}
func (this *Mail) SendMailByUID(uid string, cid string, res []*cfg.Gameatn) bool {
// 查看玩家在不在线
// 获取额外配置
var reward []*pb.UserAssets
for _, v := range res {
if v.N > 0 {
reward = append(reward, &pb.UserAssets{
A: v.A,
T: v.T,
N: v.N,
})
}
}
conf := this.configure.GetMailConf(cid)
if conf == nil {
this.Errorf("can't found mail by cid: %s", cid)
return false
}
// 构建一个每日奖励邮件对象
mail := &pb.DBMailData{
ObjId: primitive.NewObjectID().Hex(),
Uid: uid,
CreateTime: uint64(configure.Now().Unix()),
DueTime: uint64(configure.Now().Unix() + 30*24*3600),
Items: reward,
Cid: cid,
Param: []string{},
}
mail.Check = false
mail.Reward = true
if len(mail.GetItems()) > 0 {
mail.Reward = false
}
if db.IsCross() { // 如果是跨服 则取本服的db
tag, _, b := utils.UIdSplit(uid)
if b {
if conn, err := db.ServerDBConn(tag); err == nil {
dbModel := db.NewDBModel(comm.TableMail, time.Hour, conn)
if _, err = dbModel.DB.InsertOne(comm.TableMail, mail); err != nil {
this.Errorf("InsertOne mail failed:%v", err)
}
}
}
} else {
err := this.modelMail.MailInsertUserMail(mail)
if err != nil {
this.Errorf("create mail failed :%v", err)
return false
}
}
// 通知玩家
//this.AddNewMailPush(session, mail)
return true
}

View File

@ -1,23 +1,22 @@
package timer
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"time"
"go_dreamfactory/pb"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/core/cbase"
"go_dreamfactory/lego/sys/cron"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
)
// 此组件废弃
type CaravanRank struct {
cbase.ModuleBase
modules.MCompModel
service core.IService
service base.IRPCXService
module *Timer
}
@ -27,24 +26,35 @@ func (this *CaravanRank) Init(service core.IService, module core.IModule, comp c
this.TableName = comm.TableCaravan
this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Timer)
this.service = service
this.service = service.(base.IRPCXService)
return
}
func (this *CaravanRank) Start() (err error) {
err = this.MCompModel.Start()
cron.AddFunc("30 10 1 * * ?", this.TimerSeason)
this.TimerSeason()
return
}
func (this *CaravanRank) TimerSeason() {
sTime := time.Now()
Query := bson.M{}
Query["merchantmoney"] = 0
_, err := this.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true)
if err != nil {
if _, err := this.service.RpcGo(context.Background(),
comm.Service_Worker,
string(comm.Rpc_ModuleCaravanSettlement),
pb.EmptyReq{},
nil,
); err != nil {
this.module.Errorln(err)
}
this.module.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds())
// sTime := time.Now()
// Query := bson.M{}
// Query["merchantmoney"] = 0
// _, err := this.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true)
// if err != nil {
// this.module.Errorf("UpdateMany error: %v", err)
// }
// this.module.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds())
}