From d2512168fa1708cdcffdf5874b30a8796c583dae Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Fri, 13 Oct 2023 14:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=88=90=E5=B0=B1=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comm/const.go | 3 ++ modules/achieve/api_Info.go | 12 +++++-- modules/achieve/api_award.go | 37 ++++++++++++++++++-- modules/achieve/model.go | 46 +++++++++++++++++++++++++ modules/achieve/module.go | 2 ++ pb/achieve_db.pb.go | 46 +++++++++++++++++-------- pb/achieve_msg.pb.go | 66 ++++++++++++++++++++++-------------- 7 files changed, 167 insertions(+), 45 deletions(-) create mode 100644 modules/achieve/model.go diff --git a/comm/const.go b/comm/const.go index a23ff2676..e15e45385 100644 --- a/comm/const.go +++ b/comm/const.go @@ -384,6 +384,9 @@ const ( TableCaravanRank = "caravansrank" TableJielong = "jielong" + + //日常任务 + TableAchieve = "achieve" ) // RPC服务接口定义处 diff --git a/modules/achieve/api_Info.go b/modules/achieve/api_Info.go index df026fc01..7cbbe9f26 100644 --- a/modules/achieve/api_Info.go +++ b/modules/achieve/api_Info.go @@ -15,13 +15,21 @@ func (this *apiComp) InfoCheck(session comm.IUserSession, req *pb.AchieveInfoReq func (this *apiComp) Info(session comm.IUserSession, req *pb.AchieveInfoReq) (errdata *pb.ErrorData) { var ( tasks []int32 + info *pb.DBAchieveData progress []*pb.ConIProgress err error ) if errdata = this.InfoCheck(session, req); errdata != nil { return } - + if info, err = this.module.model.getmodel(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.String(), + Message: err.Error(), + } + return + } tasks = this.module.configure.tasksConf if progress, err = this.module.ModuleBuried.CheckCondition(session.GetUserId(), tasks...); err != nil { errdata = &pb.ErrorData{ @@ -31,6 +39,6 @@ func (this *apiComp) Info(session comm.IUserSession, req *pb.AchieveInfoReq) (er } return } - session.SendMsg(string(this.module.GetType()), "info", &pb.AchieveInfoResp{Tasks: progress}) + session.SendMsg(string(this.module.GetType()), "info", &pb.AchieveInfoResp{Info: info, Tasks: progress}) return } diff --git a/modules/achieve/api_award.go b/modules/achieve/api_award.go index 34ce3b4f6..5b37e30fb 100644 --- a/modules/achieve/api_award.go +++ b/modules/achieve/api_award.go @@ -15,15 +15,43 @@ func (this *apiComp) AwardCheck(session comm.IUserSession, req *pb.AchieveAwardR // /获取自己的排行榜信息 func (this *apiComp) Award(session comm.IUserSession, req *pb.AchieveAwardReq) (errdata *pb.ErrorData) { var ( + info *pb.DBAchieveData conf *cfg.GameAchieveTaskData atno []*pb.UserAtno progress []*pb.ConIProgress + ok bool err error ) if errdata = this.AwardCheck(session, req); errdata != nil { return } - conf, err = this.module.configure.getAchieveTaskById(req.Id) + if conf, err = this.module.configure.getAchieveTaskById(req.Id); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ConfigNoFound, + Title: pb.ErrorCode_ConfigNoFound.String(), + Message: err.Error(), + } + return + } + + if info, err = this.module.model.getmodel(session.GetUserId()); err != nil { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_DBError, + Title: pb.ErrorCode_DBError.String(), + Message: err.Error(), + } + return + } + + if ok = info.Receive[req.Id]; ok { + errdata = &pb.ErrorData{ + Code: pb.ErrorCode_ReqParameterError, + Title: pb.ErrorCode_ReqParameterError.String(), + Message: "Claimed", + } + return + } + if progress, err = this.module.ModuleBuried.CheckCondition(session.GetUserId(), conf.TaskBuried); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ExternalModule, @@ -45,7 +73,10 @@ func (this *apiComp) Award(session comm.IUserSession, req *pb.AchieveAwardReq) ( if errdata, atno = this.module.DispenseAtno(session, conf.TaskReward, true); errdata != nil { return } - - session.SendMsg(string(this.module.GetType()), "info", &pb.AchieveAwardResp{Id: req.Id, Award: atno}) + info.Receive[req.Id] = true + this.module.model.Change(session.GetUserId(), map[string]interface{}{ + "receive": info.Receive, + }) + session.SendMsg(string(this.module.GetType()), "award", &pb.AchieveAwardResp{Id: req.Id, Award: atno}) return } diff --git a/modules/achieve/model.go b/modules/achieve/model.go new file mode 100644 index 000000000..9e51f2f0a --- /dev/null +++ b/modules/achieve/model.go @@ -0,0 +1,46 @@ +package achieve + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/lego/core" + "go_dreamfactory/lego/sys/mgo" + "go_dreamfactory/modules" + "go_dreamfactory/pb" + + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/x/bsonx" +) + +type modelComp struct { + modules.MCompModel + module *Achieve +} + +func (this *modelComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { + err = this.MCompModel.Init(service, module, comp, options) + this.TableName = comm.TableDailytask + this.module = module.(*Achieve) + this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{ + Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}}, + }) + return +} + +// 获取用户全部的埋点数据 +func (this *modelComp) getmodel(uid string) (results *pb.DBAchieveData, err error) { + results = &pb.DBAchieveData{} + if err = this.Get(uid, results); err != nil && err != mgo.MongodbNil { + this.module.Errorln(err) + return + } + if err == mgo.MongodbNil { + results = &pb.DBAchieveData{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Receive: make(map[int32]bool), + } + err = this.Add(uid, results) + } + return +} diff --git a/modules/achieve/module.go b/modules/achieve/module.go index d15155d79..0a277ad68 100644 --- a/modules/achieve/module.go +++ b/modules/achieve/module.go @@ -11,6 +11,7 @@ type Achieve struct { service core.IService wtask comm.IWtask api *apiComp + model *modelComp configure *configureComp } @@ -45,5 +46,6 @@ func (this *Achieve) Start() (err error) { func (this *Achieve) OnInstallComp() { this.ModuleBase.OnInstallComp() this.api = this.RegisterComp(new(apiComp)).(*apiComp) + this.model = this.RegisterComp(new(modelComp)).(*modelComp) this.configure = this.RegisterComp(new(configureComp)).(*configureComp) } diff --git a/pb/achieve_db.pb.go b/pb/achieve_db.pb.go index 73e1ca2ff..b2258f457 100644 --- a/pb/achieve_db.pb.go +++ b/pb/achieve_db.pb.go @@ -26,8 +26,9 @@ type DBAchieveData struct { 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"` + 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"` + Receive map[int32]bool `protobuf:"bytes,3,rep,name=receive,proto3" json:"receive" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` } func (x *DBAchieveData) Reset() { @@ -76,15 +77,30 @@ func (x *DBAchieveData) GetUid() string { return "" } +func (x *DBAchieveData) GetReceive() map[int32]bool { + if x != nil { + return x.Receive + } + return nil +} + var File_achieve_achieve_db_proto protoreflect.FileDescriptor var file_achieve_achieve_db_proto_rawDesc = []byte{ 0x0a, 0x18, 0x61, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x2f, 0x61, 0x63, 0x68, 0x69, 0x65, 0x76, - 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x31, 0x0a, 0x0d, 0x44, 0x42, - 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x44, 0x61, 0x74, 0x61, 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, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x65, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa4, 0x01, 0x0a, 0x0d, 0x44, + 0x42, 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x44, 0x61, 0x74, 0x61, 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, 0x35, + 0x0a, 0x07, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x1b, 0x2e, 0x44, 0x42, 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x44, 0x61, 0x74, 0x61, 0x2e, + 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x72, 0x65, + 0x63, 0x65, 0x69, 0x76, 0x65, 0x1a, 0x3a, 0x0a, 0x0c, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -99,16 +115,18 @@ func file_achieve_achieve_db_proto_rawDescGZIP() []byte { return file_achieve_achieve_db_proto_rawDescData } -var file_achieve_achieve_db_proto_msgTypes = make([]protoimpl.MessageInfo, 1) +var file_achieve_achieve_db_proto_msgTypes = make([]protoimpl.MessageInfo, 2) var file_achieve_achieve_db_proto_goTypes = []interface{}{ (*DBAchieveData)(nil), // 0: DBAchieveData + nil, // 1: DBAchieveData.ReceiveEntry } var file_achieve_achieve_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 + 1, // 0: DBAchieveData.receive:type_name -> DBAchieveData.ReceiveEntry + 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_achieve_achieve_db_proto_init() } @@ -136,7 +154,7 @@ func file_achieve_achieve_db_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_achieve_achieve_db_proto_rawDesc, NumEnums: 0, - NumMessages: 1, + NumMessages: 2, NumExtensions: 0, NumServices: 0, }, diff --git a/pb/achieve_msg.pb.go b/pb/achieve_msg.pb.go index 73a7579fe..b566d703c 100644 --- a/pb/achieve_msg.pb.go +++ b/pb/achieve_msg.pb.go @@ -65,7 +65,8 @@ type AchieveInfoResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Tasks []*ConIProgress `protobuf:"bytes,1,rep,name=tasks,proto3" json:"tasks"` + Info *DBAchieveData `protobuf:"bytes,1,opt,name=info,proto3" json:"info"` + Tasks []*ConIProgress `protobuf:"bytes,2,rep,name=tasks,proto3" json:"tasks"` } func (x *AchieveInfoResp) Reset() { @@ -100,6 +101,13 @@ func (*AchieveInfoResp) Descriptor() ([]byte, []int) { return file_achieve_achieve_msg_proto_rawDescGZIP(), []int{1} } +func (x *AchieveInfoResp) GetInfo() *DBAchieveData { + if x != nil { + return x.Info + } + return nil +} + func (x *AchieveInfoResp) GetTasks() []*ConIProgress { if x != nil { return x.Tasks @@ -213,22 +221,25 @@ var File_achieve_achieve_msg_proto protoreflect.FileDescriptor var file_achieve_achieve_msg_proto_rawDesc = []byte{ 0x0a, 0x19, 0x61, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x2f, 0x61, 0x63, 0x68, 0x69, 0x65, 0x76, - 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x16, 0x62, 0x75, 0x72, - 0x69, 0x65, 0x64, 0x2f, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, - 0x10, 0x0a, 0x0e, 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, - 0x71, 0x22, 0x36, 0x0a, 0x0f, 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x49, 0x6e, 0x66, 0x6f, - 0x52, 0x65, 0x73, 0x70, 0x12, 0x23, 0x0a, 0x05, 0x74, 0x61, 0x73, 0x6b, 0x73, 0x18, 0x01, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x43, 0x6f, 0x6e, 0x49, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, - 0x73, 0x73, 0x52, 0x05, 0x74, 0x61, 0x73, 0x6b, 0x73, 0x22, 0x21, 0x0a, 0x0f, 0x41, 0x63, 0x68, - 0x69, 0x65, 0x76, 0x65, 0x41, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x22, 0x43, 0x0a, 0x10, - 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x41, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, - 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, - 0x12, 0x1f, 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x09, 0x2e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x74, 0x6e, 0x6f, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, - 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x65, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x18, 0x61, 0x63, 0x68, + 0x69, 0x65, 0x76, 0x65, 0x2f, 0x61, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x5f, 0x64, 0x62, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x16, 0x62, 0x75, 0x72, 0x69, 0x65, 0x64, 0x2f, 0x62, 0x75, + 0x72, 0x69, 0x65, 0x64, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x63, + 0x6f, 0x6d, 0x6d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x10, 0x0a, 0x0e, 0x41, 0x63, 0x68, + 0x69, 0x65, 0x76, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x71, 0x22, 0x5a, 0x0a, 0x0f, 0x41, + 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, + 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, + 0x42, 0x41, 0x63, 0x68, 0x69, 0x65, 0x76, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x04, 0x69, 0x6e, + 0x66, 0x6f, 0x12, 0x23, 0x0a, 0x05, 0x74, 0x61, 0x73, 0x6b, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x0d, 0x2e, 0x43, 0x6f, 0x6e, 0x49, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, + 0x52, 0x05, 0x74, 0x61, 0x73, 0x6b, 0x73, 0x22, 0x21, 0x0a, 0x0f, 0x41, 0x63, 0x68, 0x69, 0x65, + 0x76, 0x65, 0x41, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x71, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x22, 0x43, 0x0a, 0x10, 0x41, 0x63, + 0x68, 0x69, 0x65, 0x76, 0x65, 0x41, 0x77, 0x61, 0x72, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x0e, + 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1f, + 0x0a, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, + 0x55, 0x73, 0x65, 0x72, 0x41, 0x74, 0x6e, 0x6f, 0x52, 0x05, 0x61, 0x77, 0x61, 0x72, 0x64, 0x42, + 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -249,17 +260,19 @@ var file_achieve_achieve_msg_proto_goTypes = []interface{}{ (*AchieveInfoResp)(nil), // 1: AchieveInfoResp (*AchieveAwardReq)(nil), // 2: AchieveAwardReq (*AchieveAwardResp)(nil), // 3: AchieveAwardResp - (*ConIProgress)(nil), // 4: ConIProgress - (*UserAtno)(nil), // 5: UserAtno + (*DBAchieveData)(nil), // 4: DBAchieveData + (*ConIProgress)(nil), // 5: ConIProgress + (*UserAtno)(nil), // 6: UserAtno } var file_achieve_achieve_msg_proto_depIdxs = []int32{ - 4, // 0: AchieveInfoResp.tasks:type_name -> ConIProgress - 5, // 1: AchieveAwardResp.award:type_name -> UserAtno - 2, // [2:2] is the sub-list for method output_type - 2, // [2:2] is the sub-list for method input_type - 2, // [2:2] is the sub-list for extension type_name - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 4, // 0: AchieveInfoResp.info:type_name -> DBAchieveData + 5, // 1: AchieveInfoResp.tasks:type_name -> ConIProgress + 6, // 2: AchieveAwardResp.award:type_name -> UserAtno + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_achieve_achieve_msg_proto_init() } @@ -267,6 +280,7 @@ func file_achieve_achieve_msg_proto_init() { if File_achieve_achieve_msg_proto != nil { return } + file_achieve_achieve_db_proto_init() file_buried_buried_db_proto_init() file_comm_proto_init() if !protoimpl.UnsafeEnabled {