feat: add TenantLedger model and query generation
- Introduced TenantLedger model with fields for managing tenant transactions, including ID, TenantID, UserID, OrderID, transaction Type, Amount, and balance details. - Implemented CRUD operations for TenantLedger with methods for Create, Update, Delete, and Reload. - Generated query methods for TenantLedger to facilitate database interactions, including filtering, pagination, and aggregation functions. - Established relationships with Order model for foreign key references.
This commit is contained in:
22
backend/app/http/tenant/dto/order.go
Normal file
22
backend/app/http/tenant/dto/order.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package dto
|
||||
|
||||
import "quyun/v2/database/models"
|
||||
|
||||
// PurchaseContentForm defines the request body for purchasing a content using tenant balance.
|
||||
type PurchaseContentForm struct {
|
||||
// IdempotencyKey is used to ensure the purchase request is processed at most once.
|
||||
// 建议由客户端生成并保持稳定:同一笔购买重复请求时返回相同结果,避免重复扣款/重复下单。
|
||||
IdempotencyKey string `json:"idempotency_key,omitempty"`
|
||||
}
|
||||
|
||||
// PurchaseContentResponse returns the order and granted access after a purchase.
|
||||
type PurchaseContentResponse struct {
|
||||
// Order is the created or existing order record (may be nil for owner/free-path without order).
|
||||
Order *models.Order `json:"order,omitempty"`
|
||||
// Item is the single order item of this purchase (current implementation is 1 order -> 1 content).
|
||||
Item *models.OrderItem `json:"item,omitempty"`
|
||||
// Access is the content access record after purchase grant.
|
||||
Access *models.ContentAccess `json:"access,omitempty"`
|
||||
// AmountPaid is the final paid amount in cents (CNY 分).
|
||||
AmountPaid int64 `json:"amount_paid,omitempty"`
|
||||
}
|
||||
36
backend/app/http/tenant/dto/order_admin.go
Normal file
36
backend/app/http/tenant/dto/order_admin.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
// AdminOrderListFilter defines query filters for tenant-admin order listing.
|
||||
type AdminOrderListFilter struct {
|
||||
// Pagination controls paging parameters (page/limit).
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
// UserID filters orders by buyer user id.
|
||||
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||
// Status filters orders by order status.
|
||||
Status *consts.OrderStatus `json:"status,omitempty" query:"status"`
|
||||
}
|
||||
|
||||
// AdminOrderRefundForm defines payload for tenant-admin to refund an order.
|
||||
type AdminOrderRefundForm struct {
|
||||
// Force indicates bypassing the default refund window check (paid_at + 24h).
|
||||
// 强制退款:true 表示绕过默认退款时间窗限制(需审计)。
|
||||
Force bool `json:"force,omitempty"`
|
||||
// Reason is the human-readable refund reason used for audit.
|
||||
// 退款原因:建议必填(由业务侧校验);用于审计与追责。
|
||||
Reason string `json:"reason,omitempty"`
|
||||
// IdempotencyKey ensures refund request is processed at most once.
|
||||
// 幂等键:同一笔退款重复请求时返回一致结果,避免重复退款/重复回滚。
|
||||
IdempotencyKey string `json:"idempotency_key,omitempty"`
|
||||
}
|
||||
|
||||
// AdminOrderDetail returns a tenant-admin order detail payload.
|
||||
type AdminOrderDetail struct {
|
||||
// Order is the order with items preloaded.
|
||||
Order *models.Order `json:"order,omitempty"`
|
||||
}
|
||||
14
backend/app/http/tenant/dto/order_me.go
Normal file
14
backend/app/http/tenant/dto/order_me.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/pkg/consts"
|
||||
)
|
||||
|
||||
// MyOrderListFilter defines query filters for listing current user's orders within a tenant.
|
||||
type MyOrderListFilter struct {
|
||||
// Pagination controls paging parameters (page/limit).
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
// Status filters orders by order status.
|
||||
Status *consts.OrderStatus `json:"status,omitempty" query:"status"`
|
||||
}
|
||||
Reference in New Issue
Block a user