+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 查询
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/common/modelOperator/tableOperator.go b/common/modelOperator/tableOperator.go
index c190e15..bf1292c 100644
--- a/common/modelOperator/tableOperator.go
+++ b/common/modelOperator/tableOperator.go
@@ -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 {
diff --git a/common/rpc/logRecord/rpcGetUserResLogs.go b/common/rpc/logRecord/rpcGetUserResLogs.go
new file mode 100644
index 0000000..a106606
--- /dev/null
+++ b/common/rpc/logRecord/rpcGetUserResLogs.go
@@ -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)
+}
diff --git a/common/rpc/rpcName.go b/common/rpc/rpcName.go
index 3e283ec..fee96a9 100644
--- a/common/rpc/rpcName.go
+++ b/common/rpc/rpcName.go
@@ -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" // 玩家金流查询
)
diff --git a/server/db/server/handlerLogRecord.go b/server/db/server/handlerLogRecord.go
new file mode 100644
index 0000000..1ba3baa
--- /dev/null
+++ b/server/db/server/handlerLogRecord.go
@@ -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
+}
diff --git a/server/db/server/processor.go b/server/db/server/processor.go
index b62a7ac..fe2cb53 100644
--- a/server/db/server/processor.go
+++ b/server/db/server/processor.go
@@ -19,5 +19,8 @@ func (s *DbService) initRpcProcessor() {
rpc.AddUserResources: s.onAddUserResources,
rpc.SaveGameRecordLog: s.onSaveGameRecordLog,
rpc.SaveUserRecordLog: s.onSaveUserRecordLog,
+
+ // 日志查询
+ rpc.RpcGetUserResLog: s.onGetUserResLogs,
})
}