测试修复15分钟bug
This commit is contained in:
@@ -33,6 +33,7 @@ type OrderDTO struct {
|
||||
HandoffStatus string `json:"handoff_status"`
|
||||
SettlementStatus string `json:"settlement_status"`
|
||||
Checkout *CheckoutDTO `json:"checkout,omitempty"`
|
||||
PaymentDeadlineAt *time.Time `json:"payment_deadline_at,omitempty"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
@@ -80,12 +81,12 @@ type PaginatedResult struct {
|
||||
}
|
||||
|
||||
type RefundStatusDTO struct {
|
||||
OrderID uint64 `json:"order_id"`
|
||||
OrderNo string `json:"order_no"`
|
||||
RefundStatus string `json:"refund_status"`
|
||||
RefundAmountCent int64 `json:"refund_amount_cent"`
|
||||
RefundedAt *time.Time `json:"refunded_at,omitempty"`
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
OrderID uint64 `json:"order_id"`
|
||||
OrderNo string `json:"order_no"`
|
||||
RefundStatus string `json:"refund_status"`
|
||||
RefundAmountCent int64 `json:"refund_amount_cent"`
|
||||
RefundedAt *time.Time `json:"refunded_at,omitempty"`
|
||||
TotalAmount float64 `json:"total_amount"`
|
||||
}
|
||||
|
||||
type HandoffRecordDTO struct {
|
||||
|
||||
@@ -697,8 +697,10 @@ func (r *Repository) ListForUser(userID uint64) ([]OrderDTO, error) {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]OrderDTO, 0, len(rows))
|
||||
paymentTimeoutMinutes := pendingPaymentTimeoutMinutes(r.db)
|
||||
for _, row := range rows {
|
||||
dto := row.toDTOForUser(userID)
|
||||
applyPaymentDeadline(&dto, row.RentalOrder, paymentTimeoutMinutes)
|
||||
if shouldAttachCheckout(row.Status) {
|
||||
dto.Checkout = r.latestCheckoutDTOForUser(row.ID, userID, row.RentalOrder)
|
||||
}
|
||||
@@ -725,8 +727,11 @@ func (r *Repository) ListAdmin(page, pageSize int) (*PaginatedResult, error) {
|
||||
}
|
||||
|
||||
items := make([]OrderDTO, 0, len(rows))
|
||||
paymentTimeoutMinutes := pendingPaymentTimeoutMinutes(r.db)
|
||||
for _, row := range rows {
|
||||
items = append(items, row.toAdminDTO())
|
||||
dto := row.toAdminDTO()
|
||||
applyPaymentDeadline(&dto, row.RentalOrder, paymentTimeoutMinutes)
|
||||
items = append(items, dto)
|
||||
}
|
||||
|
||||
return &PaginatedResult{
|
||||
@@ -743,6 +748,7 @@ func (r *Repository) FindAdmin(orderID uint64) (*OrderDTO, error) {
|
||||
return nil, err
|
||||
}
|
||||
dto := row.toAdminDTO()
|
||||
applyPaymentDeadline(&dto, row.RentalOrder, pendingPaymentTimeoutMinutes(r.db))
|
||||
dto.Checkout = r.latestCheckoutAdminDTO(orderID)
|
||||
return &dto, nil
|
||||
}
|
||||
@@ -972,6 +978,7 @@ func (r *Repository) FindForUser(userID uint64, orderID uint64) (*OrderDTO, erro
|
||||
return nil, err
|
||||
}
|
||||
dto := row.toDTOForUser(userID)
|
||||
applyPaymentDeadline(&dto, row.RentalOrder, pendingPaymentTimeoutMinutes(r.db))
|
||||
dto.Checkout = r.latestCheckoutDTOForUser(orderID, userID, row.RentalOrder)
|
||||
return &dto, nil
|
||||
}
|
||||
@@ -1164,6 +1171,14 @@ func pendingPaymentTimeoutMinutes(tx *gorm.DB) int {
|
||||
return value
|
||||
}
|
||||
|
||||
func applyPaymentDeadline(dto *OrderDTO, order model.RentalOrder, timeoutMinutes int) {
|
||||
if dto == nil || order.Status != "pending_payment" || timeoutMinutes <= 0 {
|
||||
return
|
||||
}
|
||||
deadline := order.CreatedAt.Add(time.Duration(timeoutMinutes) * time.Minute)
|
||||
dto.PaymentDeadlineAt = &deadline
|
||||
}
|
||||
|
||||
func buildCheckout(order model.RentalOrder, initiatedBy uint64, status string, content string, evidenceURLS []string, consumableAmount float64, coinConsumedM float64, otherAmount float64, explicitDeduct float64, useExplicitDeduct bool) (model.OrderCheckout, error) {
|
||||
if consumableAmount < 0 || coinConsumedM < 0 || otherAmount < 0 || explicitDeduct < 0 {
|
||||
return model.OrderCheckout{}, ErrInvalidCheckoutAmount
|
||||
|
||||
Reference in New Issue
Block a user