fix(order): 修复超时与异常过渡态下的状态机流转及权限断层
This commit is contained in:
@@ -112,7 +112,15 @@ func (r *Repository) ConfirmCheckout(ctx context.Context, userID uint64, orderID
|
||||
if order.OwnerID != userID {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
if order.Status != orderStatusPendingCheckoutConfirm || order.HandoffStatus != handoffStatusPendingOwnerCheckout {
|
||||
isOwnerPending := order.Status == orderStatusPendingCheckoutConfirm ||
|
||||
(order.Status == orderStatusAbnormal &&
|
||||
(order.HandoffStatus == handoffStatusOwnerCheckoutConfirmTimeout ||
|
||||
order.HandoffStatus == handoffStatusOwnerReturnConfirmTimeout ||
|
||||
order.HandoffStatus == handoffStatusPendingOwnerCheckout))
|
||||
if !isOwnerPending ||
|
||||
(order.HandoffStatus != handoffStatusPendingOwnerCheckout &&
|
||||
order.HandoffStatus != handoffStatusOwnerCheckoutConfirmTimeout &&
|
||||
order.HandoffStatus != handoffStatusOwnerReturnConfirmTimeout) {
|
||||
return ErrCheckoutCannotConfirm
|
||||
}
|
||||
before := orderState(order)
|
||||
@@ -162,7 +170,13 @@ func (r *Repository) CounterCheckout(ctx context.Context, userID uint64, orderID
|
||||
if !isOwner && !isRenter {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
if order.Status != orderStatusPendingCheckoutConfirm && order.Status != orderStatusPendingCheckoutAccept {
|
||||
isOwnerPending := order.Status == orderStatusPendingCheckoutConfirm ||
|
||||
(order.Status == orderStatusAbnormal &&
|
||||
(order.HandoffStatus == handoffStatusOwnerCheckoutConfirmTimeout ||
|
||||
order.HandoffStatus == handoffStatusOwnerReturnConfirmTimeout ||
|
||||
order.HandoffStatus == handoffStatusPendingOwnerCheckout))
|
||||
isRenterPending := order.Status == orderStatusPendingCheckoutAccept
|
||||
if !isOwnerPending && !isRenterPending {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
before := orderState(order)
|
||||
@@ -171,10 +185,10 @@ func (r *Repository) CounterCheckout(ctx context.Context, userID uint64, orderID
|
||||
return err
|
||||
}
|
||||
turn := normalizeCheckoutTurn(checkout)
|
||||
if isOwner && (turn != checkoutTurnOwner || order.Status != orderStatusPendingCheckoutConfirm) {
|
||||
if isOwner && (turn != checkoutTurnOwner || !isOwnerPending) {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
if isRenter && (turn != checkoutTurnRenter || order.Status != orderStatusPendingCheckoutAccept) {
|
||||
if isRenter && (turn != checkoutTurnRenter || !isRenterPending) {
|
||||
return ErrCheckoutCannotCounter
|
||||
}
|
||||
round := checkout.RoundCount
|
||||
|
||||
Reference in New Issue
Block a user