This commit is contained in:
liwei1dao 2022-07-07 10:25:12 +08:00
commit 9766dbc99c
37 changed files with 1548 additions and 75 deletions

View File

@ -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()
}
//注册账号

54
cmd/robot/task.go Normal file
View File

@ -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()
}

View File

@ -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),

View File

@ -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 //成就
)

View File

@ -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)
}
)

1
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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
}

View File

@ -23,13 +23,10 @@ func (this *ModelStory) Init(service core.IService, module core.IModule, comp co
}
// 获取章节信息
func (this *ModelStory) getStoryList(uid string) ([]*pb.DBStory, error) {
storys := make([]*pb.DBStory, 0)
err := this.GetList(uid, &storys)
if err != nil {
return nil, err
}
return storys, nil
func (this *ModelStory) getStoryList(uid string) (storys []*pb.DBStory, err error) {
storys = make([]*pb.DBStory, 0)
err = this.GetList(uid, &storys)
return
}
// 修改章节信息

View File

@ -74,6 +74,10 @@ func (this *Story) CheckChallengeChapter(stroyId int32, uid string, zhangjieID i
code = pb.ErrorCode_ConfigNoFound
return
}
// 如果这一关是路线二的话
if configData.Area == 2 && curChapter.ChapterId > stroyId { // 当前的关卡ID 大于路线2的ID 即可
return
}
// 判断下一关是不是当前传入的值
if configData.Nextid != stroyId {
code = pb.ErrorCode_StoryIDFailed
@ -82,8 +86,19 @@ func (this *Story) CheckChallengeChapter(stroyId int32, uid string, zhangjieID i
}
break
case 2:
configData := this.configure.GetStoryHardChapter(curChapter.StoryId)
if configData != nil { // 校验章节
if configData.Zhangshu != zhangjieID {
code = pb.ErrorCode_ConfigNoFound
return
}
// 判断下一关是不是当前传入的值
if configData.Nextid != stroyId {
code = pb.ErrorCode_StoryIDFailed
return
}
}
break
}
return
}

View File

@ -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
}

View File

@ -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
}

35
modules/task/api_list.go Normal file
View File

@ -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
}

View File

@ -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
}

131
modules/task/config.go Normal file
View File

@ -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
}

2
modules/task/const.go Normal file
View File

@ -0,0 +1,2 @@
package task

View File

@ -0,0 +1,2 @@
package task

View File

@ -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
}

View File

@ -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
}

View File

@ -76,5 +76,7 @@ func (this *apiComp) Create(session comm.IUserSession, req *pb.UserCreateReq) (c
}
}
//初始化任务
this.module.ModuleTask.InitTaskAll(self.Uid)
return
}

View File

@ -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

View File

@ -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
}

View File

@ -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

1
pb.bat
View File

@ -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

View File

@ -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,
},

View File

@ -89,6 +89,10 @@ const (
// mainStory
ErrorCode_StoryNotFindChapter ErrorCode = 1500 // 没有找到主线关卡信息
ErrorCode_StoryIDFailed ErrorCode = 1501 // 关卡ID 错误
// task
ErrorCode_TaskInit ErrorCode = 1600 //初始化失败
ErrorCode_TaskReset ErrorCode = 1601 //重置任务失败
ErrorCode_TaskHandle ErrorCode = 1602 //任务处理失败
)
// Enum value maps for ErrorCode.
@ -154,6 +158,9 @@ var (
1401: "EquipmentLvlimitReached",
1500: "StoryNotFindChapter",
1501: "StoryIDFailed",
1600: "TaskInit",
1601: "TaskReset",
1602: "TaskHandle",
}
ErrorCode_value = map[string]int32{
"Success": 0,
@ -216,6 +223,9 @@ var (
"EquipmentLvlimitReached": 1401,
"StoryNotFindChapter": 1500,
"StoryIDFailed": 1501,
"TaskInit": 1600,
"TaskReset": 1601,
"TaskHandle": 1602,
}
)
@ -250,7 +260,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, 0x9b, 0x0a, 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,
@ -328,7 +338,10 @@ var file_errorcode_proto_rawDesc = []byte{
0x4c, 0x76, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x52, 0x65, 0x61, 0x63, 0x68, 0x65, 0x64, 0x10, 0xf9,
0x0a, 0x12, 0x18, 0x0a, 0x13, 0x53, 0x74, 0x6f, 0x72, 0x79, 0x4e, 0x6f, 0x74, 0x46, 0x69, 0x6e,
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,
0x74, 0x6f, 0x72, 0x79, 0x49, 0x44, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x10, 0xdd, 0x0b, 0x12,
0x0d, 0x0a, 0x08, 0x54, 0x61, 0x73, 0x6b, 0x49, 0x6e, 0x69, 0x74, 0x10, 0xc0, 0x0c, 0x12, 0x0e,
0x0a, 0x09, 0x54, 0x61, 0x73, 0x6b, 0x52, 0x65, 0x73, 0x65, 0x74, 0x10, 0xc1, 0x0c, 0x12, 0x0f,
0x0a, 0x0a, 0x54, 0x61, 0x73, 0x6b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x10, 0xc2, 0x0c, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}

View File

@ -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; //
}

View File

@ -73,4 +73,9 @@ enum ErrorCode {
// mainStory
StoryNotFindChapter = 1500; // 线
StoryIDFailed = 1501; // ID
// task
TaskInit = 1600; //
TaskReset = 1601; //
TaskHandle = 1602; //
}

View File

@ -117,7 +117,7 @@ message HeroProperty {
}
//
message HeroLockReq{
message HeroLockReq{
string heroid = 1;
}

View File

@ -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
}

View File

@ -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 {}

View File

@ -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"`)
}

188
pb/task_db.pb.go Normal file
View File

@ -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
}

450
pb/task_msg.pb.go Normal file
View File

@ -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
}

View File

@ -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 (

20
utils/time.go Normal file
View File

@ -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
}

18
utils/time_test.go Normal file
View File

@ -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))
}