feat: add super order detail snapshot
This commit is contained in:
@@ -166,10 +166,14 @@ type SuperOrderItem struct {
|
|||||||
AmountPaid int64 `json:"amount_paid"`
|
AmountPaid int64 `json:"amount_paid"`
|
||||||
Tenant *OrderTenantLite `json:"tenant"`
|
Tenant *OrderTenantLite `json:"tenant"`
|
||||||
Buyer *OrderBuyerLite `json:"buyer"`
|
Buyer *OrderBuyerLite `json:"buyer"`
|
||||||
PaidAt string `json:"paid_at"`
|
// Snapshot 订单快照,包含下单时的关键参数与定价信息,便于审计回溯。
|
||||||
RefundedAt string `json:"refunded_at"`
|
Snapshot any `json:"snapshot"`
|
||||||
CreatedAt string `json:"created_at"`
|
// Items 订单明细行,用于展示具体内容与金额拆分。
|
||||||
UpdatedAt string `json:"updated_at"`
|
Items []SuperOrderItemLine `json:"items"`
|
||||||
|
PaidAt string `json:"paid_at"`
|
||||||
|
RefundedAt string `json:"refunded_at"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
UpdatedAt string `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OrderTenantLite struct {
|
type OrderTenantLite struct {
|
||||||
@@ -183,6 +187,18 @@ type OrderBuyerLite struct {
|
|||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SuperOrderItemLine 表示订单明细行。
|
||||||
|
type SuperOrderItemLine struct {
|
||||||
|
// ID 订单明细ID。
|
||||||
|
ID int64 `json:"id"`
|
||||||
|
// ContentID 购买的内容ID。
|
||||||
|
ContentID int64 `json:"content_id"`
|
||||||
|
// AmountPaid 该明细实付金额(分)。
|
||||||
|
AmountPaid int64 `json:"amount_paid"`
|
||||||
|
// Snapshot 明细快照,用于展示内容标题等历史信息。
|
||||||
|
Snapshot any `json:"snapshot"`
|
||||||
|
}
|
||||||
|
|
||||||
type OrderStatisticsResponse struct {
|
type OrderStatisticsResponse struct {
|
||||||
TotalCount int64 `json:"total_count"`
|
TotalCount int64 `json:"total_count"`
|
||||||
TotalAmountPaidSum int64 `json:"total_amount_paid_sum"`
|
TotalAmountPaidSum int64 `json:"total_amount_paid_sum"`
|
||||||
|
|||||||
@@ -356,7 +356,20 @@ func (s *super) GetOrder(ctx context.Context, id int64) (*super_dto.SuperOrderDe
|
|||||||
buyer = u
|
buyer = u
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itemTbl, itemQ := models.OrderItemQuery.QueryContext(ctx)
|
||||||
|
orderItems, err := itemQ.Where(itemTbl.OrderID.Eq(o.ID)).Find()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
items := make([]super_dto.SuperOrderItemLine, 0, len(orderItems))
|
||||||
|
for _, it := range orderItems {
|
||||||
|
items = append(items, s.toSuperOrderItemLine(it))
|
||||||
|
}
|
||||||
|
|
||||||
item := s.toSuperOrderItem(o, tenant, buyer)
|
item := s.toSuperOrderItem(o, tenant, buyer)
|
||||||
|
item.Snapshot = o.Snapshot.Data()
|
||||||
|
item.Items = items
|
||||||
return &super_dto.SuperOrderDetail{
|
return &super_dto.SuperOrderDetail{
|
||||||
Order: &item,
|
Order: &item,
|
||||||
Tenant: item.Tenant,
|
Tenant: item.Tenant,
|
||||||
@@ -590,6 +603,15 @@ func (s *super) toSuperOrderItem(o *models.Order, tenant *models.Tenant, buyer *
|
|||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *super) toSuperOrderItemLine(item *models.OrderItem) super_dto.SuperOrderItemLine {
|
||||||
|
return super_dto.SuperOrderItemLine{
|
||||||
|
ID: item.ID,
|
||||||
|
ContentID: item.ContentID,
|
||||||
|
AmountPaid: item.AmountPaid,
|
||||||
|
Snapshot: item.Snapshot.Data(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (s *super) contentPriceMap(ctx context.Context, list []*models.Content) (map[int64]*models.ContentPrice, error) {
|
func (s *super) contentPriceMap(ctx context.Context, list []*models.Content) (map[int64]*models.ContentPrice, error) {
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
return map[int64]*models.ContentPrice{}, nil
|
return map[int64]*models.ContentPrice{}, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user