添加获取帐号信息的rpc,admin查找玩家信息时展示帐号状态
This commit is contained in:
parent
06b6123855
commit
76fa896ab4
@ -4,9 +4,11 @@ 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"
|
||||
)
|
||||
@ -34,3 +36,25 @@ func (e *GameUserApi) GetUserById(c *gin.Context) {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ func (s *GameUserRouter) InitGameUserRouter(Router *gin.RouterGroup, RouterPub *
|
||||
router := Router.Group("gameUser").Use(middleware.OperationRecord())
|
||||
|
||||
{
|
||||
router.PUT("getUserById", gameUserApi.GetUserById) // 获取玩家信息
|
||||
router.PUT("getUserById", gameUserApi.GetUserById) // 获取玩家信息
|
||||
router.PUT("getAccountByUid", gameUserApi.GetAccountByUid) // 获取玩家帐号信息
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,4 +8,12 @@ export function getUserById(params) {
|
||||
method: 'put',
|
||||
data: params
|
||||
})
|
||||
}
|
||||
|
||||
export function getAccountByUid(params) {
|
||||
return request({
|
||||
url: '/gameUser/getAccountByUid',
|
||||
method: 'put',
|
||||
data: params
|
||||
})
|
||||
}
|
@ -39,7 +39,10 @@
|
||||
|
||||
|
||||
<script>
|
||||
import {getUserById} from "@/api/gameUser";
|
||||
import {
|
||||
getUserById,
|
||||
getAccountByUid,
|
||||
} from "@/api/gameUser";
|
||||
|
||||
export default {
|
||||
name: 'UserManagement',
|
||||
@ -50,9 +53,9 @@ export default {
|
||||
nickname: '',
|
||||
},
|
||||
statusMap : {
|
||||
0: '正常',
|
||||
1: '禁用',
|
||||
2:'白名单',
|
||||
1: '正常',
|
||||
2: '禁用',
|
||||
3:'白名单',
|
||||
},
|
||||
userList: [
|
||||
// {
|
||||
@ -109,18 +112,19 @@ export default {
|
||||
const id = this.searchInfo.id // 或者从其他地方获取ID
|
||||
if (id) {
|
||||
const response = await getUserById({id:+id})
|
||||
if (response.code !== 0) {
|
||||
if (response.code !== 0 || response.data.user.account_id === 0) {
|
||||
console.error('获取玩家数据失败:', response.msg || `请求失败,错误码: ${response.code}`)
|
||||
this.$message.error('获取用户数据失败:'+(response.msg || `请求失败,错误码: ${response.code}`))
|
||||
return
|
||||
}
|
||||
console.error('获取玩家数据:', response.data.user)
|
||||
const retAccount = await getAccountByUid({id:+response.data.user.account_id})
|
||||
console.error('获取玩家帐号数据:', retAccount)
|
||||
this.userList = [
|
||||
{
|
||||
id:response.data.user.id,
|
||||
nickname:response.data.user.nickname,
|
||||
gold:response.data.user.gold,
|
||||
status:response.data.user.status,
|
||||
status:retAccount.data.account.status,
|
||||
},
|
||||
]
|
||||
} else {
|
||||
|
@ -37,3 +37,22 @@ func RpcGetGameUser(s service.IService, uid int64) (*user.GameUser, pb.ErrCode)
|
||||
}
|
||||
return nil, pb.ErrCode(rspMsg.RpcCode)
|
||||
}
|
||||
|
||||
// 获取玩家数据
|
||||
func RpcGetAccountByUid(s service.IService, uid int64) (*user.UserAccount, pb.ErrCode) {
|
||||
us := &user.UserAccount{
|
||||
ID: uid,
|
||||
}
|
||||
rpcMsg := ipb.MakeRpcMsg(GetUserAccountById, uid, us)
|
||||
log.DebugF("%v call rpc:%v", s.Name(), GetUserAccountById)
|
||||
rspMsg, err := s.CallByServiceId(int(pb.ServiceTypeId_STI_DB), timeout, rpcMsg)
|
||||
if err != nil {
|
||||
log.ErrorF("call rpc:%v err:%s ", rpcMsg.RpcMsgId, err.Error())
|
||||
return nil, pb.ErrCode_SystemErr
|
||||
}
|
||||
if rspMsg.RpcCode == 0 {
|
||||
_ = json.Unmarshal(rspMsg.Msg, us)
|
||||
return us, pb.ErrCode_OK
|
||||
}
|
||||
return nil, pb.ErrCode(rspMsg.RpcCode)
|
||||
}
|
||||
|
@ -2,10 +2,11 @@ package rpc
|
||||
|
||||
const (
|
||||
// 用户、用户资源及帐号相关操作
|
||||
GetUserAccount = "get.user.account.rpc"
|
||||
CreateUserAccount = "create.user.account.rpc"
|
||||
UpdateUserPassword = "update.user.password.rpc"
|
||||
LogUserAccountLogin = "user.login.rpc"
|
||||
GetUserAccount = "get.account.rpc"
|
||||
GetUserAccountById = "get.account.id.rpc"
|
||||
CreateUserAccount = "create.account.rpc"
|
||||
UpdateUserPassword = "update.account.password.rpc"
|
||||
LogUserAccountLogin = "log.account.login.rpc"
|
||||
GetUserByUid = "get.user.uid.rpc"
|
||||
GetUserByAccountId = "get.user.account.id.rpc"
|
||||
GetUserResources = "get.user.resources.rpc"
|
||||
|
@ -35,6 +35,15 @@ func (s *UserAccountOp) redisKey(username string) string {
|
||||
return fmt.Sprintf("username:%s", username)
|
||||
}
|
||||
|
||||
// 创建用户
|
||||
func (s *UserAccountOp) Find(uid int64) (*user.UserAccount, pb.ErrCode) {
|
||||
us, code := s.accountOp.Find(uid)
|
||||
if us != nil {
|
||||
us.Password = ""
|
||||
}
|
||||
return us, code
|
||||
}
|
||||
|
||||
func (s *UserAccountOp) GetUserAccount(username string) (*user.UserAccount, pb.ErrCode) {
|
||||
sUid, err := s.accountRedis.Get(context.Background(), s.redisKey(username)).Result()
|
||||
if err != nil {
|
||||
|
@ -18,6 +18,13 @@ func (s *DbService) onGetUserAccount(iMsg *ipb.InternalMsg) *ipb.InternalMsg {
|
||||
return iMsg
|
||||
}
|
||||
|
||||
func (s *DbService) onGetUserAccountById(iMsg *ipb.InternalMsg) *ipb.InternalMsg {
|
||||
operationDb[user.UserAccount](iMsg, func(us *user.UserAccount) (*user.UserAccount, pb.ErrCode) {
|
||||
return operation.NewUserAccountOp().Find(us.ID)
|
||||
})
|
||||
return iMsg
|
||||
}
|
||||
|
||||
// 创建帐号
|
||||
func (s *DbService) onCreateUserAccount(iMsg *ipb.InternalMsg) *ipb.InternalMsg {
|
||||
operationDb[user.UserAccount](iMsg, operation.NewUserAccountOp().CreateUserAccount)
|
||||
|
@ -9,6 +9,7 @@ func (s *DbService) initRpcProcessor() {
|
||||
s.RpcProcessor.RegisterMessages(map[string]processor.RpcHandler{
|
||||
rpc.CreateUserAccount: s.onCreateUserAccount,
|
||||
rpc.GetUserAccount: s.onGetUserAccount,
|
||||
rpc.GetUserAccountById: s.onGetUserAccountById,
|
||||
rpc.UpdateUserPassword: s.onUpdateUserAccount,
|
||||
rpc.LogUserAccountLogin: s.onLogUserAccountLogin,
|
||||
rpc.GetUserByUid: s.onGetUserByUid,
|
||||
|
Loading…
x
Reference in New Issue
Block a user