Compare commits
2 Commits
71bd15024e
...
86a1a0a2cc
| Author | SHA1 | Date | |
|---|---|---|---|
| 86a1a0a2cc | |||
| 549339be74 |
@@ -14,6 +14,9 @@ type AdminOrderListFilter struct {
|
||||
// Pagination 分页参数:page/limit(通用)。
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
|
||||
// SortQueryFilter 排序参数:asc/desc(逗号分隔字段名);字段白名单在 service 层统一校验。
|
||||
requests.SortQueryFilter `json:",inline" query:",inline"`
|
||||
|
||||
// UserID 下单用户ID(可选):按买家用户ID精确过滤。
|
||||
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||
|
||||
|
||||
13
backend/app/http/tenant/dto/order_admin_export.go
Normal file
13
backend/app/http/tenant/dto/order_admin_export.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package dto
|
||||
|
||||
// AdminOrderExportResponse 租户管理员订单导出响应(CSV 文本)。
|
||||
type AdminOrderExportResponse struct {
|
||||
// Filename 建议文件名:前端可用于下载时的默认文件名。
|
||||
Filename string `json:"filename"`
|
||||
|
||||
// ContentType 内容类型:当前固定为 text/csv。
|
||||
ContentType string `json:"content_type"`
|
||||
|
||||
// CSV CSV 文本内容:UTF-8 编码,包含表头与数据行;前端可直接下载为文件。
|
||||
CSV string `json:"csv"`
|
||||
}
|
||||
@@ -63,6 +63,41 @@ func (*orderAdmin) adminOrderList(
|
||||
return services.Order.AdminOrderPage(ctx, tenant.ID, filter)
|
||||
}
|
||||
|
||||
// adminOrderExport
|
||||
//
|
||||
// @Summary 订单导出(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param filter query dto.AdminOrderListFilter true "Filter"
|
||||
// @Success 200 {object} dto.AdminOrderExportResponse
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/orders/export [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind filter query
|
||||
func (*orderAdmin) adminOrderExport(
|
||||
ctx fiber.Ctx,
|
||||
tenant *models.Tenant,
|
||||
tenantUser *models.TenantUser,
|
||||
filter *dto.AdminOrderListFilter,
|
||||
) (*dto.AdminOrderExportResponse, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.AdminOrderListFilter{}
|
||||
}
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
}).Info("tenant.admin.orders.export")
|
||||
|
||||
return services.Order.AdminOrderExportCSV(ctx.Context(), tenant.ID, filter)
|
||||
}
|
||||
|
||||
// adminOrderDetail
|
||||
//
|
||||
// @Summary 订单详情(租户管理)
|
||||
|
||||
@@ -156,6 +156,13 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
PathParam[int64]("orderID"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/admin/orders/export -> orderAdmin.adminOrderExport")
|
||||
router.Get("/t/:tenantCode/v1/admin/orders/export"[len(r.Path()):], DataFunc3(
|
||||
r.orderAdmin.adminOrderExport,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
Query[dto.AdminOrderListFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /t/:tenantCode/v1/admin/orders/:orderID/refund -> orderAdmin.adminRefund")
|
||||
router.Post("/t/:tenantCode/v1/admin/orders/:orderID/refund"[len(r.Path()):], DataFunc4(
|
||||
r.orderAdmin.adminRefund,
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/csv"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -18,12 +21,165 @@ import (
|
||||
"github.com/samber/lo"
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/field"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
// AdminOrderExportCSV 租户管理员导出订单列表(CSV 文本)。
|
||||
func (s *order) AdminOrderExportCSV(ctx context.Context, tenantID int64, filter *dto.AdminOrderListFilter) (*dto.AdminOrderExportResponse, error) {
|
||||
if tenantID <= 0 {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("tenant_id must be > 0")
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.AdminOrderListFilter{}
|
||||
}
|
||||
|
||||
// 导出属于高消耗操作:限制最大行数,避免拖垮数据库。
|
||||
const maxRows = 5000
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"tenant_id": tenantID,
|
||||
"max_rows": maxRows,
|
||||
"user_id": lo.FromPtr(filter.UserID),
|
||||
"username": filter.UsernameTrimmed(),
|
||||
"content_id": lo.FromPtr(filter.ContentID),
|
||||
"content_title": filter.ContentTitleTrimmed(),
|
||||
"type": lo.FromPtr(filter.Type),
|
||||
"status": lo.FromPtr(filter.Status),
|
||||
}).Info("services.order.admin.export_csv")
|
||||
|
||||
tbl, query := models.OrderQuery.QueryContext(ctx)
|
||||
conds := []gen.Condition{tbl.TenantID.Eq(tenantID)}
|
||||
if filter.UserID != nil {
|
||||
conds = append(conds, tbl.UserID.Eq(*filter.UserID))
|
||||
}
|
||||
if filter.Type != nil {
|
||||
conds = append(conds, tbl.Type.Eq(*filter.Type))
|
||||
}
|
||||
if filter.Status != nil {
|
||||
conds = append(conds, tbl.Status.Eq(*filter.Status))
|
||||
}
|
||||
if filter.CreatedAtFrom != nil {
|
||||
conds = append(conds, tbl.CreatedAt.Gte(*filter.CreatedAtFrom))
|
||||
}
|
||||
if filter.CreatedAtTo != nil {
|
||||
conds = append(conds, tbl.CreatedAt.Lte(*filter.CreatedAtTo))
|
||||
}
|
||||
if filter.PaidAtFrom != nil {
|
||||
conds = append(conds, tbl.PaidAt.Gte(*filter.PaidAtFrom))
|
||||
}
|
||||
if filter.PaidAtTo != nil {
|
||||
conds = append(conds, tbl.PaidAt.Lte(*filter.PaidAtTo))
|
||||
}
|
||||
if filter.AmountPaidMin != nil {
|
||||
conds = append(conds, tbl.AmountPaid.Gte(*filter.AmountPaidMin))
|
||||
}
|
||||
if filter.AmountPaidMax != nil {
|
||||
conds = append(conds, tbl.AmountPaid.Lte(*filter.AmountPaidMax))
|
||||
}
|
||||
|
||||
if username := filter.UsernameTrimmed(); username != "" {
|
||||
uTbl, _ := models.UserQuery.QueryContext(ctx)
|
||||
query = query.LeftJoin(uTbl, uTbl.ID.EqCol(tbl.UserID))
|
||||
conds = append(conds, uTbl.Username.Like(database.WrapLike(username)))
|
||||
}
|
||||
|
||||
needItemJoin := (filter.ContentID != nil && *filter.ContentID > 0) || filter.ContentTitleTrimmed() != ""
|
||||
if needItemJoin {
|
||||
oiTbl, _ := models.OrderItemQuery.QueryContext(ctx)
|
||||
query = query.LeftJoin(oiTbl, oiTbl.OrderID.EqCol(tbl.ID))
|
||||
if filter.ContentID != nil && *filter.ContentID > 0 {
|
||||
conds = append(conds, oiTbl.ContentID.Eq(*filter.ContentID))
|
||||
}
|
||||
if title := filter.ContentTitleTrimmed(); title != "" {
|
||||
cTbl, _ := models.ContentQuery.QueryContext(ctx)
|
||||
query = query.LeftJoin(cTbl, cTbl.ID.EqCol(oiTbl.ContentID))
|
||||
conds = append(conds, cTbl.Title.Like(database.WrapLike(title)))
|
||||
}
|
||||
query = query.Group(tbl.ID)
|
||||
}
|
||||
|
||||
// 排序:复用 AdminOrderPage 的白名单,避免任意字段导致注入/慢查询。
|
||||
orderBys := make([]field.Expr, 0, 4)
|
||||
allowedAsc := map[string]field.Expr{
|
||||
"id": tbl.ID.Asc(),
|
||||
"created_at": tbl.CreatedAt.Asc(),
|
||||
"paid_at": tbl.PaidAt.Asc(),
|
||||
"amount_paid": tbl.AmountPaid.Asc(),
|
||||
}
|
||||
allowedDesc := map[string]field.Expr{
|
||||
"id": tbl.ID.Desc(),
|
||||
"created_at": tbl.CreatedAt.Desc(),
|
||||
"paid_at": tbl.PaidAt.Desc(),
|
||||
"amount_paid": tbl.AmountPaid.Desc(),
|
||||
}
|
||||
for _, f := range filter.AscFields() {
|
||||
f = strings.TrimSpace(f)
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if ob, ok := allowedAsc[f]; ok {
|
||||
orderBys = append(orderBys, ob)
|
||||
}
|
||||
}
|
||||
for _, f := range filter.DescFields() {
|
||||
f = strings.TrimSpace(f)
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if ob, ok := allowedDesc[f]; ok {
|
||||
orderBys = append(orderBys, ob)
|
||||
}
|
||||
}
|
||||
if len(orderBys) == 0 {
|
||||
orderBys = append(orderBys, tbl.ID.Desc())
|
||||
} else {
|
||||
orderBys = append(orderBys, tbl.ID.Desc())
|
||||
}
|
||||
|
||||
items, err := query.Where(conds...).Order(orderBys...).Limit(maxRows).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
w := csv.NewWriter(buf)
|
||||
_ = w.Write([]string{"id", "tenant_id", "user_id", "type", "status", "amount_paid", "paid_at", "created_at"})
|
||||
for _, it := range items {
|
||||
if it == nil {
|
||||
continue
|
||||
}
|
||||
paidAt := ""
|
||||
if !it.PaidAt.IsZero() {
|
||||
paidAt = it.PaidAt.UTC().Format(time.RFC3339)
|
||||
}
|
||||
_ = w.Write([]string{
|
||||
fmt.Sprintf("%d", it.ID),
|
||||
fmt.Sprintf("%d", it.TenantID),
|
||||
fmt.Sprintf("%d", it.UserID),
|
||||
string(it.Type),
|
||||
string(it.Status),
|
||||
fmt.Sprintf("%d", it.AmountPaid),
|
||||
paidAt,
|
||||
it.CreatedAt.UTC().Format(time.RFC3339),
|
||||
})
|
||||
}
|
||||
w.Flush()
|
||||
if err := w.Error(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("tenant_%d_orders_%s.csv", tenantID, time.Now().UTC().Format("20060102_150405"))
|
||||
return &dto.AdminOrderExportResponse{
|
||||
Filename: filename,
|
||||
ContentType: "text/csv",
|
||||
CSV: buf.String(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PurchaseOrderSnapshot 为“内容购买订单”的下单快照(用于历史展示与争议审计)。
|
||||
type PurchaseOrderSnapshot struct {
|
||||
// ContentID 内容ID。
|
||||
@@ -428,7 +584,47 @@ func (s *order) AdminOrderPage(
|
||||
query = query.Group(tbl.ID)
|
||||
}
|
||||
|
||||
items, total, err := query.Where(conds...).Order(tbl.ID.Desc()).FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
// 排序白名单:避免把任意字符串拼进 SQL 导致注入或慢查询。
|
||||
// 约定:只允许按以下字段排序;未指定时默认按 id desc。
|
||||
orderBys := make([]field.Expr, 0, 4)
|
||||
allowedAsc := map[string]field.Expr{
|
||||
"id": tbl.ID.Asc(),
|
||||
"created_at": tbl.CreatedAt.Asc(),
|
||||
"paid_at": tbl.PaidAt.Asc(),
|
||||
"amount_paid": tbl.AmountPaid.Asc(),
|
||||
}
|
||||
allowedDesc := map[string]field.Expr{
|
||||
"id": tbl.ID.Desc(),
|
||||
"created_at": tbl.CreatedAt.Desc(),
|
||||
"paid_at": tbl.PaidAt.Desc(),
|
||||
"amount_paid": tbl.AmountPaid.Desc(),
|
||||
}
|
||||
for _, f := range filter.AscFields() {
|
||||
f = strings.TrimSpace(f)
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if ob, ok := allowedAsc[f]; ok {
|
||||
orderBys = append(orderBys, ob)
|
||||
}
|
||||
}
|
||||
for _, f := range filter.DescFields() {
|
||||
f = strings.TrimSpace(f)
|
||||
if f == "" {
|
||||
continue
|
||||
}
|
||||
if ob, ok := allowedDesc[f]; ok {
|
||||
orderBys = append(orderBys, ob)
|
||||
}
|
||||
}
|
||||
// 默认加上 id desc 作为稳定排序(尤其是 join + group 的场景)。
|
||||
if len(orderBys) == 0 {
|
||||
orderBys = append(orderBys, tbl.ID.Desc())
|
||||
} else {
|
||||
orderBys = append(orderBys, tbl.ID.Desc())
|
||||
}
|
||||
|
||||
items, total, err := query.Where(conds...).Order(orderBys...).FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"quyun/v2/app/commands/testx"
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
@@ -590,6 +591,58 @@ func (s *OrderTestSuite) Test_AdminOrderPage() {
|
||||
So(pager.Total, ShouldEqual, 1)
|
||||
})
|
||||
|
||||
Convey("按排序字段(asc/desc)排序(白名单)", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
o1 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 2,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 500,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now.Add(-time.Hour),
|
||||
UpdatedAt: now.Add(-time.Hour),
|
||||
}
|
||||
So(o1.Create(ctx), ShouldBeNil)
|
||||
|
||||
o2 := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: 3,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 100,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o2.Create(ctx), ShouldBeNil)
|
||||
|
||||
asc := "amount_paid"
|
||||
pagerAsc, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
SortQueryFilter: requests.SortQueryFilter{Asc: &asc},
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pagerAsc.Total, ShouldEqual, 2)
|
||||
itemsAsc, ok := pagerAsc.Items.([]*models.Order)
|
||||
So(ok, ShouldBeTrue)
|
||||
So(itemsAsc[0].AmountPaid, ShouldEqual, 100)
|
||||
|
||||
desc := "created_at"
|
||||
pagerDesc, err := Order.AdminOrderPage(ctx, tenantID, &dto.AdminOrderListFilter{
|
||||
SortQueryFilter: requests.SortQueryFilter{Desc: &desc},
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
So(pagerDesc.Total, ShouldEqual, 2)
|
||||
itemsDesc, ok := pagerDesc.Items.([]*models.Order)
|
||||
So(ok, ShouldBeTrue)
|
||||
So(itemsDesc[0].CreatedAt.After(itemsDesc[1].CreatedAt), ShouldBeTrue)
|
||||
})
|
||||
|
||||
Convey("按 type 过滤", func() {
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder)
|
||||
|
||||
@@ -774,6 +827,56 @@ func (s *OrderTestSuite) Test_AdminOrderDetail() {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OrderTestSuite) Test_AdminOrderExportCSV() {
|
||||
Convey("Order.AdminOrderExportCSV", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
now := time.Now().UTC()
|
||||
tenantID := int64(1)
|
||||
|
||||
s.truncate(ctx, models.TableNameOrderItem, models.TableNameOrder, models.TableNameUser, models.TableNameContent)
|
||||
|
||||
Convey("参数非法应返回错误", func() {
|
||||
_, err := Order.AdminOrderExportCSV(ctx, 0, &dto.AdminOrderListFilter{})
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("导出应返回 CSV 且包含表头", func() {
|
||||
u := &models.User{
|
||||
Username: "alice",
|
||||
Password: "x",
|
||||
Roles: types.NewArray([]consts.Role{consts.RoleUser}),
|
||||
Status: consts.UserStatusVerified,
|
||||
Metas: types.JSON([]byte("{}")),
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(u.Create(ctx), ShouldBeNil)
|
||||
|
||||
o := &models.Order{
|
||||
TenantID: tenantID,
|
||||
UserID: u.ID,
|
||||
Type: consts.OrderTypeContentPurchase,
|
||||
Status: consts.OrderStatusPaid,
|
||||
Currency: consts.CurrencyCNY,
|
||||
AmountPaid: 123,
|
||||
Snapshot: types.JSON([]byte("{}")),
|
||||
PaidAt: now,
|
||||
CreatedAt: now,
|
||||
UpdatedAt: now,
|
||||
}
|
||||
So(o.Create(ctx), ShouldBeNil)
|
||||
|
||||
resp, err := Order.AdminOrderExportCSV(ctx, tenantID, &dto.AdminOrderListFilter{})
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.ContentType, ShouldEqual, "text/csv")
|
||||
So(resp.Filename, ShouldContainSubstring, "tenant_1_orders_")
|
||||
So(resp.CSV, ShouldContainSubstring, "id,tenant_id,user_id,type,status,amount_paid,paid_at,created_at")
|
||||
So(resp.CSV, ShouldContainSubstring, "content_purchase")
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func (s *OrderTestSuite) Test_AdminRefundOrder() {
|
||||
Convey("Order.AdminRefundOrder", s.T(), func() {
|
||||
ctx := s.T().Context()
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
-- orders 列表查询索引补齐:租户管理端常用按 created_at/type 过滤 + 排序。
|
||||
CREATE INDEX IF NOT EXISTS ix_orders_tenant_created_at ON orders(tenant_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS ix_orders_tenant_type ON orders(tenant_id, type);
|
||||
-- +goose StatementEnd
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP INDEX IF EXISTS ix_orders_tenant_type;
|
||||
DROP INDEX IF EXISTS ix_orders_tenant_created_at;
|
||||
-- +goose StatementEnd
|
||||
@@ -971,6 +971,12 @@ const docTemplate = `{
|
||||
"name": "amount_paid_min",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Asc specifies comma-separated field names to sort ascending by.",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ContentID 内容ID(可选):通过 order_items 关联过滤。",
|
||||
@@ -995,6 +1001,12 @@ const docTemplate = `{
|
||||
"name": "created_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Desc specifies comma-separated field names to sort descending by.",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
|
||||
@@ -1090,6 +1102,157 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/t/{tenantCode}/v1/admin/orders/export": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Tenant"
|
||||
],
|
||||
"summary": "订单导出(租户管理)",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Tenant Code",
|
||||
"name": "tenantCode",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "AmountPaidMax 实付金额上限(可选):amount_paid \u003c= 该值(单位分)。",
|
||||
"name": "amount_paid_max",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "AmountPaidMin 实付金额下限(可选):amount_paid \u003e= 该值(单位分)。",
|
||||
"name": "amount_paid_min",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Asc specifies comma-separated field names to sort ascending by.",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ContentID 内容ID(可选):通过 order_items 关联过滤。",
|
||||
"name": "content_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ContentTitle 内容标题关键字(可选):通过 order_items + contents 关联,模糊匹配 contents.title(like)。",
|
||||
"name": "content_title",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "CreatedAtFrom 创建时间起(可选):created_at \u003e= 该时间(用于按创建时间筛选)。",
|
||||
"name": "created_at_from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "CreatedAtTo 创建时间止(可选):created_at \u003c= 该时间(用于按创建时间筛选)。",
|
||||
"name": "created_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Desc specifies comma-separated field names to sort descending by.",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page is 1-based page index; values \u003c= 0 are normalized to 1.",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "PaidAtFrom 支付时间起(可选):paid_at \u003e= 该时间(用于按支付时间筛选)。",
|
||||
"name": "paid_at_from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "PaidAtTo 支付时间止(可选):paid_at \u003c= 该时间(用于按支付时间筛选)。",
|
||||
"name": "paid_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"created",
|
||||
"paid",
|
||||
"refunding",
|
||||
"refunded",
|
||||
"canceled",
|
||||
"failed"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
"OrderStatusCreated",
|
||||
"OrderStatusPaid",
|
||||
"OrderStatusRefunding",
|
||||
"OrderStatusRefunded",
|
||||
"OrderStatusCanceled",
|
||||
"OrderStatusFailed"
|
||||
],
|
||||
"description": "Status 订单状态(可选):created/paid/refunding/refunded/canceled/failed。",
|
||||
"name": "status",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"content_purchase",
|
||||
"topup"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
"OrderTypeContentPurchase",
|
||||
"OrderTypeTopup"
|
||||
],
|
||||
"description": "Type 订单类型(可选):content_purchase/topup 等。",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "UserID 下单用户ID(可选):按买家用户ID精确过滤。",
|
||||
"name": "user_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Username 下单用户用户名关键字(可选):模糊匹配 users.username(like)。",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.AdminOrderExportResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/t/{tenantCode}/v1/admin/orders/{orderID}": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
@@ -2239,6 +2402,23 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AdminOrderExportResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content_type": {
|
||||
"description": "ContentType 内容类型:当前固定为 text/csv。",
|
||||
"type": "string"
|
||||
},
|
||||
"csv": {
|
||||
"description": "CSV CSV 文本内容:UTF-8 编码,包含表头与数据行;前端可直接下载为文件。",
|
||||
"type": "string"
|
||||
},
|
||||
"filename": {
|
||||
"description": "Filename 建议文件名:前端可用于下载时的默认文件名。",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AdminOrderRefundForm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -965,6 +965,12 @@
|
||||
"name": "amount_paid_min",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Asc specifies comma-separated field names to sort ascending by.",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ContentID 内容ID(可选):通过 order_items 关联过滤。",
|
||||
@@ -989,6 +995,12 @@
|
||||
"name": "created_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Desc specifies comma-separated field names to sort descending by.",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
|
||||
@@ -1084,6 +1096,157 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/t/{tenantCode}/v1/admin/orders/export": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Tenant"
|
||||
],
|
||||
"summary": "订单导出(租户管理)",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Tenant Code",
|
||||
"name": "tenantCode",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "AmountPaidMax 实付金额上限(可选):amount_paid \u003c= 该值(单位分)。",
|
||||
"name": "amount_paid_max",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "AmountPaidMin 实付金额下限(可选):amount_paid \u003e= 该值(单位分)。",
|
||||
"name": "amount_paid_min",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Asc specifies comma-separated field names to sort ascending by.",
|
||||
"name": "asc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "ContentID 内容ID(可选):通过 order_items 关联过滤。",
|
||||
"name": "content_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "ContentTitle 内容标题关键字(可选):通过 order_items + contents 关联,模糊匹配 contents.title(like)。",
|
||||
"name": "content_title",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "CreatedAtFrom 创建时间起(可选):created_at \u003e= 该时间(用于按创建时间筛选)。",
|
||||
"name": "created_at_from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "CreatedAtTo 创建时间止(可选):created_at \u003c= 该时间(用于按创建时间筛选)。",
|
||||
"name": "created_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Desc specifies comma-separated field names to sort descending by.",
|
||||
"name": "desc",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Limit is page size; only values in {10,20,50,100} are accepted (otherwise defaults to 10).",
|
||||
"name": "limit",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Page is 1-based page index; values \u003c= 0 are normalized to 1.",
|
||||
"name": "page",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "PaidAtFrom 支付时间起(可选):paid_at \u003e= 该时间(用于按支付时间筛选)。",
|
||||
"name": "paid_at_from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "PaidAtTo 支付时间止(可选):paid_at \u003c= 该时间(用于按支付时间筛选)。",
|
||||
"name": "paid_at_to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"created",
|
||||
"paid",
|
||||
"refunding",
|
||||
"refunded",
|
||||
"canceled",
|
||||
"failed"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
"OrderStatusCreated",
|
||||
"OrderStatusPaid",
|
||||
"OrderStatusRefunding",
|
||||
"OrderStatusRefunded",
|
||||
"OrderStatusCanceled",
|
||||
"OrderStatusFailed"
|
||||
],
|
||||
"description": "Status 订单状态(可选):created/paid/refunding/refunded/canceled/failed。",
|
||||
"name": "status",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"enum": [
|
||||
"content_purchase",
|
||||
"topup"
|
||||
],
|
||||
"type": "string",
|
||||
"x-enum-varnames": [
|
||||
"OrderTypeContentPurchase",
|
||||
"OrderTypeTopup"
|
||||
],
|
||||
"description": "Type 订单类型(可选):content_purchase/topup 等。",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "UserID 下单用户ID(可选):按买家用户ID精确过滤。",
|
||||
"name": "user_id",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Username 下单用户用户名关键字(可选):模糊匹配 users.username(like)。",
|
||||
"name": "username",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/dto.AdminOrderExportResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/t/{tenantCode}/v1/admin/orders/{orderID}": {
|
||||
"get": {
|
||||
"consumes": [
|
||||
@@ -2233,6 +2396,23 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AdminOrderExportResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"content_type": {
|
||||
"description": "ContentType 内容类型:当前固定为 text/csv。",
|
||||
"type": "string"
|
||||
},
|
||||
"csv": {
|
||||
"description": "CSV CSV 文本内容:UTF-8 编码,包含表头与数据行;前端可直接下载为文件。",
|
||||
"type": "string"
|
||||
},
|
||||
"filename": {
|
||||
"description": "Filename 建议文件名:前端可用于下载时的默认文件名。",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"dto.AdminOrderRefundForm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -187,6 +187,18 @@ definitions:
|
||||
- $ref: '#/definitions/models.Order'
|
||||
description: Order is the order with items preloaded.
|
||||
type: object
|
||||
dto.AdminOrderExportResponse:
|
||||
properties:
|
||||
content_type:
|
||||
description: ContentType 内容类型:当前固定为 text/csv。
|
||||
type: string
|
||||
csv:
|
||||
description: CSV CSV 文本内容:UTF-8 编码,包含表头与数据行;前端可直接下载为文件。
|
||||
type: string
|
||||
filename:
|
||||
description: Filename 建议文件名:前端可用于下载时的默认文件名。
|
||||
type: string
|
||||
type: object
|
||||
dto.AdminOrderRefundForm:
|
||||
properties:
|
||||
force:
|
||||
@@ -1775,6 +1787,10 @@ paths:
|
||||
in: query
|
||||
name: amount_paid_min
|
||||
type: integer
|
||||
- description: Asc specifies comma-separated field names to sort ascending by.
|
||||
in: query
|
||||
name: asc
|
||||
type: string
|
||||
- description: ContentID 内容ID(可选):通过 order_items 关联过滤。
|
||||
in: query
|
||||
name: content_id
|
||||
@@ -1791,6 +1807,11 @@ paths:
|
||||
in: query
|
||||
name: created_at_to
|
||||
type: string
|
||||
- description: Desc specifies comma-separated field names to sort descending
|
||||
by.
|
||||
in: query
|
||||
name: desc
|
||||
type: string
|
||||
- description: Limit is page size; only values in {10,20,50,100} are accepted
|
||||
(otherwise defaults to 10).
|
||||
in: query
|
||||
@@ -1917,6 +1938,112 @@ paths:
|
||||
summary: 订单退款(租户管理)
|
||||
tags:
|
||||
- Tenant
|
||||
/t/{tenantCode}/v1/admin/orders/export:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
parameters:
|
||||
- description: Tenant Code
|
||||
in: path
|
||||
name: tenantCode
|
||||
required: true
|
||||
type: string
|
||||
- description: AmountPaidMax 实付金额上限(可选):amount_paid <= 该值(单位分)。
|
||||
in: query
|
||||
name: amount_paid_max
|
||||
type: integer
|
||||
- description: AmountPaidMin 实付金额下限(可选):amount_paid >= 该值(单位分)。
|
||||
in: query
|
||||
name: amount_paid_min
|
||||
type: integer
|
||||
- description: Asc specifies comma-separated field names to sort ascending by.
|
||||
in: query
|
||||
name: asc
|
||||
type: string
|
||||
- description: ContentID 内容ID(可选):通过 order_items 关联过滤。
|
||||
in: query
|
||||
name: content_id
|
||||
type: integer
|
||||
- description: ContentTitle 内容标题关键字(可选):通过 order_items + contents 关联,模糊匹配 contents.title(like)。
|
||||
in: query
|
||||
name: content_title
|
||||
type: string
|
||||
- description: CreatedAtFrom 创建时间起(可选):created_at >= 该时间(用于按创建时间筛选)。
|
||||
in: query
|
||||
name: created_at_from
|
||||
type: string
|
||||
- description: CreatedAtTo 创建时间止(可选):created_at <= 该时间(用于按创建时间筛选)。
|
||||
in: query
|
||||
name: created_at_to
|
||||
type: string
|
||||
- description: Desc specifies comma-separated field names to sort descending
|
||||
by.
|
||||
in: query
|
||||
name: desc
|
||||
type: string
|
||||
- description: Limit is page size; only values in {10,20,50,100} are accepted
|
||||
(otherwise defaults to 10).
|
||||
in: query
|
||||
name: limit
|
||||
type: integer
|
||||
- description: Page is 1-based page index; values <= 0 are normalized to 1.
|
||||
in: query
|
||||
name: page
|
||||
type: integer
|
||||
- description: PaidAtFrom 支付时间起(可选):paid_at >= 该时间(用于按支付时间筛选)。
|
||||
in: query
|
||||
name: paid_at_from
|
||||
type: string
|
||||
- description: PaidAtTo 支付时间止(可选):paid_at <= 该时间(用于按支付时间筛选)。
|
||||
in: query
|
||||
name: paid_at_to
|
||||
type: string
|
||||
- description: Status 订单状态(可选):created/paid/refunding/refunded/canceled/failed。
|
||||
enum:
|
||||
- created
|
||||
- paid
|
||||
- refunding
|
||||
- refunded
|
||||
- canceled
|
||||
- failed
|
||||
in: query
|
||||
name: status
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- OrderStatusCreated
|
||||
- OrderStatusPaid
|
||||
- OrderStatusRefunding
|
||||
- OrderStatusRefunded
|
||||
- OrderStatusCanceled
|
||||
- OrderStatusFailed
|
||||
- description: Type 订单类型(可选):content_purchase/topup 等。
|
||||
enum:
|
||||
- content_purchase
|
||||
- topup
|
||||
in: query
|
||||
name: type
|
||||
type: string
|
||||
x-enum-varnames:
|
||||
- OrderTypeContentPurchase
|
||||
- OrderTypeTopup
|
||||
- description: UserID 下单用户ID(可选):按买家用户ID精确过滤。
|
||||
in: query
|
||||
name: user_id
|
||||
type: integer
|
||||
- description: Username 下单用户用户名关键字(可选):模糊匹配 users.username(like)。
|
||||
in: query
|
||||
name: username
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/dto.AdminOrderExportResponse'
|
||||
summary: 订单导出(租户管理)
|
||||
tags:
|
||||
- Tenant
|
||||
/t/{tenantCode}/v1/admin/users:
|
||||
get:
|
||||
consumes:
|
||||
|
||||
@@ -142,7 +142,12 @@ Content-Type: application/json
|
||||
Authorization: Bearer {{ token }}
|
||||
|
||||
### Tenant Admin - Orders list (filter by username/content_title/created_at/type)
|
||||
GET {{ host }}/t/{{ tenantCode }}/v1/admin/orders?page=1&limit=10&username=alice&content_title=Go&created_at_from=2025-01-01T00:00:00Z&created_at_to=2026-01-01T00:00:00Z&type=content_purchase
|
||||
GET {{ host }}/t/{{ tenantCode }}/v1/admin/orders?page=1&limit=10&username=alice&content_title=Go&created_at_from=2025-01-01T00:00:00Z&created_at_to=2026-01-01T00:00:00Z&type=content_purchase&asc=amount_paid&desc=paid_at
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {{ token }}
|
||||
|
||||
### Tenant Admin - Orders export (CSV text)
|
||||
GET {{ host }}/t/{{ tenantCode }}/v1/admin/orders/export?username=alice&content_title=Go&type=content_purchase&desc=paid_at
|
||||
Content-Type: application/json
|
||||
Authorization: Bearer {{ token }}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user