From ec36100f30f665fe167484d8fe2254cdf5ae0882 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 21 Jul 2024 03:40:29 +0800 Subject: [PATCH] 1 --- server/marketserver/api/v1/user/user.go | 85 ++++++++++++++++++++----- 1 file changed, 69 insertions(+), 16 deletions(-) diff --git a/server/marketserver/api/v1/user/user.go b/server/marketserver/api/v1/user/user.go index 155db209..3c831561 100644 --- a/server/marketserver/api/v1/user/user.go +++ b/server/marketserver/api/v1/user/user.go @@ -21,20 +21,73 @@ func (this *UserApi) Info(c *gin.Context) { Gold float64 `json:"gold"` }{ } - f5.GetGoStyleDb().OrmSelectOne( - constant.GAME_DB, - "t_user", - [][]string{ - {"address", accountAddress}, - }, - func (err error, ds *f5.DataSet) { - if err != nil { - f5.RspErr(c, 500, "server internal error") - return - } - if ds.Next() { - rspObj.Gold = q5.ToFloat64(ds.GetByName("gold")) - } - c.JSON(200, rspObj) - }) + { + var dbErr error + f5.GetGoStyleDb().OrmSelectOne( + constant.GAME_DB, + "t_user", + [][]string{ + {"address", accountAddress}, + }, + func (err error, ds *f5.DataSet) { + dbErr = err + if err != nil { + return + } + if ds.Next() { + rspObj.Gold = q5.ToFloat64(ds.GetByName("gold")) + } + }) + if dbErr != nil { + f5.RspErr(c, 500, "server internal error") + return + } + } + { + var dbErr error + f5.GetGoStyleDb().OrmSelectOne( + constant.BCNFT_DB, + "t_contribution", + [][]string{ + {"account_address", accountAddress}, + }, + func (err error, ds *f5.DataSet) { + dbErr = err + if err != nil { + return + } + if ds.Next() { + rspObj.ContributionPoint += q5.ToInt64(ds.GetByName("contribution")) + } + }) + if dbErr != nil { + f5.RspErr(c, 500, "server internal error") + return + } + } + { + var dbErr error + sql := "SELECT SUM(contribution) FROM t_staking_daily_settlement WHERE account_address = ?" + params := []string{ + accountAddress, + } + f5.GetGoStyleDb().RawQuery( + constant.BCNFT_DB, + sql, + params, + func (err error, ds *f5.DataSet) { + dbErr = err + if err != nil { + return + } + for ds.Next() { + rspObj.ContributionPoint += q5.ToInt64(ds.GetByIndex(0)) + } + }) + if dbErr != nil { + f5.RspErr(c, 500, "server internal error") + return + } + } + c.JSON(200, rspObj) }