gm后台添加金流日志
This commit is contained in:
parent
d4904ea20c
commit
ef253158e4
@ -3,13 +3,15 @@ package v1
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/gameUser"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/logRecord"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
|
||||
)
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
GameUserApiGroup gameUser.ApiGroup
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
GameUserApiGroup gameUser.ApiGroup
|
||||
LogRecordApiGroup logRecord.ApiGroup
|
||||
}
|
||||
|
5
admin/server/api/v1/logRecord/enter.go
Normal file
5
admin/server/api/v1/logRecord/enter.go
Normal file
@ -0,0 +1,5 @@
|
||||
package logRecord
|
||||
|
||||
type ApiGroup struct {
|
||||
LogRecordApi
|
||||
}
|
35
admin/server/api/v1/logRecord/logRecord.go
Normal file
35
admin/server/api/v1/logRecord/logRecord.go
Normal file
@ -0,0 +1,35 @@
|
||||
package logRecord
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/proto/pb"
|
||||
rpc "game/common/rpc/logRecord"
|
||||
"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/servicex"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type LogRecordApi struct{}
|
||||
|
||||
func (e *LogRecordApi) GetUserResLogs(c *gin.Context) {
|
||||
var req = &rpc.LogUserResReq{}
|
||||
err := c.ShouldBindJSON(req)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
if req.UserId < 1 {
|
||||
response.FailWithMessage(fmt.Sprintf("玩家id不能为0"), c)
|
||||
return
|
||||
}
|
||||
|
||||
values, code := rpc.RpcGetUserResLogs(servicex.GetService(), req.UserId, req)
|
||||
if code != pb.ErrCode_OK {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(fmt.Errorf(code.String())))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"log": values}, c)
|
||||
}
|
@ -54,6 +54,7 @@ func Routers() *gin.Engine {
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
gameUserRouter := router.RouterGroupApp.GameUser
|
||||
logRecordRouter := router.RouterGroupApp.LogRecord
|
||||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
||||
// VUE_APP_BASE_API = /
|
||||
// VUE_APP_BASE_PATH = http://localhost
|
||||
@ -113,6 +114,9 @@ func Routers() *gin.Engine {
|
||||
{
|
||||
gameUserRouter.InitGameUserRouter(PrivateGroup, PublicGroup)
|
||||
}
|
||||
{
|
||||
logRecordRouter.InitLogRecordRouter(PrivateGroup, PublicGroup)
|
||||
}
|
||||
|
||||
//插件路由安装
|
||||
InstallPlugin(PrivateGroup, PublicGroup, Router)
|
||||
|
@ -3,13 +3,15 @@ package router
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/gameUser"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/logRecord"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/system"
|
||||
)
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
|
||||
type RouterGroup struct {
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
GameUser gameUser.GameUserRouter
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
GameUser gameUser.GameUserRouter
|
||||
LogRecord logRecord.RouterGroup
|
||||
}
|
||||
|
11
admin/server/router/logRecord/enter.go
Normal file
11
admin/server/router/logRecord/enter.go
Normal file
@ -0,0 +1,11 @@
|
||||
package logRecord
|
||||
|
||||
import api "github.com/flipped-aurora/gin-vue-admin/server/api/v1"
|
||||
|
||||
type RouterGroup struct {
|
||||
LogRecordRouter
|
||||
}
|
||||
|
||||
var (
|
||||
logRecordApi = api.ApiGroupApp.LogRecordApiGroup.LogRecordApi
|
||||
)
|
18
admin/server/router/logRecord/user.go
Normal file
18
admin/server/router/logRecord/user.go
Normal file
@ -0,0 +1,18 @@
|
||||
package logRecord
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type LogRecordRouter struct{}
|
||||
|
||||
func (s *LogRecordRouter) InitLogRecordRouter(Router *gin.RouterGroup, RouterPub *gin.RouterGroup) {
|
||||
_ = RouterPub
|
||||
router := Router.Group("logRecord").Use(middleware.OperationRecord())
|
||||
|
||||
{
|
||||
router.PUT("getUserResLogs", logRecordApi.GetUserResLogs) // 查询玩家金流
|
||||
}
|
||||
|
||||
}
|
13
admin/web/src/api/logRecord.js
Normal file
13
admin/web/src/api/logRecord.js
Normal file
@ -0,0 +1,13 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
export function getUserResLogs(params) {
|
||||
return request({
|
||||
url: '/logRecord/getUserResLogs',
|
||||
method: 'put',
|
||||
data: params
|
||||
})
|
||||
}
|
@ -20,6 +20,7 @@
|
||||
"/src/view/example/upload/upload.vue": "Upload",
|
||||
"/src/view/gameuser/addResourceDialog.vue": "AddResourceDialog",
|
||||
"/src/view/gameuser/index.vue": "Index",
|
||||
"/src/view/gameuser/logResource.vue": "LogResource",
|
||||
"/src/view/init/index.vue": "Init",
|
||||
"/src/view/layout/aside/asideComponent/asyncSubmenu.vue": "AsyncSubmenu",
|
||||
"/src/view/layout/aside/asideComponent/index.vue": "AsideComponent",
|
||||
@ -39,6 +40,7 @@
|
||||
"/src/view/layout/setting/title.vue": "layoutSettingTitle",
|
||||
"/src/view/layout/tabs/index.vue": "HistoryComponent",
|
||||
"/src/view/login/index.vue": "Login",
|
||||
"/src/view/logRecord/logResource.vue": "LogResource",
|
||||
"/src/view/person/person.vue": "Person",
|
||||
"/src/view/routerHolder.vue": "RouterHolder",
|
||||
"/src/view/superAdmin/api/api.vue": "Api",
|
||||
|
@ -136,7 +136,7 @@ export default {
|
||||
const id = this.searchInfo.id // 或者从其他地方获取ID
|
||||
if (id) {
|
||||
const response = await getUserById({id:+id})
|
||||
if (response.code !== 0 || response.data.user.account_id === 0) {
|
||||
if (response.code !== 0) {
|
||||
console.error('获取玩家数据失败:', response.msg || `请求失败,错误码: ${response.code}`)
|
||||
this.$message.error('获取用户数据失败:'+(response.msg || `请求失败,错误码: ${response.code}`))
|
||||
return
|
||||
|
112
admin/web/src/view/logRecord/logResource.vue
Normal file
112
admin/web/src/view/logRecord/logResource.vue
Normal file
@ -0,0 +1,112 @@
|
||||
<template>
|
||||
<div class="query-container">
|
||||
<el-form :inline="true" class="demo-form-inline">
|
||||
<!-- 用户ID输入框(按您要求放在最左侧) -->
|
||||
<el-form-item label="用户ID">
|
||||
<el-input v-model="searchInfo.userId" placeholder="0"></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 游戏ID下拉选择 -->
|
||||
<el-form-item label="游戏ID">
|
||||
<el-select v-model="searchInfo.gameId" placeholder="请选择游戏">
|
||||
<el-option
|
||||
v-for="item in gameOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 用户ID输入框(按您要求放在最左侧) -->
|
||||
<el-form-item label="对局记录ID">
|
||||
<el-input v-model="searchInfo.gameNo" ></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 时间范围选择 -->
|
||||
<el-form-item label="开始时间">
|
||||
<el-date-picker
|
||||
v-model="searchInfo.startTime"
|
||||
type="date"
|
||||
placeholder="选择日期">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="结束时间">
|
||||
<el-date-picker
|
||||
v-model="searchInfo.endTime"
|
||||
type="date"
|
||||
placeholder="选择日期">
|
||||
</el-date-picker>
|
||||
</el-form-item>
|
||||
|
||||
<!-- 查询按钮 -->
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="onQuery">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
getUserResLogs,
|
||||
} from "@/api/logRecord";
|
||||
|
||||
const searchInfo = {
|
||||
userId: '',
|
||||
gameId: 0,
|
||||
gameNo:'',
|
||||
startTime: '',
|
||||
endTime: '',
|
||||
}
|
||||
|
||||
const gameOptions= [
|
||||
{ value: 1, label: '王者荣耀' },
|
||||
{ value: 2, label: '原神' },
|
||||
{ value: 3, label: '和平精英' }
|
||||
]
|
||||
|
||||
async function onQuery() {
|
||||
// 显示加载状态
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
text: '加载中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
})
|
||||
try {
|
||||
const req = {
|
||||
user_id:+searchInfo.userId,
|
||||
game_id:+searchInfo.gameId,
|
||||
game_no:searchInfo.gameNo,
|
||||
startTime:searchInfo.startTime,
|
||||
endTime:searchInfo.endTime,
|
||||
}
|
||||
const response = await getUserResLogs(req)
|
||||
if (response.code !== 0) {
|
||||
console.error('获取金流失败:', response.msg || `请求失败,错误码: ${response.code}`)
|
||||
this.$message.error('获取金流失败:' + (response.msg || `请求失败,错误码: ${response.code}`))
|
||||
return
|
||||
}
|
||||
console.log(response.data.log)
|
||||
}catch (error){
|
||||
console.error('获取金流失败:', error)
|
||||
this.$message.error('获取金流失败:'+error)
|
||||
}finally {
|
||||
// 关闭加载状态
|
||||
loading.close()
|
||||
}
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.query-container {
|
||||
padding: 20px;
|
||||
background: #fff;
|
||||
}
|
||||
.el-form-item {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
</style>
|
@ -33,7 +33,7 @@ type TableOp[T iTable] struct {
|
||||
}
|
||||
|
||||
func NewTableOp[T iTable](db *gorm.DB, rds *redis.Client) *TableOp[T] {
|
||||
return &TableOp[T]{db: db.Debug(), rds: rds}
|
||||
return &TableOp[T]{db: db, rds: rds}
|
||||
}
|
||||
|
||||
func (s *TableOp[T]) tableName() string {
|
||||
|
40
common/rpc/logRecord/rpcGetUserResLogs.go
Normal file
40
common/rpc/logRecord/rpcGetUserResLogs.go
Normal file
@ -0,0 +1,40 @@
|
||||
package logRecord
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"game/common/proto/pb"
|
||||
"game/common/rpc"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
"github.com/fox/fox/service"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
timeout = time.Second * 30
|
||||
)
|
||||
|
||||
type LogUserResReq struct {
|
||||
UserId int64 `json:"user_id"`
|
||||
GameId int `json:"game_id"`
|
||||
GameNo string `json:"game_no"`
|
||||
ResName string `json:"res_name"`
|
||||
StartTime string `json:"start_time"`
|
||||
EndTime string `json:"end_time"`
|
||||
}
|
||||
|
||||
// 添加玩家资源,负数为减少
|
||||
func RpcGetUserResLogs(s service.IService, uid int64, req *LogUserResReq) (map[string]int64, pb.ErrCode) {
|
||||
rpcMsg := ipb.MakeRpcMsg(rpc.RpcGetUserResLog, uid, req)
|
||||
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 {
|
||||
res := map[string]int64{}
|
||||
_ = json.Unmarshal(rspMsg.Msg, &res)
|
||||
return res, pb.ErrCode_OK
|
||||
}
|
||||
return nil, pb.ErrCode(rspMsg.RpcCode)
|
||||
}
|
@ -14,4 +14,7 @@ const (
|
||||
AddUserResources = "add.user.resources.rpc"
|
||||
SaveGameRecordLog = "save.game.record.log.rpc" // 保存对局日志
|
||||
SaveUserRecordLog = "save.user.record.log.rpc" // 保存玩家战绩
|
||||
|
||||
// 日志查询
|
||||
RpcGetUserResLog = "get.user.res.log.rpc" // 玩家金流查询
|
||||
)
|
||||
|
55
server/db/server/handlerLogRecord.go
Normal file
55
server/db/server/handlerLogRecord.go
Normal file
@ -0,0 +1,55 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"game/common/model/user"
|
||||
"game/common/proto/pb"
|
||||
"game/common/rpc/logRecord"
|
||||
"game/common/utils"
|
||||
"game/server/db/operation"
|
||||
"github.com/fox/fox/ipb"
|
||||
"github.com/fox/fox/log"
|
||||
)
|
||||
|
||||
// 获取玩家金流日志
|
||||
func (s *DbService) onGetUserResLogs(iMsg *ipb.InternalMsg) *ipb.InternalMsg {
|
||||
var req = &logRecord.LogUserResReq{}
|
||||
err := json.Unmarshal(iMsg.Msg, req)
|
||||
if err != nil {
|
||||
log.ErrorF("error unmarshalling user account %v", err)
|
||||
iMsg.RpcCode = int32(pb.ErrCode_SystemErr)
|
||||
return iMsg
|
||||
}
|
||||
var logs []user.UserResourcesLog
|
||||
condition := make(map[string]any)
|
||||
condition["user_id"] = req.UserId
|
||||
if req.ResName != "" {
|
||||
condition["res_name"] = req.ResName
|
||||
}
|
||||
if req.GameId > 0 {
|
||||
condition["game_id"] = req.GameId
|
||||
}
|
||||
if req.GameNo != "" {
|
||||
condition["game_no"] = req.GameNo
|
||||
}
|
||||
db := operation.LogDB.Where(condition)
|
||||
if req.StartTime != "" {
|
||||
db = db.Where("start_time >= ?", req.StartTime)
|
||||
}
|
||||
if req.EndTime != "" {
|
||||
db = db.Where("end_time <= ?", req.EndTime)
|
||||
}
|
||||
err = db.Find(&logs).Error
|
||||
if err != nil {
|
||||
log.ErrorF("find table:%v condition:%v err:%v", user.UserResourcesLog{}.TableName(), utils.JsonMarshal(condition), err)
|
||||
iMsg.RpcCode = int32(pb.ErrCode_SystemErr)
|
||||
return iMsg
|
||||
}
|
||||
iMsg.Msg, err = json.Marshal(logs)
|
||||
if err != nil {
|
||||
log.ErrorF("error marshalling user account %v", err)
|
||||
iMsg.RpcCode = int32(pb.ErrCode_SystemErr)
|
||||
return iMsg
|
||||
}
|
||||
return iMsg
|
||||
}
|
@ -19,5 +19,8 @@ func (s *DbService) initRpcProcessor() {
|
||||
rpc.AddUserResources: s.onAddUserResources,
|
||||
rpc.SaveGameRecordLog: s.onSaveGameRecordLog,
|
||||
rpc.SaveUserRecordLog: s.onSaveUserRecordLog,
|
||||
|
||||
// 日志查询
|
||||
rpc.RpcGetUserResLog: s.onGetUserResLogs,
|
||||
})
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user