diff --git a/pb/mail.pb.go b/pb/mail.pb.go index 103198ff3..e5e2522b9 100644 --- a/pb/mail.pb.go +++ b/pb/mail.pb.go @@ -75,7 +75,6 @@ func (x *MailAttachment) GetItemCount() uint32 { return 0 } -//背包格子 type MailData struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -163,14 +162,13 @@ func (x *MailData) GetItems() []*MailAttachment { return nil } -//用户背包 type DB_UserMailData struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId uint32 `bson:"_id" json:"UserId,omitempty" protobuf:"varint,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id - Mails []*MailData `protobuf:"bytes,2,rep,name=mails,proto3" json:"mails,omitempty"` // 邮件列表 + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id + Mails []*MailData `protobuf:"bytes,2,rep,name=mails,proto3" json:"mails,omitempty"` // 邮件列表 } func (x *DB_UserMailData) Reset() { @@ -205,11 +203,11 @@ func (*DB_UserMailData) Descriptor() ([]byte, []int) { return file_mail_proto_rawDescGZIP(), []int{2} } -func (x *DB_UserMailData) GetUserId() uint32 { +func (x *DB_UserMailData) GetUserId() string { if x != nil { return x.UserId } - return 0 + return "" } func (x *DB_UserMailData) GetMails() []*MailData { @@ -240,7 +238,7 @@ var file_mail_proto_rawDesc = []byte{ 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x41, 0x74, 0x74, 0x61, 0x63, 0x68, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x4a, 0x0a, 0x0f, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x12, 0x16, 0x0a, 0x06, 0x55, 0x73, 0x65, - 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, + 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1f, 0x0a, 0x05, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x09, 0x2e, 0x4d, 0x61, 0x69, 0x6c, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x6d, 0x61, 0x69, 0x6c, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, diff --git a/pb/pack_db.pb.go b/pb/pack_db.pb.go index 6dd9577bf..0dc1074bd 100644 --- a/pb/pack_db.pb.go +++ b/pb/pack_db.pb.go @@ -139,7 +139,7 @@ type DB_UserPackData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}用户Id + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}用户Id Pack []*GridData `protobuf:"bytes,2,rep,name=Pack,proto3" json:"Pack,omitempty"` //背包列表 } diff --git a/pb/proto/mail.proto b/pb/proto/mail.proto index ebdf9ed65..6c3c4f54c 100644 --- a/pb/proto/mail.proto +++ b/pb/proto/mail.proto @@ -5,7 +5,7 @@ message MailAttachment { // 附件 uint32 Itemid = 1; // 道具iD uint32 ItemCount = 2; // 数量 } -//背包格子 + message MailData { string Title = 1; // 邮件标题 string Contex = 2; // 邮件内容 @@ -15,8 +15,7 @@ message MailData { repeated MailAttachment Items = 6; // 附件 } -//用户背包 message DB_UserMailData { - uint32 UserId = 1; //tags:{bson:"_id"}用户Id + string UserId = 1; //tags:{bson:"_id"}用户Id repeated MailData mails = 2; // 邮件列表 } \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index 2ce469232..2c4b65c99 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -88,7 +88,7 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - UserId string `protobuf:"bytes,1,opt,name=UserId,proto3" json:"UserId,omitempty" bson:"_id"` //tags:{bson:"_id"}动态Id + UserId string `bson:"_id" json:"UserId,omitempty" protobuf:"bytes,1,opt,name=UserId,proto3"` //tags:{bson:"_id"}动态Id Account string `protobuf:"bytes,2,opt,name=account,proto3" json:"account,omitempty"` NiceName string `protobuf:"bytes,3,opt,name=NiceName,proto3" json:"NiceName,omitempty"` Email string `protobuf:"bytes,4,opt,name=Email,proto3" json:"Email,omitempty"` diff --git a/sys/cache/core.go b/sys/cache/core.go index e8eecaed8..ddda681f7 100644 --- a/sys/cache/core.go +++ b/sys/cache/core.go @@ -4,6 +4,7 @@ type ( ISys interface { IUser IPack + IMail } ) diff --git a/sys/cache/mail.go b/sys/cache/mail.go index fca759d23..d42970c83 100644 --- a/sys/cache/mail.go +++ b/sys/cache/mail.go @@ -1,7 +1,35 @@ package cache -const ( //Redis - Redis_mailCache string = "mail:%d" +import ( + "fmt" + "go_dreamfactory/pb" + "go_dreamfactory/sys/db" + + "github.com/liwei1dao/lego/sys/mgo" + "github.com/liwei1dao/lego/sys/redis" ) -type IMail interface{} +const ( //Redis + Redis_MailCache string = "mail:%s" +) + +type IMail interface { + QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) +} + +// 查询玩家邮件数据 +func (this *Cache) QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) { + mail = &pb.DB_UserMailData{ + UserId: uId, + } + if err = this.redis.Get(fmt.Sprintf(Redis_MailCache, uId), mail); err == nil { + return + } else if err == redis.RedisNil { + if mail, err = db.Defsys.QueryUserMail(uId); err == nil { + this.redis.Set(fmt.Sprintf(Redis_MailCache, uId), mail, -1) + } else if err == mgo.MongodbNil { + err = nil + } + } + return +} diff --git a/sys/db/mail.go b/sys/db/mail.go index fa06af9f5..5772e2e42 100644 --- a/sys/db/mail.go +++ b/sys/db/mail.go @@ -4,15 +4,19 @@ import ( "go_dreamfactory/pb" "github.com/liwei1dao/lego/core" + "go.mongodb.org/mongo-driver/bson" ) -type IMail interface { -} - const ( //Redis DB_MailTable core.SqlTable = "mail" ) -type IMain interface { - QueryUserMail(uId uint32) (pack *pb.DB_UserPackData, err error) +type IMail interface { + QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) +} + +func (this *DB) QueryUserMail(uId string) (mail *pb.DB_UserMailData, err error) { + mail = &pb.DB_UserMailData{} + err = this.mgo.FindOne(DB_MailTable, bson.M{"_id": uId}).Decode(mail) + return }