feat: expand merchant revenue statistics
This commit is contained in:
@@ -123,6 +123,10 @@ export PAY007_KEY=your-secret-key
|
||||
007pay stats --begin "2026-07-01 00:00:00" --end "2026-07-31 23:59:59"
|
||||
```
|
||||
|
||||
`StatsResponse` includes order counts by state, manual-order count, gross and
|
||||
received amounts, successful refund count/amount, fee, and net amount. All
|
||||
amount fields use cents.
|
||||
|
||||
签名调试:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -67,3 +67,55 @@ func TestSubmitPostsSignedForm(t *testing.T) {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatsDecodesDetailedResponse(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/pay/stats" {
|
||||
t.Fatalf("path = %s", r.URL.Path)
|
||||
}
|
||||
params := map[string]string{}
|
||||
for key, values := range r.URL.Query() {
|
||||
if len(values) > 0 {
|
||||
params[key] = values[0]
|
||||
}
|
||||
}
|
||||
if !VerifySign(params, "secret") {
|
||||
t.Fatalf("invalid sign: %s", params["sign"])
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"code": 200,
|
||||
"message": "Success",
|
||||
"data": map[string]any{
|
||||
"order_count": 3,
|
||||
"total_order_count": 5,
|
||||
"paid_order_count": 3,
|
||||
"unpaid_order_count": 2,
|
||||
"refunded_order_count": 1,
|
||||
"closed_order_count": 1,
|
||||
"manual_order_count": 1,
|
||||
"total_amount": 17000,
|
||||
"received_amount": 11000,
|
||||
"refund_amount": 6000,
|
||||
"refund_count": 2,
|
||||
"total_fee": 170,
|
||||
"net_amount": 10830,
|
||||
},
|
||||
})
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client, err := NewClient(server.URL, "pid-1", "secret")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp, err := client.Stats(context.Background(), StatsRequest{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if resp.TotalOrderCount != 5 || resp.PaidOrderCount != 3 ||
|
||||
resp.RefundedOrderCount != 1 || resp.RefundCount != 2 ||
|
||||
resp.ReceivedAmount != 11000 || resp.NetAmount != 10830 {
|
||||
t.Fatalf("unexpected response: %+v", resp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,8 +168,17 @@ func (r StatsRequest) params() map[string]string {
|
||||
}
|
||||
|
||||
type StatsResponse struct {
|
||||
OrderCount int64 `json:"order_count"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
TotalFee int64 `json:"total_fee"`
|
||||
NetAmount int64 `json:"net_amount"`
|
||||
OrderCount int64 `json:"order_count"`
|
||||
TotalAmount int64 `json:"total_amount"`
|
||||
TotalFee int64 `json:"total_fee"`
|
||||
NetAmount int64 `json:"net_amount"`
|
||||
TotalOrderCount int64 `json:"total_order_count"`
|
||||
PaidOrderCount int64 `json:"paid_order_count"`
|
||||
UnpaidOrderCount int64 `json:"unpaid_order_count"`
|
||||
RefundedOrderCount int64 `json:"refunded_order_count"`
|
||||
ClosedOrderCount int64 `json:"closed_order_count"`
|
||||
ManualOrderCount int64 `json:"manual_order_count"`
|
||||
ReceivedAmount int64 `json:"received_amount"`
|
||||
RefundAmount int64 `json:"refund_amount"`
|
||||
RefundCount int64 `json:"refund_count"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user