完善订单交接结账流程留痕
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/processlog"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const processBusinessOrder = "order"
|
||||
|
||||
func orderState(order model.RentalOrder) map[string]any {
|
||||
return map[string]any{
|
||||
"order_status": order.Status, "handoff_status": order.HandoffStatus,
|
||||
"settlement_status": order.SettlementStatus,
|
||||
"offline_settlement_status": effectiveOfflineSettlementStatus(order),
|
||||
}
|
||||
}
|
||||
|
||||
func checkoutEventPayload(checkout model.OrderCheckout) map[string]any {
|
||||
return map[string]any{
|
||||
"checkout_id": checkout.ID, "round": checkout.RoundCount, "turn": normalizeCheckoutTurn(&checkout),
|
||||
"proposed_by": checkout.ProposedBy, "rent_amount_cent": checkout.RentAmountCent,
|
||||
"owner_rent_amount_cent": checkout.OwnerRentAmountCent, "platform_fee_cent": checkout.PlatformFeeCent,
|
||||
"deposit_amount_cent": checkout.DepositAmountCent, "consumable_amount_cent": checkout.ConsumableAmountCent,
|
||||
"coin_consumed_m": checkout.CoinConsumedM, "deposit_deduct_amount_cent": checkout.DepositDeductAmountCent,
|
||||
"renter_refund_amount_cent": checkout.RenterRefundAmountCent, "owner_income_amount_cent": checkout.OwnerIncomeAmountCent,
|
||||
"shortfall_cent": checkout.ShortfallCent, "overshoot_amount_cent": checkout.OvershootAmountCent,
|
||||
}
|
||||
}
|
||||
|
||||
func appendOrderEvent(tx *gorm.DB, order model.RentalOrder, stage, action, actorType string, actorID uint64, targetType string, targetID *uint64, content, reason string, payload, before map[string]any, attachments []string) error {
|
||||
return processlog.Append(tx, processlog.Entry{
|
||||
BusinessType: processBusinessOrder, BusinessID: order.ID, Stage: stage, Action: action,
|
||||
ActorType: actorType, ActorID: actorID, TargetType: targetType, TargetID: targetID,
|
||||
Content: content, Reason: reason, Payload: payload, Attachments: attachments,
|
||||
StateBefore: before, StateAfter: orderState(order),
|
||||
})
|
||||
}
|
||||
|
||||
func (r *Repository) ProcessEventsAdmin(ctx context.Context, orderID uint64) ([]ProcessEventDTO, error) {
|
||||
var order model.RentalOrder
|
||||
if err := r.db.WithContext(ctx).First(&order, orderID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := processlog.List(r.db.WithContext(ctx), processBusinessOrder, orderID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]ProcessEventDTO, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
items = append(items, ProcessEventDTO{
|
||||
ID: row.ID, BusinessType: row.BusinessType, BusinessID: row.BusinessID, Stage: row.Stage,
|
||||
Action: row.Action, ActorType: row.ActorType, ActorID: row.ActorID, ActorName: row.ActorName,
|
||||
TargetType: row.TargetType, TargetID: row.TargetID, TargetName: row.TargetName,
|
||||
Content: row.Content, Reason: row.Reason, Payload: row.Payload,
|
||||
AttachmentURLs: decodeStringList(row.AttachmentURLs), StateBefore: row.StateBefore,
|
||||
StateAfter: row.StateAfter, CreatedAt: row.CreatedAt,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
Reference in New Issue
Block a user