feat: add media supply billing center
Frontend CI / Frontend (push) Successful in 5m44s
Backend CI / Backend (push) Failing after 6m58s

This commit is contained in:
2026-06-29 23:13:33 +08:00
parent 4040d22605
commit 31811b07d4
16 changed files with 926 additions and 12 deletions
@@ -2,6 +2,7 @@ package transport
import (
"strconv"
"time"
"github.com/gin-gonic/gin"
@@ -157,6 +158,58 @@ func listMediaSupplyWalletsHandler(svc *app.MediaSupplyService) gin.HandlerFunc
}
}
func listMediaSupplyBillingsHandler(svc *app.MediaSupplyService) gin.HandlerFunc {
return func(c *gin.Context) {
tenantID, err := parseOptionalOpsInt64Query(c, "tenant_id")
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_tenant_id", "租户参数必须是数字"))
return
}
userID, err := parseOptionalOpsInt64Query(c, "user_id")
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_user_id", "用户参数必须是数字"))
return
}
orderID, err := parseOptionalOpsInt64Query(c, "order_id")
if err != nil {
response.Error(c, response.ErrBadRequest(40001, "invalid_order_id", "订单参数必须是数字"))
return
}
startAt, err := parseOptionalOpsTimeQuery(c, "start_at")
if err != nil {
response.Error(c, response.ErrBadRequest(40003, "invalid_start_at", "start_at 必须是 RFC3339"))
return
}
endAt, err := parseOptionalOpsTimeQuery(c, "end_at")
if err != nil {
response.Error(c, response.ErrBadRequest(40004, "invalid_end_at", "end_at 必须是 RFC3339"))
return
}
if startAt != nil && endAt != nil && !startAt.Before(*endAt) {
response.Error(c, response.ErrBadRequest(40005, "invalid_billing_time_range", "结束时间必须晚于开始时间"))
return
}
page, _ := parseOptionalOpsIntQuery(c, "page")
size, _ := parseOptionalOpsIntQuery(c, "page_size")
result, err := svc.ListBillings(c.Request.Context(), app.ListMediaSupplyBillingsInput{
Keyword: c.Query("keyword"),
TenantID: tenantID,
UserID: userID,
OrderID: orderID,
Reason: c.Query("reason"),
StartAt: startAt,
EndAt: endAt,
Page: page,
Size: size,
})
if err != nil {
response.Error(c, err)
return
}
response.Success(c, result)
}
}
func adjustMediaSupplyWalletHandler(svc *app.MediaSupplyService) gin.HandlerFunc {
return func(c *gin.Context) {
var body adjustMediaSupplyWalletRequest
@@ -199,3 +252,15 @@ func parseOptionalOpsInt64Query(c *gin.Context, key string) (int64, error) {
}
return strconv.ParseInt(raw, 10, 64)
}
func parseOptionalOpsTimeQuery(c *gin.Context, key string) (*time.Time, error) {
raw := c.Query(key)
if raw == "" {
return nil, nil
}
parsed, err := time.Parse(time.RFC3339, raw)
if err != nil {
return nil, err
}
return &parsed, nil
}
+1
View File
@@ -139,6 +139,7 @@ func RegisterRoutes(d Deps) {
authed.PUT("/media-supply/resources/:id/visibility", setMediaSupplyResourceVisibilityHandler(d.MediaSupply))
authed.POST("/media-supply/sync-jobs", queueMediaSupplySyncHandler(d.MediaSupply))
authed.GET("/media-supply/wallets", listMediaSupplyWalletsHandler(d.MediaSupply))
authed.GET("/media-supply/billings", listMediaSupplyBillingsHandler(d.MediaSupply))
authed.POST("/media-supply/wallets/adjustments", adjustMediaSupplyWalletHandler(d.MediaSupply))
authed.GET("/scheduler/jobs", listSchedulerJobsHandler(d.Scheduler))