From 0d08ac88b85bc47ed6582ba3c722665fd4cbb1fb Mon Sep 17 00:00:00 2001 From: xuyang Date: Mon, 8 Jun 2026 19:16:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20stat=20=E6=96=B0=E5=A2=9E=E6=8C=89?= =?UTF-8?q?=E6=B8=B8=E6=88=8F=E7=BB=9F=E8=AE=A1=E5=85=85=E5=80=BC=E5=87=80?= =?UTF-8?q?=E9=A2=9D=E6=8E=A5=E5=8F=A3=20GetGamePayAmount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对接 stat.gaore.com 的 /pay/getGamePayAmount: - pay_channel.go:GetGamePayAmountReq/Resp/Param + 工厂函数(POST form, 入参 tdate/tdate2/game_id/group_by_date),返回 game_id + pay_amount(单位元); - client.go:新增 GetGamePayAmount 方法; - client_test.go:新增 TestGetGamePayAmount。 Co-Authored-By: Claude Opus 4.8 (1M context) --- services/stat/client.go | 7 ++++ services/stat/client_test.go | 28 ++++++++++++++ services/stat/pay_channel.go | 73 ++++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 services/stat/pay_channel.go diff --git a/services/stat/client.go b/services/stat/client.go index 4338705..7ef6891 100644 --- a/services/stat/client.go +++ b/services/stat/client.go @@ -157,3 +157,10 @@ func (c *Client) CallbackWeightUpdate(req *CallbackWeightUpdateReq) (resp *Callb err = c.DoAction(req, resp) return } + +// GetGamePayAmount 按游戏统计充值净额(gr_pay_channel.pay_amount) +func (c *Client) GetGamePayAmount(req *GetGamePayAmountReq) (resp *GetGamePayAmountResp, err error) { + resp = CreateGetGamePayAmountResp() + err = c.DoAction(req, resp) + return +} diff --git a/services/stat/client_test.go b/services/stat/client_test.go index dee3bbc..4844991 100644 --- a/services/stat/client_test.go +++ b/services/stat/client_test.go @@ -350,3 +350,31 @@ func TestCallbackWeightUpdate(t *testing.T) { } t.Log(resp) } + +// TestGetGamePayAmount 按游戏统计充值净额(pay_amount,单位元) +func TestGetGamePayAmount(t *testing.T) { + client, err := NewClient() + if err != nil { + t.Fatal(err) + } + req := CreateGetGamePayAmountReq(GetGamePayAmountParam{ + Tdate: "2026-05-01", // 开始日期 + Tdate2: "2026-05-31", // 结束日期(含当天) + GameIds: []int64{3706}, // 游戏id(=switch_game_id),传 nil 则全部 + GroupByDate: false, // 仅按游戏汇总;true 则按日期+游戏拆分 + }) + + resp, err := client.GetGamePayAmount(req) + if err != nil { + t.Fatal(err) + } + fmt.Println(resp.Code, resp.Msg) + for _, r := range resp.Data.List { + fmt.Printf("tdate=%s game_id=%d pay_amount=%.2f\n", r.Tdate, r.GameId, r.PayAmount) + } + + // 成功码为 1 + if resp.Code != 1 { + t.Errorf("GetGamePayAmount failed: code=%d msg=%s", resp.Code, resp.Msg) + } +} diff --git a/services/stat/pay_channel.go b/services/stat/pay_channel.go new file mode 100644 index 0000000..2009423 --- /dev/null +++ b/services/stat/pay_channel.go @@ -0,0 +1,73 @@ +package stat + +import ( + "strconv" + "strings" + + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/requests" + "golib.gaore.com/GaoreGo/gaore-common-sdk-go/sdk/responses" +) + +// GetGamePayAmountReq 按游戏统计充值净额(gr_pay_channel.pay_amount)请求 +type GetGamePayAmountReq struct { + *requests.RpcRequest +} + +// GetGamePayAmountParam 调用参数 +type GetGamePayAmountParam struct { + Tdate string // 开始日期 YYYY-MM-DD(必填) + Tdate2 string // 结束日期 YYYY-MM-DD(选填,含当天) + GameIds []int64 // 游戏id(选填,空=全部游戏) + GroupByDate bool // true=按日期+游戏分组;false=仅按游戏汇总 +} + +// GetGamePayAmountResp 响应 +type GetGamePayAmountResp struct { + *responses.BaseResponse + Code int `json:"code"` + Msg string `json:"msg"` + Data GamePayAmountList `json:"data"` +} + +type GamePayAmountList struct { + List []GamePayAmount `json:"list"` +} + +// GamePayAmount 单条统计;未按日期分组时 Tdate 为空 +type GamePayAmount struct { + Tdate string `json:"tdate"` + GameId int64 `json:"game_id"` + PayAmount float64 `json:"pay_amount"` // 充值净额,单位:元 +} + +// CreateGetGamePayAmountReq 创建「按游戏统计充值净额」请求 +func CreateGetGamePayAmountReq(param GetGamePayAmountParam) *GetGamePayAmountReq { + req := &GetGamePayAmountReq{ + &requests.RpcRequest{}, + } + req.InitWithApiInfo(HOST, VERSION, "/pay/getGamePayAmount") + req.Method = requests.POST + + gameIds := make([]string, 0, len(param.GameIds)) + for _, id := range param.GameIds { + gameIds = append(gameIds, strconv.FormatInt(id, 10)) + } + groupByDate := "0" + if param.GroupByDate { + groupByDate = "1" + } + req.FormParams = map[string]string{ + "tdate": param.Tdate, + "tdate2": param.Tdate2, + "game_id": strings.Join(gameIds, ","), + "group_by_date": groupByDate, + } + return req +} + +// CreateGetGamePayAmountResp 创建响应对象 +func CreateGetGamePayAmountResp() *GetGamePayAmountResp { + return &GetGamePayAmountResp{ + BaseResponse: &responses.BaseResponse{}, + } +}