diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index 02ff0c90c..3efb1dd1f 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -55,7 +55,7 @@ func (r *Robot) Run() { //处理响应 go func() { - for { + for { var msg *pb.UserMessage = &pb.UserMessage{} _, data, err := r.ws.ReadMessage() if err != nil { @@ -81,8 +81,8 @@ type TestCase struct { rsp proto.Message enabled bool start time.Time - requested bool //请求标识 true已发 - print func(rsp proto.Message) + requested bool //请求标识 true已发 + print func(rsp proto.Message) //定义打印 } func (r *Robot) addBuilders(builders []*TestCase) { @@ -178,6 +178,8 @@ func (r *Robot) onUserLoaded() { //pack // r.RunPack() + //task + r.RunTask() } //注册账号 diff --git a/cmd/robot/task.go b/cmd/robot/task.go new file mode 100644 index 000000000..76be133cc --- /dev/null +++ b/cmd/robot/task.go @@ -0,0 +1,54 @@ +package robot + +import ( + "fmt" + "go_dreamfactory/comm" + "go_dreamfactory/modules/task" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +var ( + taskBuilders = []*TestCase{ + { + //list + Desc: "任务列表", + mainType: string(comm.ModuleTask), + subType: task.TaskSubTypeList, + req: &pb.TaskListReq{ + TaskTag: int32(comm.TASK_DAILY), + }, + rsp: &pb.TaskListResp{}, + print: func(rsp proto.Message) { + out := rsp.(*pb.TaskListResp) + for _, v := range out.List { + fmt.Printf("%v \n", v) + } + }, + enabled: true, + }, { + Desc: "领取任务奖励", + mainType: string(comm.ModuleTask), + subType: task.TaskSubTypeReceive, + req: &pb.TaskReceiveReq{ + TaskTag: int32(comm.TASK_DAILY), + Id: "62c5681374c83911207fa265", + }, + rsp: &pb.TaskReceiveResp{}, + // enabled: true, + }, { + mainType: string(comm.ModuleTask), + subType: "active", + req: &pb.TaskActiveReq{}, + rsp: &pb.TaskActiveResp{}, + // enabled: true, + }, + } +) + +//声明加入到构建器并发起请求 +func (r *Robot) RunTask() { + r.addBuilders(taskBuilders) + r.handleReq() +} diff --git a/cmd/robot/user.go b/cmd/robot/user.go index f96f1593a..e74b74ab6 100644 --- a/cmd/robot/user.go +++ b/cmd/robot/user.go @@ -14,10 +14,10 @@ var user_builders = []*TestCase{ mainType: string(comm.ModuleUser), subType: user.UserSubTypeCreate, req: &pb.UserCreateReq{ //设置请求参数 - NickName: "乐谷7422", + NickName: "乐谷70614", }, - rsp: &pb.UserCreateResp{}, - enabled: true, + rsp: &pb.UserCreateResp{}, + // enabled: true, }, { Desc: "添加资源", mainType: string(comm.ModuleUser), diff --git a/comm/const.go b/comm/const.go index ad19667b4..ca296aefd 100644 --- a/comm/const.go +++ b/comm/const.go @@ -86,7 +86,24 @@ const ( ) const ( - ResGold = "gold" //金币 - ResExp = "exp" //经验 - ResDiamonds = "diamonds" // 钻石 + ResGold = "gold" //金币 + ResExp = "exp" //经验 + ResDiamond = "diamond" //钻石 + ResTaskActive = "taskActive" //任务活跃度 +) + +type TaskType int32 + +const ( + TaskTypeUpEquip TaskType = 101 //任意装备升级 + TaskTypeGetHero TaskType = 102 //获取星级英雄 +) + +//任务标签:日常/周常/成就 +type TaskTag int32 + +const ( + TASK_DAILY TaskTag = 1 //每日任务 + TASK_WEEKLY TaskTag = 2 //周任务 + TASK_ACHIEVE TaskTag = 3 //成就 ) diff --git a/comm/imodule.go b/comm/imodule.go index abb0f66b8..bd95682cf 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -75,4 +75,15 @@ type ( // 检查能不能挑战该关卡 CheckChallengeChapter(stroyId int32, uid string, zhangjieID int32) (code pb.ErrorCode) } + //任务 + ITask interface { + //初始化用户任务 + InitTask(uid string, taskTag TaskTag) (code pb.ErrorCode) + //初始化 日常/周常/成就 + InitTaskAll(uid string) (code pb.ErrorCode) + //清空任务 + ResetTask(uid string, taskTag TaskTag) (code pb.ErrorCode) + //任务通知 + SendToTask(uid string, taskType TaskType, param *pb.TaskParam) (code pb.ErrorCode) + } ) diff --git a/go.mod b/go.mod index b9f0933ba..6deb63a2d 100644 --- a/go.mod +++ b/go.mod @@ -74,6 +74,7 @@ require ( github.com/hashicorp/serf v0.9.7 // indirect github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect + github.com/jinzhu/now v1.1.5 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/juju/ratelimit v1.0.1 // indirect github.com/julienschmidt/httprouter v1.3.0 // indirect diff --git a/go.sum b/go.sum index 7d40d401e..222a87f5b 100644 --- a/go.sum +++ b/go.sum @@ -367,6 +367,8 @@ github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c/go.mod github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 h1:IPJ3dvxmJ4uczJe5YQdrYB16oTJlGSC/OyZDqUk9xX4= github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869/go.mod h1:cJ6Cj7dQo+O6GJNiMx+Pa94qKj+TG8ONdKHgMNIyyag= github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= diff --git a/modules/modulebase.go b/modules/modulebase.go index 8b7173d48..f1f54d30d 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -29,6 +29,7 @@ type ModuleBase struct { ModuleItems comm.IItems //道具背包模块 ModuleHero comm.IHero //英雄模块 ModuleEquipment comm.IEquipment //装备模块 + ModuleTask comm.ITask //任务 } //模块初始化接口 @@ -61,10 +62,15 @@ func (this *ModuleBase) Start() (err error) { return } this.ModuleHero = module.(comm.IHero) - if module, err = this.service.GetModule(comm.ModuleEquipment); err == nil { + if module, err = this.service.GetModule(comm.ModuleEquipment); err != nil { return } this.ModuleEquipment = module.(comm.IEquipment) + + if module, err = this.service.GetModule(comm.ModuleTask); err != nil { + return + } + this.ModuleTask = module.(comm.ITask) return } diff --git a/modules/task/api.go b/modules/task/api.go index f640ee51c..e715fd789 100644 --- a/modules/task/api.go +++ b/modules/task/api.go @@ -1,11 +1,31 @@ package task import ( - "go_dreamfactory/lego/base" + "go_dreamfactory/lego/core" "go_dreamfactory/modules" ) +const ( + TaskSubTypeList = "list" //任务列表 + TaskSubTypeReceive = "receive" //领取 +) + type apiComp struct { modules.MCompGate - service base.IRPCXService + service core.IService + moduleTask *ModuleTask +} + +//组件初始化接口 +func (this *apiComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompGate.Init(service, module, comp, options) + this.moduleTask = module.(*ModuleTask) + this.service = service + return +} + +func (this *apiComp) Start() (err error) { + err = this.MCompGate.Start() + + return } diff --git a/modules/task/api_active.go b/modules/task/api_active.go new file mode 100644 index 000000000..e90001311 --- /dev/null +++ b/modules/task/api_active.go @@ -0,0 +1,19 @@ +package task + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//用于测试 + +func (this *apiComp) ActiveCheck(session comm.IUserSession, req *pb.TaskActiveReq) (code pb.ErrorCode) { + return +} + +func (this *apiComp) Active(session comm.IUserSession, req *pb.TaskActiveReq) (code pb.ErrorCode, data proto.Message) { + this.moduleTask.ModuleTask.SendToTask(session.GetUserId(), comm.TaskTypeGetHero, &pb.TaskParam{First: 5}) + return +} diff --git a/modules/task/api_list.go b/modules/task/api_list.go new file mode 100644 index 000000000..db81c1859 --- /dev/null +++ b/modules/task/api_list.go @@ -0,0 +1,35 @@ +package task + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + "go_dreamfactory/utils" + + "google.golang.org/protobuf/proto" +) + +func (this *apiComp) ListCheck(session comm.IUserSession, req *pb.TaskListReq) (code pb.ErrorCode) { + if req.TaskTag == 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +func (this *apiComp) List(session comm.IUserSession, req *pb.TaskListReq) (code pb.ErrorCode, data proto.Message) { + if code = this.ListCheck(session, req); code != pb.ErrorCode_Success { + return + } + rsp := &pb.TaskListResp{} + + defer func() { + err := session.SendMsg(string(this.moduleTask.GetType()), TaskSubTypeList, rsp) + if err != nil { + code = pb.ErrorCode_SystemError + } + utils.TraceFunc(session.GetUserId(), string(this.moduleTask.GetType()), TaskSubTypeList, req, rsp) + }() + + rsp.List = this.moduleTask.modelTask.getTaskList(session.GetUserId(), comm.TaskTag(req.TaskTag)) + + return +} diff --git a/modules/task/api_receive.go b/modules/task/api_receive.go new file mode 100644 index 000000000..47aea55e5 --- /dev/null +++ b/modules/task/api_receive.go @@ -0,0 +1,54 @@ +package task + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/pb" + "go_dreamfactory/utils" + + "google.golang.org/protobuf/proto" +) + +//领取 +func (this *apiComp) ReceiveCheck(session comm.IUserSession, req *pb.TaskReceiveReq) (code pb.ErrorCode) { + if req.TaskTag == 0 || req.Id == "" { + code = pb.ErrorCode_ReqParameterError + } + return +} + +func (this *apiComp) Receive(session comm.IUserSession, req *pb.TaskReceiveReq) (code pb.ErrorCode, data proto.Message) { + resp := &pb.TaskReceiveResp{} + defer func() { + err := session.SendMsg(string(this.moduleTask.GetType()), TaskSubTypeList, resp) + if err != nil { + code = pb.ErrorCode_SystemError + } + utils.TraceFunc(session.GetUserId(), string(this.moduleTask.GetType()), TaskSubTypeList, req, resp) + }() + userTask := this.moduleTask.modelTask.getUserTask(session.GetUserId(), comm.TaskTag(req.TaskTag), req.Id) + if userTask != nil { + conf, err := this.moduleTask.configure.getTaskById(userTask.TaskId) + if err != nil { + log.Errorf("get task config err:%v", err) + return + } + //奖励 + if code = this.moduleTask.CheckConsumeRes(session.GetUserId(), conf.Reword); code != pb.ErrorCode_Success { + return + } + + //更新用户领取状态 + update := map[string]interface{}{ + "received": 1, + } + if err := this.moduleTask.modelTask.modifyUserTask(session.GetUserId(), comm.TaskTag(conf.IdTag), userTask.Id, update); err != nil { + code = pb.ErrorCode_DBError + return + } + + resp.TaskId = userTask.TaskId + } + + return +} diff --git a/modules/task/config.go b/modules/task/config.go new file mode 100644 index 000000000..80cfe9c66 --- /dev/null +++ b/modules/task/config.go @@ -0,0 +1,131 @@ +package task + +import ( + "fmt" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" + "go_dreamfactory/modules" + cfg "go_dreamfactory/sys/configure/structs" + "sort" +) + +const ( + gameActiveReward = "game_activereward.json" + gameTaskRound = "game_taskround.json" +) + +type configureComp struct { + modules.MCompConfigure +} + +func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompConfigure.Init(service, module, comp, options) + this.LoadMultiConfigure(map[string]interface{}{ + gameTaskRound: cfg.NewGame_taskRound, + gameActiveReward: cfg.NewGame_activeReward, + }) + return +} + +//获取活跃度奖励配置 +func (this *configureComp) getActiveRewardCfg() (data *cfg.Game_activeReward, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameActiveReward); err != nil { + return + } else { + if data, ok = v.(*cfg.Game_activeReward); !ok { + err = fmt.Errorf("%T no is *cfg.Game_ActiveReward", v) + return + } + } + return +} + +//获取任务配置 +func (this *configureComp) getTaskRoundCfg() (data *cfg.Game_taskRound, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(gameTaskRound); err != nil { + return + } else { + if data, ok = v.(*cfg.Game_taskRound); !ok { + err = fmt.Errorf("%T no is *cfg.Game_taskRound", v) + return + } + } + return +} + +//根据taskId获取配置 +func (this *configureComp) getTaskById(taskId int32) (data *cfg.Game_taskRoundData, err error) { + cfg, err := this.getTaskRoundCfg() + if err != nil { + log.Errorf("%v", err) + return data, err + } + if cfg != nil { + data = cfg.GetDataMap()[taskId] + } + return +} + +//获取任务配置列表 +func (this *configureComp) getTaskList() (data []*cfg.Game_taskRoundData, err error) { + cfg, err := this.getTaskRoundCfg() + if err != nil { + log.Errorf("%v", err) + return data, err + } + if cfg != nil { + data = cfg.GetDataList() + } + return +} + +//根据任务类型获取任务列表 +func (this *configureComp) getTasks(taskType int32) (data []*cfg.Game_taskRoundData, err error) { + list, err := this.getTaskList() + if err != nil { + log.Errorf("%v", err) + return data, err + } + + for _, d := range list { + if d.TypeId == taskType { + data = append(data, d) + } + } + + return +} + +//任务列表 正序 +func (this *configureComp) getSortedTasks(taskType int32) (data []*cfg.Game_taskRoundData, err error) { + if data, err = this.getTasks(taskType); err != nil { + return nil, err + } + sort.SliceStable(data, func(i, j int) bool { + return data[i].IdList > data[j].IdList + }) + return +} + +//获取任务配置 条件 tasktag +func (this *configureComp) getTaskByTag(taskTag int32) (data []*cfg.Game_taskRoundData, err error) { + list, err := this.getTaskList() + if err != nil { + log.Errorf("%v", err) + return data, err + } + for _, d := range list { + if d.IdTag == taskTag { + data = append(data, d) + } + } + return +} diff --git a/modules/task/const.go b/modules/task/const.go new file mode 100644 index 000000000..29512d9ba --- /dev/null +++ b/modules/task/const.go @@ -0,0 +1,2 @@ +package task + diff --git a/modules/task/model_status.go b/modules/task/model_status.go new file mode 100644 index 000000000..29512d9ba --- /dev/null +++ b/modules/task/model_status.go @@ -0,0 +1,2 @@ +package task + diff --git a/modules/task/model_task.go b/modules/task/model_task.go index 0f73947ed..77b936ff3 100644 --- a/modules/task/model_task.go +++ b/modules/task/model_task.go @@ -1,20 +1,175 @@ package task import ( + "fmt" + "go_dreamfactory/comm" "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "go.mongodb.org/mongo-driver/bson/primitive" ) const ( //Redis - TableTask core.SqlTable = "task" //任务表 + TableTask core.SqlTable = "task" //每日任务表 ) type ModelTask struct { modules.MCompModel + moduleTask *ModuleTask } func (this *ModelTask) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.MCompModel.Init(service, module, comp, options) + this.moduleTask = module.(*ModuleTask) this.TableName = string(TableTask) return } + +func (this *ModelTask) swapKey(uid string, tag comm.TaskTag) string { + return fmt.Sprintf("%s_%v", uid, tag) +} + +//获取玩家任务列表 +func (this *ModelTask) getTaskList(uid string, taskTag comm.TaskTag) (list []*pb.DBTask) { + if err := this.GetList(this.swapKey(uid, taskTag), &list); err != nil { + log.Errorf("initTaskByTag err %v", err) + return + } + return +} + +//初始化任务 +func (this *ModelTask) initTaskByTag(uid string, taskTag comm.TaskTag) error { + taskList := this.getTaskList(uid, taskTag) + if len(taskList) > 0 { + return fmt.Errorf("clear data before init task") + } + if data, err := this.moduleTask.configure.getTaskByTag(int32(taskTag)); err == nil { + for _, v := range data { + objId := primitive.NewObjectID().Hex() + task := &pb.DBTask{ + Id: objId, + Uid: uid, + TaskId: v.Key, + Progress: v.ConditionSecond, + } + if err := this.AddList(this.swapKey(uid, taskTag), task.Id, task); err != nil { + log.Errorf("initTaskByTag addlists err %v", err) + return err + } + } + } + return nil +} + +//查询用户任务 +func (this *ModelTask) getUserTask(uid string, taskTag comm.TaskTag, taskId string) *pb.DBTask { + userTask := &pb.DBTask{} + if err := this.moduleTask.modelTask.GetListObj(this.swapKey(uid, taskTag), taskId, userTask); err != nil { + log.Errorf("getUserTask err:%v", err) + return nil + } + return userTask +} + +//检查活跃度 +func (this *ModelTask) checkActiveVal(uid string) error { + return nil +} + +//获取未完成的任务列表 +func (this *ModelTask) getUnFinishTaskList(uid string, taskTag comm.TaskTag) (list []*pb.DBTask) { + taskList := this.getTaskList(uid, taskTag) + for _, v := range taskList { + if v.Status == 0 { + list = append(list, v) + } + } + return +} + +//检查任务进度 返回未完成的 +func (this *ModelTask) checkTaskProgress(uid string, config *cfg.Game_taskRoundData) (*pb.DBTask, bool) { + taskList := this.getUnFinishTaskList(uid, comm.TaskTag(config.IdTag)) + for _, v := range taskList { + if config.Key == v.TaskId && v.Status == 0 { + return v, true + } + } + + return nil, false +} + +//更改用户任务 +func (this *ModelTask) modifyUserTask(uid string, taskTag comm.TaskTag, taskId string, data map[string]interface{}) error { + if err := this.ChangeList(this.swapKey(uid, taskTag), taskId, data); err != nil { + log.Errorf("err %v", err) + return err + } + return nil +} + +//任务处理 +func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam *pb.TaskParam) error { + //查询当前用户未完成的任务列表 + data, err := this.moduleTask.configure.getTasks(int32(taskType)) + if err != nil { + log.Errorf("taskHandle err %v", err) + return err + } + + for _, conf := range data { + //不满足限定条件 + if taskParam.First != conf.ConditionCondition { + continue + } + //检查进度,完成了执行处理器 + if v, ok := this.checkTaskProgress(uid, conf); ok { + if err := this.finishHandle(v, comm.TaskTag(conf.IdTag), conf); err != nil { + return err + } + + } + } + return nil +} + +//任务完成处理 +func (this *ModelTask) finishHandle(userTask *pb.DBTask, taskTag comm.TaskTag, config *cfg.Game_taskRoundData) error { + if userTask.Progress-1 < 0 { + return fmt.Errorf("uid %s task[%s] was finished", userTask.Uid, userTask.Id) + } + //修改玩家任务状态和进度 + update := map[string]interface{}{ + "progress": userTask.Progress - 1, + } + if userTask.Progress-1 == 0 { + update["status"] = 1 + } + + if err := this.modifyUserTask(userTask.Uid, taskTag, userTask.Id, update); err != nil { + log.Errorf("err %v", err) + return err + } + //修改玩家任务活跃度 成就没有活跃度 + if config.IdTag != int32(comm.TASK_ACHIEVE) { + this.moduleTask.ModuleUser.AddAttributeValue(userTask.Uid, comm.ResTaskActive, config.Active) + } + + return nil +} + +//清空任务 +func (this *ModelTask) clearTask(uid string, taskTag comm.TaskTag) error { + taskList := this.getTaskList(uid, taskTag) + for _, v := range taskList { + if err := this.moduleTask.modelTask.DelListlds(this.swapKey(uid, taskTag), v.Id); err != nil { + log.Errorf("uid: %v taskTag:%v err:%v", uid, taskTag, err) + return err + } + } + return nil +} diff --git a/modules/task/module.go b/modules/task/module.go index 50620b7ca..699bb8c7a 100644 --- a/modules/task/module.go +++ b/modules/task/module.go @@ -4,24 +4,28 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" + "go_dreamfactory/pb" "time" ) -type TaskModule struct { +type ModuleTask struct { modules.ModuleBase - modelTask *ModelTask - api *apiComp + modelTask *ModelTask + api *apiComp + configure *configureComp + lastDayTime int64 //上次日任务执行时间戳 + lastWeekTime int64 //上次周任务执行时间戳 } func NewModule() core.IModule { - return &TaskModule{} + return &ModuleTask{} } -func (this *TaskModule) GetType() core.M_Modules { +func (this *ModuleTask) GetType() core.M_Modules { return comm.ModuleTask } -func (this *TaskModule) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { +func (this *ModuleTask) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { err = this.ModuleBase.Init(service, module, options) go func() { @@ -33,16 +37,78 @@ func (this *TaskModule) Init(service core.IService, module core.IModule, options } } }() - return } -func (this *TaskModule) OnInstallComp() { +func (this *ModuleTask) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) this.modelTask = this.RegisterComp(new(ModelTask)).(*ModelTask) + this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } -func (this *TaskModule) update(t time.Time) { - +//模块启动接口 +func (this *ModuleTask) Start() (err error) { + err = this.ModuleBase.Start() + return +} + +func (this *ModuleTask) update(t time.Time) { + this.taskEveryDay(t) + this.taskWeekDay(t) +} + +//日任务 +func (this *ModuleTask) taskEveryDay(t time.Time) { + n := time.Now().Unix() + if t.Hour() == 4 && t.Minute() == 0 { + this.lastDayTime = n + } else { + this.lastDayTime = 0 + } +} + +//周任务 +func (this *ModuleTask) taskWeekDay(t time.Time) { + n := time.Now().Unix() + if int(t.Weekday()) == 1 { //周一 + if t.Hour() == 0 && t.Minute() == 0 { + this.lastWeekTime = n + } else { + this.lastWeekTime = 0 + } + } +} + +//初始化任务 +func (this *ModuleTask) InitTask(uid string, taskTag comm.TaskTag) (code pb.ErrorCode) { + if err := this.modelTask.initTaskByTag(uid, taskTag); err != nil { + code = pb.ErrorCode_TaskInit + } + return +} + +//初始化日常、周常、成就 +func (this *ModuleTask) InitTaskAll(uid string) (code pb.ErrorCode) { + this.InitTask(uid, comm.TASK_DAILY) + this.InitTask(uid, comm.TASK_WEEKLY) + this.InitTask(uid, comm.TASK_ACHIEVE) + return +} + +//重置任务 +func (this *ModuleTask) ResetTask(uid string, taskTag comm.TaskTag) (code pb.ErrorCode) { + if err := this.modelTask.clearTask(uid, taskTag); err != nil { + code = pb.ErrorCode_TaskReset + return + } + return this.InitTask(uid, taskTag) +} + +//任务处理 +func (this *ModuleTask) SendToTask(uid string, taskType comm.TaskType, taskPram *pb.TaskParam) (code pb.ErrorCode) { + if err := this.modelTask.taskHandle(uid, taskType, taskPram); err != nil { + code = pb.ErrorCode_TaskHandle + } + return } diff --git a/modules/user/api_create.go b/modules/user/api_create.go index 670156747..3dc76159e 100644 --- a/modules/user/api_create.go +++ b/modules/user/api_create.go @@ -76,5 +76,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c } } + //初始化任务 + this.module.ModuleTask.InitTaskAll(self.Uid) return } diff --git a/modules/user/api_login.go b/modules/user/api_login.go index 22c863321..5fb1c59e0 100644 --- a/modules/user/api_login.go +++ b/modules/user/api_login.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/sys/cache" + "go_dreamfactory/utils" "time" "go.mongodb.org/mongo-driver/mongo" @@ -52,14 +53,20 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod } } + var isNewUser bool if user == nil { //如果是新玩家,创建一条基础的数据,页面会引导进入创角页面 - user = &pb.DBUser{Sid: req.Sid, Binduid: req.Account} + user = &pb.DBUser{ + Sid: req.Sid, + Binduid: req.Account, + Lastloginip: session.GetIP(), + } err = this.module.modelUser.User_Create(user) if err != nil { log.Errorf("User_CreateUser err %v", err) return } + isNewUser = true } //bind user @@ -69,11 +76,6 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod return } - //set user other info - user.Logintime = time.Now().Unix() - user.Lastloginip = session.GetIP() - user.Createip = session.GetIP() - //缓存user session err = this.module.modelSession.Change(user.Uid, map[string]interface{}{ "uid": user.Uid, @@ -88,11 +90,33 @@ func (this *apiComp) Login(session comm.IUserSession, req *pb.UserLoginReq) (cod return } - //缓存user - err = this.module.modelUser.Add(user.Uid, user, cache.WithDisabledMgoLog()) - if err != nil { - code = pb.ErrorCode_DBError - return + if !isNewUser { + //set user other info + update := map[string]interface{}{ + "logintime": time.Now().Unix(), + "lastloginip": session.GetIP(), + } + + //缓存user + err = this.module.modelUser.Change(user.Uid, update) + if err != nil { + code = pb.ErrorCode_DBError + return + } + + if this.module.modelUser.isLoginFirst(user.Logintime) { + //清空日常 + if code = this.module.ModuleTask.ResetTask(user.Uid, comm.TASK_DAILY); code != pb.ErrorCode_Success { + return + } + //清周常 + if utils.IsAfterWeek(user.Logintime) { + if code = this.module.ModuleTask.ResetTask(user.Uid, comm.TASK_WEEKLY); code != pb.ErrorCode_Success { + return + } + } + } + } return diff --git a/modules/user/model_user.go b/modules/user/model_user.go index 843fe4339..90f7422f3 100644 --- a/modules/user/model_user.go +++ b/modules/user/model_user.go @@ -6,6 +6,7 @@ import ( "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/pb" + "go_dreamfactory/utils" "time" uuid "github.com/satori/go.uuid" @@ -51,12 +52,14 @@ func (this *ModelUser) NickNameIsExist(name string) bool { } func (this *ModelUser) User_Create(user *pb.DBUser) (err error) { + now := time.Now().Unix() _id := primitive.NewObjectID().Hex() user.Id = _id user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id) user.Uuid = uuid.NewV4().String() user.Lv = 1 //初始等级 - user.Ctime = time.Now().Unix() + user.Ctime = now + user.Logintime = now return this.Add(user.Uid, user) } @@ -74,3 +77,20 @@ func (this *ModelUser) GetUser(uid string) (user *pb.DBUser) { func (this *ModelUser) updateUserAttr(uid string, data map[string]interface{}) error { return this.Change(uid, data) } + +//是否今天首次登录 +func (this *ModelUser) isLoginFirst(timestamp int64) bool { + now := time.Now() + if timestamp == 0 || timestamp > now.Unix() { + log.Debugf("lastlogin time great now") + return false + } + tt := time.Unix(timestamp, 0) + if !utils.IsToday(timestamp) { + if tt.Before(now) { + return true + } + } + + return false +} diff --git a/modules/user/module.go b/modules/user/module.go index 9af3af765..134168a58 100644 --- a/modules/user/module.go +++ b/modules/user/module.go @@ -104,9 +104,26 @@ func (this *User) AddAttributeValue(uid string, attr string, add int32) (code pb } } update[comm.ResExp] = user.Exp + add + case comm.ResDiamond: + if add < 0 { + if user.Diamond+add < 0 { + code = pb.ErrorCode_ResNoEnough + return + } + } + update[comm.ResDiamond] = user.Diamond + add + case comm.ResTaskActive: + if add < 0 { + if user.TaskActive+add < 0 { + code = pb.ErrorCode_ResNoEnough + return + } + } + update[comm.ResTaskActive] = user.TaskActive + add } if err := this.modelUser.updateUserAttr(uid, update); err != nil { + log.Errorf("AddAttributeValue err:%v", err) code = pb.ErrorCode_DBError } return diff --git a/pb.bat b/pb.bat index 70023bb1f..9561bd4fa 100644 --- a/pb.bat +++ b/pb.bat @@ -17,4 +17,5 @@ protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\equipment\ protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\hero\*.proto protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\shop\*.proto protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\story\*.proto +protoc --proto_path=%SRC% --go_out=%TAR% --go_opt=paths=import %SRC%\task\*.proto pause \ No newline at end of file diff --git a/pb/comm.pb.go b/pb/comm.pb.go index dcac48fc8..00d712538 100644 --- a/pb/comm.pb.go +++ b/pb/comm.pb.go @@ -790,6 +790,53 @@ func (x *UserAssets) GetN() int32 { return 0 } +type TaskParam struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + First int32 `protobuf:"varint,1,opt,name=first,proto3" json:"first"` //限定条件 +} + +func (x *TaskParam) Reset() { + *x = TaskParam{} + if protoimpl.UnsafeEnabled { + mi := &file_comm_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskParam) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskParam) ProtoMessage() {} + +func (x *TaskParam) ProtoReflect() protoreflect.Message { + mi := &file_comm_proto_msgTypes[11] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskParam.ProtoReflect.Descriptor instead. +func (*TaskParam) Descriptor() ([]byte, []int) { + return file_comm_proto_rawDescGZIP(), []int{11} +} + +func (x *TaskParam) GetFirst() int32 { + if x != nil { + return x.First + } + return 0 +} + var File_comm_proto protoreflect.FileDescriptor var file_comm_proto_rawDesc = []byte{ @@ -876,12 +923,14 @@ var file_comm_proto_rawDesc = []byte{ 0x0a, 0x0a, 0x55, 0x73, 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x41, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x41, 0x12, 0x0c, 0x0a, 0x01, 0x54, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x01, 0x54, 0x12, 0x0c, 0x0a, 0x01, 0x4e, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x01, 0x4e, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, 0x6f, 0x41, 0x74, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x06, 0x0a, 0x02, - 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, 0x12, 0x07, 0x0a, - 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, 0x65, 0x64, 0x10, - 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, 0x5a, 0x04, 0x2e, - 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x01, 0x28, 0x05, 0x52, 0x01, 0x4e, 0x22, 0x21, 0x0a, 0x09, 0x54, 0x61, 0x73, 0x6b, 0x50, 0x61, + 0x72, 0x61, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x66, 0x69, 0x72, 0x73, 0x74, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x05, 0x66, 0x69, 0x72, 0x73, 0x74, 0x2a, 0x43, 0x0a, 0x12, 0x48, 0x65, 0x72, + 0x6f, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x06, 0x0a, 0x02, 0x48, 0x70, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x41, 0x74, 0x6b, 0x10, 0x01, + 0x12, 0x07, 0x0a, 0x03, 0x44, 0x65, 0x66, 0x10, 0x02, 0x12, 0x09, 0x0a, 0x05, 0x53, 0x70, 0x65, + 0x65, 0x64, 0x10, 0x03, 0x12, 0x08, 0x0a, 0x04, 0x43, 0x72, 0x69, 0x74, 0x10, 0x04, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -897,7 +946,7 @@ func file_comm_proto_rawDescGZIP() []byte { } var file_comm_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_comm_proto_msgTypes = make([]protoimpl.MessageInfo, 12) var file_comm_proto_goTypes = []interface{}{ (HeroAttributesType)(0), // 0: HeroAttributesType (*UserMessage)(nil), // 1: UserMessage @@ -911,18 +960,19 @@ var file_comm_proto_goTypes = []interface{}{ (*AgentCloseeReq)(nil), // 9: AgentCloseeReq (*NoticeUserCloseReq)(nil), // 10: NoticeUserCloseReq (*UserAssets)(nil), // 11: UserAssets - (*anypb.Any)(nil), // 12: google.protobuf.Any - (ErrorCode)(0), // 13: ErrorCode + (*TaskParam)(nil), // 12: TaskParam + (*anypb.Any)(nil), // 13: google.protobuf.Any + (ErrorCode)(0), // 14: ErrorCode } var file_comm_proto_depIdxs = []int32{ - 12, // 0: UserMessage.data:type_name -> google.protobuf.Any - 12, // 1: AgentMessage.Message:type_name -> google.protobuf.Any - 13, // 2: RPCMessageReply.Code:type_name -> ErrorCode - 12, // 3: RPCMessageReply.ErrorData:type_name -> google.protobuf.Any + 13, // 0: UserMessage.data:type_name -> google.protobuf.Any + 13, // 1: AgentMessage.Message:type_name -> google.protobuf.Any + 14, // 2: RPCMessageReply.Code:type_name -> ErrorCode + 13, // 3: RPCMessageReply.ErrorData:type_name -> google.protobuf.Any 1, // 4: RPCMessageReply.Reply:type_name -> UserMessage 1, // 5: AgentSendMessageReq.Reply:type_name -> UserMessage - 12, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any - 12, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any + 13, // 6: BatchMessageReq.Data:type_name -> google.protobuf.Any + 13, // 7: BroadCastMessageReq.Data:type_name -> google.protobuf.Any 8, // [8:8] is the sub-list for method output_type 8, // [8:8] is the sub-list for method input_type 8, // [8:8] is the sub-list for extension type_name @@ -1069,6 +1119,18 @@ func file_comm_proto_init() { return nil } } + file_comm_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskParam); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -1076,7 +1138,7 @@ func file_comm_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_comm_proto_rawDesc, NumEnums: 1, - NumMessages: 11, + NumMessages: 12, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 3880b336c..620a0533f 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -89,6 +89,10 @@ const ( // mainStory ErrorCode_StoryNotFindChapter ErrorCode = 1500 // 没有找到主线关卡信息 ErrorCode_StoryIDFailed ErrorCode = 1501 // 关卡ID 错误 + // task + ErrorCode_TaskInit ErrorCode = 1500 //初始化失败 + ErrorCode_TaskReset ErrorCode = 1501 //重置任务失败 + ErrorCode_TaskHandle ErrorCode = 1502 //任务处理失败 ) // Enum value maps for ErrorCode. @@ -154,6 +158,9 @@ var ( 1401: "EquipmentLvlimitReached", 1500: "StoryNotFindChapter", 1501: "StoryIDFailed", + 1500: "TaskInit", + 1501: "TaskReset", + 1502: "TaskHandle", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -216,6 +223,9 @@ var ( "EquipmentLvlimitReached": 1401, "StoryNotFindChapter": 1500, "StoryIDFailed": 1501, + "TaskInit": 1500, + "TaskReset": 1501, + "TaskHandle": 1502, } ) @@ -251,6 +261,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2a, 0xeb, 0x09, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xc8, 0x09, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, @@ -330,6 +341,15 @@ var file_errorcode_proto_rawDesc = []byte{ 0x64, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x10, 0xdc, 0x0b, 0x12, 0x12, 0x0a, 0x0d, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x49, 0x44, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0xdd, 0x0b, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x45, 0x71, 0x75, 0x69, 0x70, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x10, 0x9f, 0x0a, 0x12, 0x1e, + 0x0a, 0x19, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4f, 0x6e, 0x46, 0x6f, 0x75, + 0x6e, 0x64, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x10, 0xf8, 0x0a, 0x12, 0x1c, + 0x0a, 0x17, 0x45, 0x71, 0x75, 0x69, 0x70, 0x6d, 0x65, 0x6e, 0x74, 0x4c, 0x76, 0x6c, 0x69, 0x6d, + 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9, 0x0a, 0x12, 0x0d, 0x0a, 0x08, + 0x54, 0x61, 0x73, 0x6b, 0x49, 0x6e, 0x69, 0x74, 0x10, 0xdc, 0x0b, 0x12, 0x0e, 0x0a, 0x09, 0x54, + 0x61, 0x73, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x74, 0x10, 0xdd, 0x0b, 0x12, 0x0f, 0x0a, 0x0a, 0x54, + 0x61, 0x73, 0x6b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x10, 0xde, 0x0b, 0x42, 0x06, 0x5a, 0x04, + 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/proto/comm.proto b/pb/proto/comm.proto index e33218916..ba2de3d20 100644 --- a/pb/proto/comm.proto +++ b/pb/proto/comm.proto @@ -65,20 +65,27 @@ message BroadCastMessageReq { message AgentCloseeReq { string UserSessionId = 1; } //通知用户离线 -message NoticeUserCloseReq {string UserSessionId = 1; string UserId = 2; } +message NoticeUserCloseReq { + string UserSessionId = 1; + string UserId = 2; +} //英雄属性类型 -enum HeroAttributesType{ - Hp = 0; //血量 - Atk = 1; //攻击 - Def = 2; //防御 +enum HeroAttributesType { + Hp = 0; //血量 + Atk = 1; //攻击 + Def = 2; //防御 Speed = 3; //速度 - Crit = 4; //暴击 + Crit = 4; //暴击 } //用户资产数据 对标*cfg.Game_atn 数据结构 -message UserAssets{ - string A=1; - string T=2; - int32 N=3; +message UserAssets { + string A = 1; + string T = 2; + int32 N = 3; +} + +message TaskParam { + int32 first = 1; //限定条件 } \ No newline at end of file diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 40909bd47..6d903e756 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -73,4 +73,9 @@ enum ErrorCode { // mainStory StoryNotFindChapter = 1500; // 没有找到主线关卡信息 StoryIDFailed = 1501; // 关卡ID 错误 + + // task + TaskInit = 1500; //初始化失败 + TaskReset = 1501; //重置任务失败 + TaskHandle = 1502; //任务处理失败 } \ No newline at end of file diff --git a/pb/proto/task/task_db.proto b/pb/proto/task/task_db.proto new file mode 100644 index 000000000..76da8516d --- /dev/null +++ b/pb/proto/task/task_db.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +option go_package = ".;pb"; + +message DBTask { + string id = 1; //@go_tags(`bson:"_id"`) ID + string uid = 2; //@go_tags(`bson:"uid"`) 用户ID + int32 taskId = 3; //@go_tags(`bson:"taskId"`) 任务Id + int32 progress = 4; //@go_tags(`bson:"progress"`) 任务进度/完成次数 + int32 status = 5; //@go_tags(`bson:"status"`) 任务状态 默认0未完成 1已完成 + int32 received = 6; //@go_tags(`bson:"received"`) 领取状态 默认0未领取 1已领取 +} \ No newline at end of file diff --git a/pb/proto/task/task_msg.proto b/pb/proto/task/task_msg.proto new file mode 100644 index 000000000..03fb7cc9c --- /dev/null +++ b/pb/proto/task/task_msg.proto @@ -0,0 +1,24 @@ +syntax = "proto3"; +option go_package = ".;pb"; +import "task/task_db.proto"; + +//领取 +message TaskReceiveReq { + int32 taskTag = 1; //日常/周常/成就 + string id = 2; //任务唯一ID +} + +message TaskReceiveResp { + int32 taskId = 1; //任务配置ID +} + +//任务列表 +message TaskListReq { + int32 taskTag = 1; //日常/周常/成就 +} + +message TaskListResp { repeated DBTask list = 1; } + +//激活测试 +message TaskActiveReq {} +message TaskActiveResp {} \ No newline at end of file diff --git a/pb/proto/user/user_db.proto b/pb/proto/user/user_db.proto index 1e27beda4..ddc46f98e 100644 --- a/pb/proto/user/user_db.proto +++ b/pb/proto/user/user_db.proto @@ -27,4 +27,6 @@ message DBUser { bool created = 15; //@go_tags(`bson:"created"`) 创角 int32 lv = 16; //@go_tags(`bson:"lv"`) 等级 int32 vip = 17; //@go_tags(`bson:"vip"`) vip + int32 taskActive = 18; //@go_tags(`bson:"taskActive"`) 任务活跃度 + int32 diamond = 19; //@go_tags(`bson:"diamond"`) 钻石 } \ No newline at end of file diff --git a/pb/task_db.pb.go b/pb/task_db.pb.go new file mode 100644 index 000000000..be257bb50 --- /dev/null +++ b/pb/task_db.pb.go @@ -0,0 +1,188 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: task/task_db.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type DBTask struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + TaskId int32 `protobuf:"varint,3,opt,name=taskId,proto3" json:"taskId" bson:"taskId"` //任务Id + Progress int32 `protobuf:"varint,4,opt,name=progress,proto3" json:"progress" bson:"progress"` //任务进度/完成次数 + Status int32 `protobuf:"varint,5,opt,name=status,proto3" json:"status" bson:"status"` // 任务状态 默认0未完成 1已完成 + Received int32 `protobuf:"varint,6,opt,name=received,proto3" json:"received" bson:"received"` //领取状态 默认0未领取 1已领取 +} + +func (x *DBTask) Reset() { + *x = DBTask{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_db_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DBTask) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DBTask) ProtoMessage() {} + +func (x *DBTask) ProtoReflect() protoreflect.Message { + mi := &file_task_task_db_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use DBTask.ProtoReflect.Descriptor instead. +func (*DBTask) Descriptor() ([]byte, []int) { + return file_task_task_db_proto_rawDescGZIP(), []int{0} +} + +func (x *DBTask) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *DBTask) GetUid() string { + if x != nil { + return x.Uid + } + return "" +} + +func (x *DBTask) GetTaskId() int32 { + if x != nil { + return x.TaskId + } + return 0 +} + +func (x *DBTask) GetProgress() int32 { + if x != nil { + return x.Progress + } + return 0 +} + +func (x *DBTask) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +func (x *DBTask) GetReceived() int32 { + if x != nil { + return x.Received + } + return 0 +} + +var File_task_task_db_proto protoreflect.FileDescriptor + +var file_task_task_db_proto_rawDesc = []byte{ + 0x0a, 0x12, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x92, 0x01, 0x0a, 0x06, 0x44, 0x42, 0x54, 0x61, 0x73, 0x6b, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, + 0x64, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, + 0x67, 0x72, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x70, 0x72, 0x6f, + 0x67, 0x72, 0x65, 0x73, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, + 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_task_task_db_proto_rawDescOnce sync.Once + file_task_task_db_proto_rawDescData = file_task_task_db_proto_rawDesc +) + +func file_task_task_db_proto_rawDescGZIP() []byte { + file_task_task_db_proto_rawDescOnce.Do(func() { + file_task_task_db_proto_rawDescData = protoimpl.X.CompressGZIP(file_task_task_db_proto_rawDescData) + }) + return file_task_task_db_proto_rawDescData +} + +var file_task_task_db_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_task_task_db_proto_goTypes = []interface{}{ + (*DBTask)(nil), // 0: DBTask +} +var file_task_task_db_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_task_task_db_proto_init() } +func file_task_task_db_proto_init() { + if File_task_task_db_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_task_task_db_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DBTask); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_task_task_db_proto_rawDesc, + NumEnums: 0, + NumMessages: 1, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_task_task_db_proto_goTypes, + DependencyIndexes: file_task_task_db_proto_depIdxs, + MessageInfos: file_task_task_db_proto_msgTypes, + }.Build() + File_task_task_db_proto = out.File + file_task_task_db_proto_rawDesc = nil + file_task_task_db_proto_goTypes = nil + file_task_task_db_proto_depIdxs = nil +} diff --git a/pb/task_msg.pb.go b/pb/task_msg.pb.go new file mode 100644 index 000000000..e97ee1efe --- /dev/null +++ b/pb/task_msg.pb.go @@ -0,0 +1,450 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.0 +// protoc v3.20.0 +// source: task/task_msg.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +//领取 +type TaskReceiveReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TaskTag int32 `protobuf:"varint,1,opt,name=taskTag,proto3" json:"taskTag"` //日常/周常/成就 + Id string `protobuf:"bytes,2,opt,name=id,proto3" json:"id"` //任务唯一ID +} + +func (x *TaskReceiveReq) Reset() { + *x = TaskReceiveReq{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskReceiveReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskReceiveReq) ProtoMessage() {} + +func (x *TaskReceiveReq) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskReceiveReq.ProtoReflect.Descriptor instead. +func (*TaskReceiveReq) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{0} +} + +func (x *TaskReceiveReq) GetTaskTag() int32 { + if x != nil { + return x.TaskTag + } + return 0 +} + +func (x *TaskReceiveReq) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type TaskReceiveResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TaskId int32 `protobuf:"varint,1,opt,name=taskId,proto3" json:"taskId"` //任务配置ID +} + +func (x *TaskReceiveResp) Reset() { + *x = TaskReceiveResp{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskReceiveResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskReceiveResp) ProtoMessage() {} + +func (x *TaskReceiveResp) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskReceiveResp.ProtoReflect.Descriptor instead. +func (*TaskReceiveResp) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{1} +} + +func (x *TaskReceiveResp) GetTaskId() int32 { + if x != nil { + return x.TaskId + } + return 0 +} + +//任务列表 +type TaskListReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TaskTag int32 `protobuf:"varint,1,opt,name=taskTag,proto3" json:"taskTag"` //日常/周常/成就 +} + +func (x *TaskListReq) Reset() { + *x = TaskListReq{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskListReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskListReq) ProtoMessage() {} + +func (x *TaskListReq) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskListReq.ProtoReflect.Descriptor instead. +func (*TaskListReq) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{2} +} + +func (x *TaskListReq) GetTaskTag() int32 { + if x != nil { + return x.TaskTag + } + return 0 +} + +type TaskListResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + List []*DBTask `protobuf:"bytes,1,rep,name=list,proto3" json:"list"` +} + +func (x *TaskListResp) Reset() { + *x = TaskListResp{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskListResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskListResp) ProtoMessage() {} + +func (x *TaskListResp) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskListResp.ProtoReflect.Descriptor instead. +func (*TaskListResp) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{3} +} + +func (x *TaskListResp) GetList() []*DBTask { + if x != nil { + return x.List + } + return nil +} + +//激活测试 +type TaskActiveReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *TaskActiveReq) Reset() { + *x = TaskActiveReq{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskActiveReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskActiveReq) ProtoMessage() {} + +func (x *TaskActiveReq) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskActiveReq.ProtoReflect.Descriptor instead. +func (*TaskActiveReq) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{4} +} + +type TaskActiveResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *TaskActiveResp) Reset() { + *x = TaskActiveResp{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskActiveResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskActiveResp) ProtoMessage() {} + +func (x *TaskActiveResp) ProtoReflect() protoreflect.Message { + mi := &file_task_task_msg_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TaskActiveResp.ProtoReflect.Descriptor instead. +func (*TaskActiveResp) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{5} +} + +var File_task_task_msg_proto protoreflect.FileDescriptor + +var file_task_task_msg_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x6d, 0x73, 0x67, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x74, 0x61, 0x73, 0x6b, + 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3a, 0x0a, 0x0e, 0x54, 0x61, 0x73, + 0x6b, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x74, + 0x61, 0x73, 0x6b, 0x54, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, + 0x73, 0x6b, 0x54, 0x61, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x29, 0x0a, 0x0f, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x63, + 0x65, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, + 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, + 0x22, 0x27, 0x0a, 0x0b, 0x54, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x71, 0x12, + 0x18, 0x0a, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x61, 0x67, 0x22, 0x2b, 0x0a, 0x0c, 0x54, 0x61, 0x73, + 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x6c, 0x69, 0x73, + 0x74, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x54, 0x61, 0x73, 0x6b, + 0x52, 0x04, 0x6c, 0x69, 0x73, 0x74, 0x22, 0x0f, 0x0a, 0x0d, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, + 0x74, 0x69, 0x76, 0x65, 0x52, 0x65, 0x71, 0x22, 0x10, 0x0a, 0x0e, 0x54, 0x61, 0x73, 0x6b, 0x41, + 0x63, 0x74, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_task_task_msg_proto_rawDescOnce sync.Once + file_task_task_msg_proto_rawDescData = file_task_task_msg_proto_rawDesc +) + +func file_task_task_msg_proto_rawDescGZIP() []byte { + file_task_task_msg_proto_rawDescOnce.Do(func() { + file_task_task_msg_proto_rawDescData = protoimpl.X.CompressGZIP(file_task_task_msg_proto_rawDescData) + }) + return file_task_task_msg_proto_rawDescData +} + +var file_task_task_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_task_task_msg_proto_goTypes = []interface{}{ + (*TaskReceiveReq)(nil), // 0: TaskReceiveReq + (*TaskReceiveResp)(nil), // 1: TaskReceiveResp + (*TaskListReq)(nil), // 2: TaskListReq + (*TaskListResp)(nil), // 3: TaskListResp + (*TaskActiveReq)(nil), // 4: TaskActiveReq + (*TaskActiveResp)(nil), // 5: TaskActiveResp + (*DBTask)(nil), // 6: DBTask +} +var file_task_task_msg_proto_depIdxs = []int32{ + 6, // 0: TaskListResp.list:type_name -> DBTask + 1, // [1:1] is the sub-list for method output_type + 1, // [1:1] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_task_task_msg_proto_init() } +func file_task_task_msg_proto_init() { + if File_task_task_msg_proto != nil { + return + } + file_task_task_db_proto_init() + if !protoimpl.UnsafeEnabled { + file_task_task_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskReceiveReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskReceiveResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskListReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskListResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskActiveReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskActiveResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_task_task_msg_proto_rawDesc, + NumEnums: 0, + NumMessages: 6, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_task_task_msg_proto_goTypes, + DependencyIndexes: file_task_task_msg_proto_depIdxs, + MessageInfos: file_task_task_msg_proto_msgTypes, + }.Build() + File_task_task_msg_proto = out.File + file_task_task_msg_proto_rawDesc = nil + file_task_task_msg_proto_goTypes = nil + file_task_task_msg_proto_depIdxs = nil +} diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 34f029e4b..a9a260f1d 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -113,6 +113,8 @@ type DBUser struct { Created bool `protobuf:"varint,15,opt,name=created,proto3" json:"created" bson:"created"` //创角 Lv int32 `protobuf:"varint,16,opt,name=lv,proto3" json:"lv" bson:"lv"` //等级 Vip int32 `protobuf:"varint,17,opt,name=vip,proto3" json:"vip" bson:"vip"` // vip + TaskActive int32 `protobuf:"varint,18,opt,name=taskActive,proto3" json:"taskActive" bson:"taskActive"` //任务活跃度 + Diamond int32 `protobuf:"varint,19,opt,name=diamond,proto3" json:"diamond" bson:"diamond"` // 钻石 } func (x *DBUser) Reset() { @@ -266,6 +268,20 @@ func (x *DBUser) GetVip() int32 { return 0 } +func (x *DBUser) GetTaskActive() int32 { + if x != nil { + return x.TaskActive + } + return 0 +} + +func (x *DBUser) GetDiamond() int32 { + if x != nil { + return x.Diamond + } + return 0 +} + var File_user_user_db_proto protoreflect.FileDescriptor var file_user_user_db_proto_rawDesc = []byte{ @@ -277,7 +293,7 @@ var file_user_user_db_proto_rawDesc = []byte{ 0x64, 0x12, 0x2a, 0x0a, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x0e, 0x0a, - 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x22, 0x8c, 0x03, + 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x22, 0xc6, 0x03, 0x0a, 0x06, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x75, @@ -302,8 +318,12 @@ var file_user_user_db_proto_rawDesc = []byte{ 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x6c, 0x76, 0x18, 0x10, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6c, 0x76, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x69, - 0x70, 0x18, 0x11, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x42, 0x06, 0x5a, 0x04, - 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x18, 0x11, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x76, 0x69, 0x70, 0x12, 0x1e, 0x0a, 0x0a, + 0x74, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x18, 0x12, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x0a, 0x74, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x12, 0x18, 0x0a, 0x07, + 0x64, 0x69, 0x61, 0x6d, 0x6f, 0x6e, 0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x64, + 0x69, 0x61, 0x6d, 0x6f, 0x6e, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/utils/time.go b/utils/time.go new file mode 100644 index 000000000..e5ab49307 --- /dev/null +++ b/utils/time.go @@ -0,0 +1,20 @@ +package utils + +import "time" + +// 判断时间点处于今天 +func IsToday(d int64) bool { + tt := time.Unix(d, 0) + now := time.Now() + return tt.Year() == now.Year() && tt.Month() == now.Month() && tt.Day() == now.Day() +} + +//判断是否大于1周 +func IsAfterWeek(d int64) bool { + tt := time.Unix(d, 0) + now := time.Now() + if !tt.Before(now) { + return false + } + return now.Sub(tt) >= time.Hour*24*7 +} diff --git a/utils/time_test.go b/utils/time_test.go new file mode 100644 index 000000000..b39028aea --- /dev/null +++ b/utils/time_test.go @@ -0,0 +1,18 @@ +package utils_test + +import ( + "fmt" + "go_dreamfactory/utils" + "testing" + "time" +) + +func TestIsToday(t *testing.T) { + tt := time.Unix(1657163870, 0) + fmt.Println(utils.IsToday(tt)) + +} + +func TestSubTime(t *testing.T) { + fmt.Println(utils.IsAfterWeek(1657172915)) +}