tenant: extend admin order filters
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
@@ -8,27 +9,65 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
// AdminOrderListFilter defines query filters for tenant-admin order listing.
|
||||
// AdminOrderListFilter 租户管理员分页查询订单的过滤条件。
|
||||
type AdminOrderListFilter struct {
|
||||
// Pagination controls paging parameters (page/limit).
|
||||
// Pagination 分页参数:page/limit(通用)。
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
// UserID filters orders by buyer user id.
|
||||
|
||||
// UserID 下单用户ID(可选):按买家用户ID精确过滤。
|
||||
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||
// ContentID filters orders by purchased content id (via order_items join).
|
||||
|
||||
// Username 下单用户用户名关键字(可选):模糊匹配 users.username(like)。
|
||||
Username *string `json:"username,omitempty" query:"username"`
|
||||
|
||||
// ContentID 内容ID(可选):通过 order_items 关联过滤。
|
||||
ContentID *int64 `json:"content_id,omitempty" query:"content_id"`
|
||||
// Status filters orders by order status.
|
||||
|
||||
// ContentTitle 内容标题关键字(可选):通过 order_items + contents 关联,模糊匹配 contents.title(like)。
|
||||
ContentTitle *string `json:"content_title,omitempty" query:"content_title"`
|
||||
|
||||
// Type 订单类型(可选):content_purchase/topup 等。
|
||||
Type *consts.OrderType `json:"type,omitempty" query:"type"`
|
||||
|
||||
// Status 订单状态(可选):created/paid/refunding/refunded/canceled/failed。
|
||||
Status *consts.OrderStatus `json:"status,omitempty" query:"status"`
|
||||
// PaidAtFrom filters orders by paid_at >= this time.
|
||||
|
||||
// CreatedAtFrom 创建时间起(可选):created_at >= 该时间(用于按创建时间筛选)。
|
||||
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
|
||||
|
||||
// CreatedAtTo 创建时间止(可选):created_at <= 该时间(用于按创建时间筛选)。
|
||||
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
|
||||
|
||||
// PaidAtFrom 支付时间起(可选):paid_at >= 该时间(用于按支付时间筛选)。
|
||||
PaidAtFrom *time.Time `json:"paid_at_from,omitempty" query:"paid_at_from"`
|
||||
// PaidAtTo filters orders by paid_at <= this time.
|
||||
|
||||
// PaidAtTo 支付时间止(可选):paid_at <= 该时间(用于按支付时间筛选)。
|
||||
PaidAtTo *time.Time `json:"paid_at_to,omitempty" query:"paid_at_to"`
|
||||
// AmountPaidMin filters orders by amount_paid >= this amount (cents).
|
||||
|
||||
// AmountPaidMin 实付金额下限(可选):amount_paid >= 该值(单位分)。
|
||||
AmountPaidMin *int64 `json:"amount_paid_min,omitempty" query:"amount_paid_min"`
|
||||
// AmountPaidMax filters orders by amount_paid <= this amount (cents).
|
||||
|
||||
// AmountPaidMax 实付金额上限(可选):amount_paid <= 该值(单位分)。
|
||||
AmountPaidMax *int64 `json:"amount_paid_max,omitempty" query:"amount_paid_max"`
|
||||
}
|
||||
|
||||
// AdminOrderRefundForm defines payload for tenant-admin to refund an order.
|
||||
// UsernameTrimmed 对 username 做统一处理,避免空白与大小写差异导致查询不一致。
|
||||
func (f *AdminOrderListFilter) UsernameTrimmed() string {
|
||||
if f == nil || f.Username == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(*f.Username)
|
||||
}
|
||||
|
||||
// ContentTitleTrimmed 对 content_title 做统一处理,避免空白与大小写差异导致查询不一致。
|
||||
func (f *AdminOrderListFilter) ContentTitleTrimmed() string {
|
||||
if f == nil || f.ContentTitle == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(*f.ContentTitle)
|
||||
}
|
||||
|
||||
// AdminOrderRefundForm 租户管理员退款的请求参数。
|
||||
type AdminOrderRefundForm struct {
|
||||
// Force indicates bypassing the default refund window check (paid_at + 24h).
|
||||
// 强制退款:true 表示绕过默认退款时间窗限制(需审计)。
|
||||
@@ -41,7 +80,7 @@ type AdminOrderRefundForm struct {
|
||||
IdempotencyKey string `json:"idempotency_key,omitempty"`
|
||||
}
|
||||
|
||||
// AdminOrderDetail returns a tenant-admin order detail payload.
|
||||
// AdminOrderDetail 租户管理员订单详情返回结构。
|
||||
type AdminOrderDetail struct {
|
||||
// Order is the order with items preloaded.
|
||||
Order *models.Order `json:"order,omitempty"`
|
||||
|
||||
@@ -41,10 +41,23 @@ func (*orderAdmin) adminOrderList(
|
||||
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,
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"query_user_id": filter.UserID,
|
||||
"username": filter.UsernameTrimmed(),
|
||||
"content_id": filter.ContentID,
|
||||
"content_title": filter.ContentTitleTrimmed(),
|
||||
"type": filter.Type,
|
||||
"status": filter.Status,
|
||||
"created_at_from": filter.CreatedAtFrom,
|
||||
"created_at_to": filter.CreatedAtTo,
|
||||
"paid_at_from": filter.PaidAtFrom,
|
||||
"paid_at_to": filter.PaidAtTo,
|
||||
}).Info("tenant.admin.orders.list")
|
||||
|
||||
return services.Order.AdminOrderPage(ctx, tenant.ID, filter)
|
||||
|
||||
Reference in New Issue
Block a user