12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package models
- import (
- "context"
- mhayaTime "github.com/mhaya/extend/time"
- "github.com/mhaya/game/game_cluster/internal/code"
- "github.com/mhaya/game/game_cluster/internal/constant"
- "github.com/mhaya/game/game_cluster/internal/guid"
- "github.com/mhaya/game/game_cluster/internal/mdb"
- "github.com/mhaya/game/game_cluster/internal/param"
- clog "github.com/mhaya/logger"
- "go.mongodb.org/mongo-driver/bson"
- )
- type Account struct {
- UserName string `json:"username" bson:"userName"`
- Platform string `json:"platform" bson:"platform"`
- Channel string `json:"channel" bson:"channel"`
- OpenId string `json:"-" bson:"openId"`
- JoinIp string `json:"joinip" bson:"JoinIp"`
- JoinTime int64 `json:"jointime" bson:"JoinTime"`
- }
- func (ac *Account) AccountRegisterOrLogin(req *param.LoginReq) (*Account, int32) {
- var account Account
- findFilter := bson.M{"openId": req.OpenID}
- mdb.MDB.Collection(constant.CNameAccount).FindOne(context.Background(), findFilter).Decode(&account)
- if account.OpenId != "" {
- return &account, code.OK
- }
- devAccountTable := &Account{
- UserName: guid.Next(),
- OpenId: req.OpenID,
- Platform: req.Platform,
- Channel: req.Channel,
- JoinIp: req.IP,
- JoinTime: mhayaTime.Now().Unix(),
- }
- _, err := mdb.MDB.Collection(constant.CNameAccount).InsertOne(context.Background(), devAccountTable)
- if err != nil {
- clog.Error("Failed to AccountRegisterOrLogin request: %v err = %v", devAccountTable, err.Error())
- return nil, code.LoginError
- }
- //统计新注册
- SetDailyRecord(req.Platform, req.Channel, DailyRecordNewRegistered, 1)
- return devAccountTable, code.OK
- }
|