完善订单交接结账流程留痕
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/adminnotification"
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
"hfb_sys/backend/internal/processlog"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
@@ -81,6 +82,7 @@ func (r *Repository) AdminPlatformHandoff(ctx context.Context, adminID uint64, o
|
||||
if !canAdminPlatformHandoff(order) {
|
||||
return ErrOrderCannotHandoff
|
||||
}
|
||||
before := orderState(order)
|
||||
beforeHandoffStatus := order.HandoffStatus
|
||||
if order.ManagedAdminID == nil {
|
||||
order.ManagedAdminID = &adminID
|
||||
@@ -98,6 +100,9 @@ func (r *Repository) AdminPlatformHandoff(ctx context.Context, adminID uint64, o
|
||||
now := time.Now()
|
||||
order.HandoffStatus = handoffStatusPendingRenterConfirm
|
||||
order.HandoffStartedAt = &now
|
||||
if err := appendOrderEvent(tx, order, "handoff", "platform_handoff_submitted", processlog.ActorAdmin, adminID, processlog.ActorUser, &order.RenterID, req.Content, req.Reason, nil, before, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
orderID := order.ID
|
||||
content := "客服已提交交接说明,请查看交接记录,确认账号可正常登录后点击确认收号。"
|
||||
if beforeHandoffStatus == handoffStatusOwnerTimeout {
|
||||
@@ -146,6 +151,7 @@ func (r *Repository) AdminPlatformCheckoutConfirm(ctx context.Context, adminID u
|
||||
if !canAdminPlatformCheckoutConfirm(order) {
|
||||
return ErrCheckoutCannotConfirm
|
||||
}
|
||||
before := orderState(order)
|
||||
checkout, err := lockOpenCheckout(tx, order.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -175,6 +181,9 @@ func (r *Repository) AdminPlatformCheckoutConfirm(ctx context.Context, adminID u
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := appendOrderEvent(tx, order, "checkout", "platform_checkout_confirmed", processlog.ActorAdmin, adminID, processlog.ActorUser, &order.RenterID, "客服确认当前结账方案,订单完成。", req.Reason, checkoutEventPayload(*checkout), before, decodeStringList(checkout.EvidenceURLS)); err != nil {
|
||||
return err
|
||||
}
|
||||
return appendAuditLog(tx, adminID, "order.platform_checkout_confirm", "order", order.ID, meta, map[string]any{
|
||||
"order_id": order.ID,
|
||||
"order_no": order.OrderNo,
|
||||
@@ -207,6 +216,7 @@ func (r *Repository) AdminPlatformCheckoutCounter(ctx context.Context, adminID u
|
||||
if !canAdminPlatformCheckoutConfirm(order) {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
before := orderState(order)
|
||||
if order.ManagedAdminID == nil {
|
||||
order.ManagedAdminID = &adminID
|
||||
}
|
||||
@@ -259,6 +269,9 @@ func (r *Repository) AdminPlatformCheckoutCounter(ctx context.Context, adminID u
|
||||
if err := tx.Create(&record).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := appendOrderEvent(tx, order, "checkout", "platform_checkout_countered", processlog.ActorAdmin, adminID, processlog.ActorUser, &order.RenterID, "", req.Reason, checkoutEventPayload(*checkout), before, req.EvidenceURLS); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := appendAuditLog(tx, adminID, "order.platform_checkout_counter", "order", order.ID, meta, map[string]any{
|
||||
"order_id": order.ID,
|
||||
"order_no": order.OrderNo,
|
||||
@@ -308,6 +321,7 @@ func (r *Repository) AdminPlatformCheckoutDispute(ctx context.Context, adminID u
|
||||
if !canAdminPlatformCheckoutConfirm(order) {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
before := orderState(order)
|
||||
if order.ManagedAdminID == nil {
|
||||
order.ManagedAdminID = &adminID
|
||||
}
|
||||
@@ -369,6 +383,9 @@ func (r *Repository) AdminPlatformCheckoutDispute(ctx context.Context, adminID u
|
||||
if err := tx.Create(&record).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := appendOrderEvent(tx, order, "dispute", "platform_checkout_dispute_opened", processlog.ActorAdmin, adminID, processlog.ActorUser, &order.RenterID, "客服发起结账争议。", req.Reason, map[string]any{"checkout_id": checkout.ID, "dispute_id": row.ID}, before, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
disputeID := row.ID
|
||||
orderID := order.ID
|
||||
if err := notification.Append(tx, notification.Entry{
|
||||
@@ -415,6 +432,7 @@ func (r *Repository) AdminMarkOfflineSettlement(ctx context.Context, adminID uin
|
||||
if !canAdminMarkOfflineSettlement(order) {
|
||||
return ErrOfflineSettlementCannotMark
|
||||
}
|
||||
before := orderState(order)
|
||||
beforeStatus := order.OfflineSettlementStatus
|
||||
now := time.Now()
|
||||
order.OfflineSettlementStatus = offlineSettlementStatusSettled
|
||||
@@ -422,6 +440,9 @@ func (r *Repository) AdminMarkOfflineSettlement(ctx context.Context, adminID uin
|
||||
order.OfflineSettledBy = &adminID
|
||||
order.OfflineSettledAt = &now
|
||||
order.OwnerSettledAt = &now
|
||||
if err := appendOrderEvent(tx, order, "settlement", "offline_settlement_confirmed", processlog.ActorAdmin, adminID, processlog.ActorUser, &order.OwnerID, "确认已完成线下结算。", req.Remark, map[string]any{"offline_settlement_amount_cent": order.OfflineSettlementAmountCent}, before, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := appendAuditLog(tx, adminID, "order.offline_settlement", "order", order.ID, meta, map[string]any{
|
||||
"order_id": order.ID,
|
||||
"order_no": order.OrderNo,
|
||||
|
||||
Reference in New Issue
Block a user