diff --git a/dao/account_log.go b/dao/account_log.go new file mode 100644 index 0000000..4a32fad --- /dev/null +++ b/dao/account_log.go @@ -0,0 +1,94 @@ +package dao + +import ( + "context" + + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/mongox" + + "mongo.games.com/game/dao/internal" + modelpkg "mongo.games.com/game/model" +) + +var ( + _ = context.Background() + _ = logger.Logger + _ = bson.M{} + _ = mongo.Database{} +) + +type AccountLogColumns = internal.AccountLogColumns + +type AccountLog struct { + *internal.AccountLog +} + +func GetAccountLog(key string) (*AccountLog, error) { + return mongox.GetDao(key, NewAccountLog) +} + +func NewAccountLog(db *mongo.Database, c *mongo.Collection) (*AccountLog, any) { + if db == nil || c == nil { + return &AccountLog{}, &modelpkg.AccountLog{} + } + + v := internal.NewAccountLog() + v.Database = db + v.Collection = c + + c.Indexes().CreateMany(context.Background(), []mongo.IndexModel{ + { + Keys: bson.D{{"platform", 1}}, // 1 表示升序,-1 表示降序 + Options: options.Index().SetBackground(true).SetSparse(true), // 后台创建索引,稀疏索引 + }, + { + Keys: bson.D{{"snid", 1}}, // 1 表示升序,-1 表示降序 + Options: options.Index().SetBackground(true).SetSparse(true), // 后台创建索引,稀疏索引 + }, + { + Keys: bson.D{{"faceBookId", 1}}, // 1 表示升序,-1 表示降序 + Options: options.Index().SetBackground(true).SetSparse(true), // 后台创建索引,稀疏索引 + }, + }) + + return &AccountLog{AccountLog: v}, &modelpkg.AccountLog{} +} + +func (a *AccountLog) GetByFaceBookId(id string) (*modelpkg.AccountLog, error) { + ret, err := a.FindOne(context.Background(), func(cols *internal.AccountLogColumns) interface{} { + return bson.M{cols.FaceBookId: id} + }) + if err != nil { + return nil, err + } + return ret, nil +} + +func (a *AccountLog) Save(log *modelpkg.AccountLog) error { + old, err := a.FindOne(context.Background(), func(cols *internal.AccountLogColumns) interface{} { + return bson.M{cols.SnId: log.SnId} + }) + if err != nil { + return err + } + + if old != nil { + // 更新 + log.ID = old.ID + _, err = a.UpdateOne(context.Background(), func(cols *internal.AccountLogColumns) interface{} { + return bson.M{cols.SnId: log.SnId} + }, func(cols *internal.AccountLogColumns) interface{} { + return bson.M{"$set": log} + }) + if err != nil { + return err + } + return nil + } + // 插入 + _, err = a.InsertOne(context.Background(), log) + return err +} diff --git a/dao/internal/account_log.go b/dao/internal/account_log.go new file mode 100644 index 0000000..47411f8 --- /dev/null +++ b/dao/internal/account_log.go @@ -0,0 +1,277 @@ +// -------------------------------------------------------------------------------------------- +// The following code is automatically generated by the mongo-dao-generator tool. +// Please do not modify this code manually to avoid being overwritten in the next generation. +// For more tool details, please click the link to view https://github.com/dobyte/mongo-dao-generator +// -------------------------------------------------------------------------------------------- + +package internal + +import ( + "context" + "errors" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/bson/primitive" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + modelpkg "mongo.games.com/game/model" +) + +type AccountLogFilterFunc func(cols *AccountLogColumns) interface{} +type AccountLogUpdateFunc func(cols *AccountLogColumns) interface{} +type AccountLogPipelineFunc func(cols *AccountLogColumns) interface{} +type AccountLogCountOptionsFunc func(cols *AccountLogColumns) *options.CountOptions +type AccountLogAggregateOptionsFunc func(cols *AccountLogColumns) *options.AggregateOptions +type AccountLogFindOneOptionsFunc func(cols *AccountLogColumns) *options.FindOneOptions +type AccountLogFindManyOptionsFunc func(cols *AccountLogColumns) *options.FindOptions +type AccountLogUpdateOptionsFunc func(cols *AccountLogColumns) *options.UpdateOptions +type AccountLogDeleteOptionsFunc func(cols *AccountLogColumns) *options.DeleteOptions +type AccountLogInsertOneOptionsFunc func(cols *AccountLogColumns) *options.InsertOneOptions +type AccountLogInsertManyOptionsFunc func(cols *AccountLogColumns) *options.InsertManyOptions + +type AccountLog struct { + Columns *AccountLogColumns + Database *mongo.Database + Collection *mongo.Collection +} + +type AccountLogColumns struct { + ID string + Platform string + SnId string + FaceBookId string +} + +var accountLogColumns = &AccountLogColumns{ + ID: "_id", + Platform: "Platform", + SnId: "SnId", + FaceBookId: "FaceBookId", +} + +func NewAccountLog() *AccountLog { + return &AccountLog{ + Columns: accountLogColumns, + } +} + +// Count returns the number of documents in the collection. +func (dao *AccountLog) Count(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogCountOptionsFunc) (int64, error) { + var ( + opts *options.CountOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.CountDocuments(ctx, filter, opts) +} + +// Aggregate executes an aggregate command against the collection and returns a cursor over the resulting documents. +func (dao *AccountLog) Aggregate(ctx context.Context, pipelineFunc AccountLogPipelineFunc, optionsFunc ...AccountLogAggregateOptionsFunc) (*mongo.Cursor, error) { + var ( + opts *options.AggregateOptions + pipeline = pipelineFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.Aggregate(ctx, pipeline, opts) +} + +// InsertOne executes an insert command to insert a single document into the collection. +func (dao *AccountLog) InsertOne(ctx context.Context, model *modelpkg.AccountLog, optionsFunc ...AccountLogInsertOneOptionsFunc) (*mongo.InsertOneResult, error) { + if model == nil { + return nil, errors.New("model is nil") + } + + if err := dao.autofill(ctx, model); err != nil { + return nil, err + } + + var opts *options.InsertOneOptions + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.InsertOne(ctx, model, opts) +} + +// InsertMany executes an insert command to insert multiple documents into the collection. +func (dao *AccountLog) InsertMany(ctx context.Context, models []*modelpkg.AccountLog, optionsFunc ...AccountLogInsertManyOptionsFunc) (*mongo.InsertManyResult, error) { + if len(models) == 0 { + return nil, errors.New("models is empty") + } + + documents := make([]interface{}, 0, len(models)) + for i := range models { + model := models[i] + if err := dao.autofill(ctx, model); err != nil { + return nil, err + } + documents = append(documents, model) + } + + var opts *options.InsertManyOptions + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.InsertMany(ctx, documents, opts) +} + +// UpdateOne executes an update command to update at most one document in the collection. +func (dao *AccountLog) UpdateOne(ctx context.Context, filterFunc AccountLogFilterFunc, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) { + var ( + opts *options.UpdateOptions + filter = filterFunc(dao.Columns) + update = updateFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.UpdateOne(ctx, filter, update, opts) +} + +// UpdateOneByID executes an update command to update at most one document in the collection. +func (dao *AccountLog) UpdateOneByID(ctx context.Context, id string, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.UpdateOne(ctx, func(cols *AccountLogColumns) interface{} { + return bson.M{"_id": objectID} + }, updateFunc, optionsFunc...) +} + +// UpdateMany executes an update command to update documents in the collection. +func (dao *AccountLog) UpdateMany(ctx context.Context, filterFunc AccountLogFilterFunc, updateFunc AccountLogUpdateFunc, optionsFunc ...AccountLogUpdateOptionsFunc) (*mongo.UpdateResult, error) { + var ( + opts *options.UpdateOptions + filter = filterFunc(dao.Columns) + update = updateFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.UpdateMany(ctx, filter, update, opts) +} + +// FindOne executes a find command and returns a model for one document in the collection. +func (dao *AccountLog) FindOne(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogFindOneOptionsFunc) (*modelpkg.AccountLog, error) { + var ( + opts *options.FindOneOptions + model = &modelpkg.AccountLog{} + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + err := dao.Collection.FindOne(ctx, filter, opts).Decode(model) + if err != nil { + if err == mongo.ErrNoDocuments { + return nil, nil + } + return nil, err + } + + return model, nil +} + +// FindOneByID executes a find command and returns a model for one document in the collection. +func (dao *AccountLog) FindOneByID(ctx context.Context, id string, optionsFunc ...AccountLogFindOneOptionsFunc) (*modelpkg.AccountLog, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.FindOne(ctx, func(cols *AccountLogColumns) interface{} { + return bson.M{"_id": objectID} + }, optionsFunc...) +} + +// FindMany executes a find command and returns many models the matching documents in the collection. +func (dao *AccountLog) FindMany(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogFindManyOptionsFunc) ([]*modelpkg.AccountLog, error) { + var ( + opts *options.FindOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + cur, err := dao.Collection.Find(ctx, filter, opts) + if err != nil { + return nil, err + } + + models := make([]*modelpkg.AccountLog, 0) + + if err = cur.All(ctx, &models); err != nil { + return nil, err + } + + return models, nil +} + +// DeleteOne executes a delete command to delete at most one document from the collection. +func (dao *AccountLog) DeleteOne(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) { + var ( + opts *options.DeleteOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.DeleteOne(ctx, filter, opts) +} + +// DeleteOneByID executes a delete command to delete at most one document from the collection. +func (dao *AccountLog) DeleteOneByID(ctx context.Context, id string, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) { + objectID, err := primitive.ObjectIDFromHex(id) + if err != nil { + return nil, err + } + + return dao.DeleteOne(ctx, func(cols *AccountLogColumns) interface{} { + return bson.M{"_id": objectID} + }, optionsFunc...) +} + +// DeleteMany executes a delete command to delete documents from the collection. +func (dao *AccountLog) DeleteMany(ctx context.Context, filterFunc AccountLogFilterFunc, optionsFunc ...AccountLogDeleteOptionsFunc) (*mongo.DeleteResult, error) { + var ( + opts *options.DeleteOptions + filter = filterFunc(dao.Columns) + ) + + if len(optionsFunc) > 0 { + opts = optionsFunc[0](dao.Columns) + } + + return dao.Collection.DeleteMany(ctx, filter, opts) +} + +// autofill when inserting data +func (dao *AccountLog) autofill(ctx context.Context, model *modelpkg.AccountLog) error { + if model.ID.IsZero() { + model.ID = primitive.NewObjectID() + } + + return nil +} diff --git a/dbproxy/mq/c_accountlog.go b/dbproxy/mq/c_accountlog.go new file mode 100644 index 0000000..9cd910f --- /dev/null +++ b/dbproxy/mq/c_accountlog.go @@ -0,0 +1,34 @@ +package mq + +import ( + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/mongox" + + "mongo.games.com/game/dao" + "mongo.games.com/game/model" + "mongo.games.com/game/mq" +) + +func init() { + mq.RegisterHandler(&mq.RegisterHandlerParam{ + Name: mq.DBAccountLog, + Data: model.AccountLog{}, + Handler: func(data interface{}) (err error) { + log, ok := data.(*model.AccountLog) + if !ok { + return nil + } + c, err := dao.GetAccountLog(mongox.Global) + if err != nil { + logger.Logger.Errorf("GetAccountLog error: %v", err) + return err + } + err = c.Save(log) + if err != nil { + logger.Logger.Errorf("Save error: %v", err) + return err + } + return nil + }, + }) +} diff --git a/dbproxy/svc/l_accountlog.go b/dbproxy/svc/l_accountlog.go new file mode 100644 index 0000000..bb15ae9 --- /dev/null +++ b/dbproxy/svc/l_accountlog.go @@ -0,0 +1,33 @@ +package svc + +import ( + "mongo.games.com/game/dao" + "mongo.games.com/game/model" + "mongo.games.com/goserver/core/logger" + "mongo.games.com/goserver/core/mongox" + "net/rpc" +) + +type AccountLogSvc struct { +} + +func (a *AccountLogSvc) GetByFaceBookId(req *string, res *model.AccountLog) error { + c, err := dao.GetAccountLog(mongox.Global) + if err != nil { + logger.Logger.Errorf("GetAccountLog error: %v", err) + return err + } + log, err := c.GetByFaceBookId(*req) + if err != nil { + logger.Logger.Errorf("GetByFaceBookId error: %v", err) + return err + } + *res = *log + return nil +} + +var AccountLogSvcInst = new(AccountLogSvc) + +func init() { + rpc.Register(AccountLogSvcInst) +} diff --git a/model/accountlog.go b/model/accountlog.go new file mode 100644 index 0000000..c58e9d0 --- /dev/null +++ b/model/accountlog.go @@ -0,0 +1,47 @@ +package model + +import ( + "errors" + "go.mongodb.org/mongo-driver/bson/primitive" + "mongo.games.com/goserver/core/logger" + "time" +) + +// AccountLog 账号日志 +// 根据facebookId查询账号信息 + +//go:generate mongoctl -model-dir=. -model-names=AccountLog -dao-dir=../dao/ +type AccountLog struct { + ID primitive.ObjectID `bson:"_id" gen:"autoFill"` + Platform string `json:"platform"` + SnId int32 `json:"snId"` + AccountType int32 `json:"accountType"` + FaceBookId string `json:"faceBookId"` +} + +func (a *AccountLog) DatabaseName() string { + return "log" +} + +func (a *AccountLog) CollectionName() string { + return "log_account" +} + +func GetByFaceBookId(faceBookId string) (*AccountLog, error) { + if rpcCli == nil { + return nil, errors.New("rpc client is nil") + } + + if faceBookId == "" { + return nil, nil + } + + accountLog := &AccountLog{} + err := rpcCli.CallWithTimeout("AccountLogSvc.GetByFaceBookId", &faceBookId, accountLog, time.Second*30) + if err != nil { + logger.Logger.Errorf("GetByFaceBookId err:%v", err) + return nil, err + } + + return accountLog, nil +} diff --git a/mq/keyconf.go b/mq/keyconf.go index 7638967..9464bce 100644 --- a/mq/keyconf.go +++ b/mq/keyconf.go @@ -50,6 +50,7 @@ const ( DBLotteryCode = "db_lotterycode" // 玩家抽奖码 DBLotteryLog = "db_lotterylog" // 中奖记录 DBRedPacket = "db_redpackethistory" // 红包记录 + DBAccountLog = "db_accountlog" // 账号日志 ) // ranksrv 消息 diff --git a/protocol/webapi/webapi.pb.go b/protocol/webapi/webapi.pb.go index 2e7e508..935e443 100644 --- a/protocol/webapi/webapi.pb.go +++ b/protocol/webapi/webapi.pb.go @@ -8486,8 +8486,9 @@ type ASPlayerDelete struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"` // 平台id - Snid int32 `protobuf:"varint,2,opt,name=Snid,proto3" json:"Snid,omitempty"` // 玩家id + Platform string `protobuf:"bytes,1,opt,name=platform,proto3" json:"platform,omitempty"` // 平台id + Snid int32 `protobuf:"varint,2,opt,name=Snid,proto3" json:"Snid,omitempty"` // 玩家id + FaceBookId string `protobuf:"bytes,3,opt,name=FaceBookId,proto3" json:"FaceBookId,omitempty"` // facebook id } func (x *ASPlayerDelete) Reset() { @@ -8536,6 +8537,13 @@ func (x *ASPlayerDelete) GetSnid() int32 { return 0 } +func (x *ASPlayerDelete) GetFaceBookId() string { + if x != nil { + return x.FaceBookId + } + return "" +} + type SAPlayerDelete struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -11441,11 +11449,13 @@ var file_protocol_webapi_webapi_proto_rawDesc = []byte{ 0x65, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x12, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x4d, 0x73, - 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x22, 0x40, 0x0a, 0x0e, + 0x67, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x4d, 0x73, 0x67, 0x22, 0x60, 0x0a, 0x0e, 0x41, 0x53, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x6c, 0x61, 0x74, 0x66, 0x6f, 0x72, 0x6d, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6e, - 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x6e, 0x69, 0x64, 0x22, 0x45, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x53, 0x6e, 0x69, 0x64, 0x12, 0x1e, + 0x0a, 0x0a, 0x46, 0x61, 0x63, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x49, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0a, 0x46, 0x61, 0x63, 0x65, 0x42, 0x6f, 0x6f, 0x6b, 0x49, 0x64, 0x22, 0x45, 0x0a, 0x0e, 0x53, 0x41, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x21, 0x0a, 0x03, 0x54, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0f, 0x2e, 0x77, 0x65, 0x62, 0x61, 0x70, 0x69, 0x2e, 0x54, 0x61, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x03, diff --git a/protocol/webapi/webapi.proto b/protocol/webapi/webapi.proto index 1404d64..8dbfd38 100644 --- a/protocol/webapi/webapi.proto +++ b/protocol/webapi/webapi.proto @@ -909,6 +909,7 @@ message SAGetImgVerify{ message ASPlayerDelete{ string platform = 1; // 平台id int32 Snid = 2; // 玩家id + string FaceBookId = 3; // facebook id } message SAPlayerDelete{ TagCode Tag = 1; //错误码 diff --git a/worldsrv/task_login.go b/worldsrv/task_login.go index 4abab69..9a8d293 100644 --- a/worldsrv/task_login.go +++ b/worldsrv/task_login.go @@ -10,6 +10,7 @@ import ( "time" "github.com/globalsign/mgo/bson" + "go.mongodb.org/mongo-driver/bson/primitive" "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/netlib" @@ -427,6 +428,16 @@ func SCLogin(s *netlib.Session, sid int64, csLogin *login_proto.CSLogin, acc *mo ct, cr := PlatformMgrSingleton.GetCurrencyByPackageTag(csLogin.PlatformTag) sclogin.CurrencyType = ct sclogin.CurrencyRatio = cr + // facebook账号信息 + if acc.AccountType == common.AccountTypeFacebook { + mq.Write(&model.AccountLog{ + ID: primitive.NewObjectID(), + Platform: acc.Platform, + SnId: acc.SnId, + AccountType: acc.AccountType, + FaceBookId: strings.TrimPrefix(acc.UserName, "facebook_"), + }, mq.DBAccountLog) + } } } } diff --git a/worldsrv/trascate_webapi.go b/worldsrv/trascate_webapi.go index 3581b88..4157ce3 100644 --- a/worldsrv/trascate_webapi.go +++ b/worldsrv/trascate_webapi.go @@ -2451,6 +2451,18 @@ func init() { } task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { + if msg.GetFaceBookId() != "" { + fb, err := model.GetByFaceBookId(msg.GetFaceBookId()) + if err != nil { + return err + } + if fb == nil { + return nil + } + msg.Platform = fb.Platform + msg.Snid = fb.SnId + } + pd, _ := model.GetPlayerDataBySnId(msg.Platform, msg.Snid, false, false) if pd == nil || pd.SnId == 0 { err = errors.New("player not found")