From f73f0e407ed70e238a6011d6a33b842281a3191e Mon Sep 17 00:00:00 2001 From: zhaocy Date: Mon, 13 Jun 2022 11:31:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=9B=E8=A7=92=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pb/proto/user/user_db.proto | 23 ++++++++------- pb/user_db.pb.go | 57 +++++++++++++++++++++---------------- sys/db/user.go | 9 +++++- sys/db/user_test.go | 4 +-- 4 files changed, 55 insertions(+), 38 deletions(-) diff --git a/pb/proto/user/user_db.proto b/pb/proto/user/user_db.proto index c79ee461b..e43ceefac 100644 --- a/pb/proto/user/user_db.proto +++ b/pb/proto/user/user_db.proto @@ -8,15 +8,16 @@ message Cache_UserData { } message DB_UserData { - string uid = 1; - string uuid = 2; //玩家唯一uuid - string binduid = 3; //玩家账号 - string name = 4; //玩家名 - int32 sid = 5; //区服id - string createip = 6; //创建账号时的ip - string lastloginip = 7; //最后一次登录时的ip - int64 ctime = 8; //玩家创号时间戳 - int64 logintime = 9; //最后一次登录时间 - int32 FriendPoint = 10; //友情点 - int32 avatar = 11; //头像 + string id = 1; // @go_tags(`bson:"_id"`) ID + string uid = 2; + string uuid = 3; //玩家唯一uuid + string binduid = 4; //玩家账号 + string name = 5; //玩家名 + int32 sid = 6; //区服id + string createip = 7; //创建账号时的ip + string lastloginip = 8; //最后一次登录时的ip + int64 ctime = 9; //玩家创号时间戳 + int64 logintime = 10; //最后一次登录时间 + int32 FriendPoint = 11; //友情点 + int32 avatar = 12; //头像 } \ No newline at end of file diff --git a/pb/user_db.pb.go b/pb/user_db.pb.go index ab1da5a4b..6cfe560eb 100644 --- a/pb/user_db.pb.go +++ b/pb/user_db.pb.go @@ -88,17 +88,18 @@ type DB_UserData struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"` - Uuid string `protobuf:"bytes,2,opt,name=uuid,proto3" json:"uuid,omitempty"` //玩家唯一uuid - Binduid string `protobuf:"bytes,3,opt,name=binduid,proto3" json:"binduid,omitempty"` //玩家账号 - Name string `protobuf:"bytes,4,opt,name=name,proto3" json:"name,omitempty"` //玩家名 - Sid int32 `protobuf:"varint,5,opt,name=sid,proto3" json:"sid,omitempty"` //区服id - Createip string `protobuf:"bytes,6,opt,name=createip,proto3" json:"createip,omitempty"` //创建账号时的ip - Lastloginip string `protobuf:"bytes,7,opt,name=lastloginip,proto3" json:"lastloginip,omitempty"` //最后一次登录时的ip - Ctime int64 `protobuf:"varint,8,opt,name=ctime,proto3" json:"ctime,omitempty"` //玩家创号时间戳 - Logintime int64 `protobuf:"varint,9,opt,name=logintime,proto3" json:"logintime,omitempty"` //最后一次登录时间 - FriendPoint int32 `protobuf:"varint,10,opt,name=FriendPoint,proto3" json:"FriendPoint,omitempty"` //友情点 - Avatar int32 `protobuf:"varint,11,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty" bson:"_id"` // ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` + Uuid string `protobuf:"bytes,3,opt,name=uuid,proto3" json:"uuid,omitempty"` //玩家唯一uuid + Binduid string `protobuf:"bytes,4,opt,name=binduid,proto3" json:"binduid,omitempty"` //玩家账号 + Name string `protobuf:"bytes,5,opt,name=name,proto3" json:"name,omitempty"` //玩家名 + Sid int32 `protobuf:"varint,6,opt,name=sid,proto3" json:"sid,omitempty"` //区服id + Createip string `protobuf:"bytes,7,opt,name=createip,proto3" json:"createip,omitempty"` //创建账号时的ip + Lastloginip string `protobuf:"bytes,8,opt,name=lastloginip,proto3" json:"lastloginip,omitempty"` //最后一次登录时的ip + Ctime int64 `protobuf:"varint,9,opt,name=ctime,proto3" json:"ctime,omitempty"` //玩家创号时间戳 + Logintime int64 `protobuf:"varint,10,opt,name=logintime,proto3" json:"logintime,omitempty"` //最后一次登录时间 + FriendPoint int32 `protobuf:"varint,11,opt,name=FriendPoint,proto3" json:"FriendPoint,omitempty"` //友情点 + Avatar int32 `protobuf:"varint,12,opt,name=avatar,proto3" json:"avatar,omitempty"` //头像 } func (x *DB_UserData) Reset() { @@ -133,6 +134,13 @@ func (*DB_UserData) Descriptor() ([]byte, []int) { return file_user_user_db_proto_rawDescGZIP(), []int{1} } +func (x *DB_UserData) GetId() string { + if x != nil { + return x.Id + } + return "" +} + func (x *DB_UserData) GetUid() string { if x != nil { return x.Uid @@ -222,25 +230,26 @@ var file_user_user_db_proto_rawDesc = []byte{ 0x10, 0x47, 0x61, 0x74, 0x65, 0x77, 0x61, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, - 0x61, 0x52, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0x9f, 0x02, 0x0a, 0x0b, - 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x12, 0x10, 0x0a, 0x03, 0x75, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, - 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, - 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x61, 0x52, 0x08, 0x55, 0x73, 0x65, 0x72, 0x44, 0x61, 0x74, 0x61, 0x22, 0xaf, 0x02, 0x0a, 0x0b, + 0x44, 0x42, 0x5f, 0x55, 0x73, 0x65, 0x72, 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, 0x12, 0x0a, + 0x04, 0x75, 0x75, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x75, 0x69, + 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x62, 0x69, 0x6e, 0x64, 0x75, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, - 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, - 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, - 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x18, 0x06, 0x20, + 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, + 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x69, 0x70, 0x12, 0x20, 0x0a, - 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x18, 0x07, 0x20, 0x01, + 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x6c, 0x61, 0x73, 0x74, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x69, 0x70, 0x12, - 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, + 0x14, 0x0a, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, - 0x6d, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, + 0x6d, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6c, 0x6f, 0x67, 0x69, 0x6e, 0x74, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, - 0x6e, 0x74, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, + 0x6e, 0x74, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x18, - 0x0b, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a, + 0x0c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x61, 0x76, 0x61, 0x74, 0x61, 0x72, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } diff --git a/sys/db/user.go b/sys/db/user.go index 3b6e2fbf4..9250b704b 100644 --- a/sys/db/user.go +++ b/sys/db/user.go @@ -1,10 +1,13 @@ package db import ( + "fmt" "go_dreamfactory/pb" + "time" "go_dreamfactory/lego/core" + uuid "github.com/satori/go.uuid" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo/options" @@ -44,7 +47,11 @@ func (this *DB) User_FindById(id string) (*pb.DB_UserData, error) { } func (this *DB) User_Create(user *pb.DB_UserData) (err error) { - user.Uid = primitive.NewObjectID().Hex() + _id := primitive.NewObjectID().Hex() + user.Id = _id + user.Uid = fmt.Sprintf("%d_%s", user.Sid, _id) + user.Uuid = uuid.NewV4().String() + user.Ctime = time.Now().Unix() _, err = this.mgo.InsertOne(DB_UserTable, user) return err } diff --git a/sys/db/user_test.go b/sys/db/user_test.go index 8cd774c0a..2b07fea2e 100644 --- a/sys/db/user_test.go +++ b/sys/db/user_test.go @@ -11,8 +11,8 @@ import ( func TestCreate(t *testing.T) { user := &pb.DB_UserData{ - Binduid: "legu3", - Name: "乐谷3", + Binduid: "legu131", + Name: "legu131", Sid: 1, }