tenant: admin order export csv

This commit is contained in:
2025-12-19 09:11:28 +08:00
parent 549339be74
commit 86a1a0a2cc
9 changed files with 718 additions and 0 deletions

View 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"`
}

View File

@@ -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 订单详情(租户管理)

View File

@@ -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,