61 lines
1.6 KiB
Go

package gameUser
import (
"fmt"
"game/common/model/user"
"game/common/proto/pb"
"game/common/rpc"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
us "github.com/flipped-aurora/gin-vue-admin/server/service/user"
"github.com/flipped-aurora/gin-vue-admin/server/servicex"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
type GameUserApi struct{}
func (e *GameUserApi) GetUserById(c *gin.Context) {
var gameUser = &user.GameUser{}
err := c.ShouldBindJSON(&gameUser)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if gameUser.ID < 1 {
response.FailWithMessage(fmt.Sprintf("玩家id不能为0"), c)
return
}
var code pb.ErrCode
gameUser, code = us.GetUser(gameUser.ID)
if code != pb.ErrCode_OK {
global.GVA_LOG.Error("查询失败!", zap.Error(fmt.Errorf(code.String())))
response.FailWithMessage("查询失败", c)
return
}
response.OkWithData(gin.H{"user": gameUser}, c)
}
func (e *GameUserApi) GetAccountByUid(c *gin.Context) {
var account = &user.UserAccount{}
err := c.ShouldBindJSON(&account)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if account.ID < 1 {
response.FailWithMessage(fmt.Sprintf("玩家帐号id不能为0"), c)
return
}
var code pb.ErrCode
account, code = rpc.RpcGetAccountByUid(servicex.GetService(), account.ID)
if code != pb.ErrCode_OK {
global.GVA_LOG.Error("查询失败!", zap.Error(fmt.Errorf(code.String())))
response.FailWithMessage("查询失败", c)
return
}
response.OkWithData(gin.H{"account": account}, c)
}