优化订单结算金额展示和钱包流水号

This commit is contained in:
yml2213
2026-06-05 00:37:50 +08:00
parent 064abb6621
commit 498e3d7bde
7 changed files with 148 additions and 15 deletions
+15 -2
View File
@@ -698,7 +698,11 @@ func (r *Repository) ListForUser(userID uint64) ([]OrderDTO, error) {
}
items := make([]OrderDTO, 0, len(rows))
for _, row := range rows {
items = append(items, row.toDTOForUser(userID))
dto := row.toDTOForUser(userID)
if shouldAttachCheckout(row.Status) {
dto.Checkout = r.latestCheckoutDTOForUser(row.ID, userID, row.RentalOrder)
}
items = append(items, dto)
}
return items, nil
}
@@ -1312,6 +1316,15 @@ func (r *Repository) latestCheckoutAdminDTO(orderID uint64) *CheckoutDTO {
return &dto
}
func shouldAttachCheckout(status string) bool {
switch status {
case "pending_checkout_confirm", "pending_checkout_accept", "checkout_disputing", "completed":
return true
default:
return false
}
}
func (r *Repository) latestCheckoutDTOForUser(orderID uint64, userID uint64, order model.RentalOrder) *CheckoutDTO {
var checkout model.OrderCheckout
if err := r.db.Where("order_id = ?", orderID).Order("id DESC").First(&checkout).Error; err != nil {
@@ -1598,7 +1611,7 @@ func newOrderNo() (string, error) {
// 将2字节转为0-999的数字
randomNum := (int(buf[0])<<8 | int(buf[1])) % 1000
return "RO" + timeStr + strconv.Itoa(1000+randomNum)[1:], nil
return "RO" + timeStr + strconv.Itoa(1000 + randomNum)[1:], nil
}
func appendAuditLog(tx *gorm.DB, actorID uint64, action string, bizType string, bizID uint64, meta AuditMeta, detail map[string]any) error {