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