From b5f2a9fcc85e03d6c8c92eee9cfad7530d75c6e0 Mon Sep 17 00:00:00 2001 From: yangduo Date: Mon, 19 Aug 2024 17:51:58 +0800 Subject: [PATCH] player email --- server/adminserver/api/v1/system/player.go | 71 +++++++++++++++++++++- server/adminserver/app/app.go | 12 +++- server/adminserver/model/system/player.go | 1 + 3 files changed, 82 insertions(+), 2 deletions(-) diff --git a/server/adminserver/api/v1/system/player.go b/server/adminserver/api/v1/system/player.go index f7af1db6..70004ebe 100644 --- a/server/adminserver/api/v1/system/player.go +++ b/server/adminserver/api/v1/system/player.go @@ -7,6 +7,7 @@ import ( "main/model/system" "net/http" "q5" + "strings" "github.com/gin-gonic/gin" ) @@ -20,6 +21,7 @@ func (pai *PlayerApi) Info(c *gin.Context) { AccurateName bool `json:"accurate_name"` Account_id string `json:"account_id"` Address string `json:"address"` + Email string `json:"email"` } reqJson := InfoForm{} @@ -41,10 +43,45 @@ func (pai *PlayerApi) Info(c *gin.Context) { filterstr = " account_id = '" + reqJson.Account_id + "'" } else if reqJson.Address != "" { filterstr = " address = '" + reqJson.Address + "'" + } else if reqJson.Email != "" { + email := strings.ToLower(reqJson.Email) + sql := fmt.Sprintf(`SELECT account_id FROM t_immutable_account WHERE idx > 1 AND lower_case_email = '%s'`, email) + + accountids := []string{} + f5.GetGoStyleDb().RawQuery( + constant.ACCOUNT_DB, + sql, + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + for ds.Next() { + accountids = append(accountids, ds.GetByIndex(0)) + } + }) + + if len(accountids) == 0 { + c.JSON(http.StatusOK, gin.H{ + "code": 0, + "message": "", + }) + + return + } + + filterstr = " account_id IN (" + for _, id := range accountids { + filterstr += "'" + id + "'," + } + filterstr = filterstr[:len(filterstr)-1] + filterstr += ")" + } else { c.JSON(http.StatusOK, gin.H{ "code": 1, - "message": "input one of playername, account_id, address", + "message": "input one of playername, account_id, address, email", }) return } @@ -53,6 +90,38 @@ func (pai *PlayerApi) Info(c *gin.Context) { query(constant.GAME_DB, cursor, sql, c, func(ds *f5.DataSet) interface{} { p := new(system.Player) p.LoadFromDs(ds) + + accountid := "" + if reqJson.Playername != "" { + if reqJson.AccurateName { + accountid = p.Account_id + } + } else if reqJson.Account_id != "" { + accountid = reqJson.Account_id + } else if reqJson.Address != "" { + accountid = p.Account_id + } else if reqJson.Email != "" { + p.Email = strings.ToLower(reqJson.Email) + } + + if accountid != "" { + sql := fmt.Sprintf(`SELECT lower_case_email FROM t_immutable_account WHERE idx > 1 AND account_id = '%s'`, accountid) + + f5.GetGoStyleDb().RawQuery( + constant.ACCOUNT_DB, + sql, + []string{}, + func(err error, ds *f5.DataSet) { + if err != nil { + return + } + + if ds.Next() { + p.Email = ds.GetByIndex(0) + } + }) + } + return p }) } diff --git a/server/adminserver/app/app.go b/server/adminserver/app/app.go index ff05c9c4..a7beb34d 100644 --- a/server/adminserver/app/app.go +++ b/server/adminserver/app/app.go @@ -6,8 +6,8 @@ import ( "f5" //"fmt" "main/constant" - "main/task" "main/mt" + "main/task" //"sync" //"time" ) @@ -119,6 +119,16 @@ func (this *app) registerDataSources() { 1, mt.Table.ConfDb.GetById(0).GetMaxOpenConns(), mt.Table.ConfDb.GetById(0).GetMaxIdleConns()) + f5.GetGoStyleDb().RegisterDataSource( + constant.ACCOUNT_DB, + mt.Table.AccountDb.GetById(0).GetHost(), + mt.Table.AccountDb.GetById(0).GetPort(), + mt.Table.AccountDb.GetById(0).GetUser(), + mt.Table.AccountDb.GetById(0).GetPasswd(), + mt.Table.AccountDb.GetById(0).GetDatabase(), + 1, + mt.Table.AccountDb.GetById(0).GetMaxOpenConns(), + mt.Table.AccountDb.GetById(0).GetMaxIdleConns()) } func (this *app) HasTask() bool { diff --git a/server/adminserver/model/system/player.go b/server/adminserver/model/system/player.go index bc79bdbb..5ddb51e9 100644 --- a/server/adminserver/model/system/player.go +++ b/server/adminserver/model/system/player.go @@ -48,6 +48,7 @@ type Player struct { Parachute int `gorm:"comment:降落伞id" json:"parachute"` Star_num int `gorm:"comment:星星数(成长任务)" json:"star_num"` Address string `gorm:"uniqueIndex;comment:钱包地址" json:"address"` + Email string `json:"email"` } func (this *Player) TableName() string {