Merge branch 'main-merge-base-a'

# Conflicts:
#	deploy/dev/docker-compose.yml
#	deploy/dev/envoy.yaml
#	desc/api/dispute.api
#	desc/api/review.api
#	desc/api/search.api
This commit is contained in:
zetaloop
2026-04-25 05:42:42 +08:00
231 changed files with 34629 additions and 44 deletions
+29 -2
View File
@@ -3,6 +3,8 @@ package order
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"time"
@@ -55,13 +57,39 @@ func toAPIOrder(in *orderservice.Orders) types.Order {
return order
}
// validTransitions defines the allowed order state transitions per the API spec.
var validTransitions = map[string][]string{
"pending_payment": {"pending_accept"},
"pending_accept": {"in_progress", "cancelled"},
"in_progress": {"pending_close", "disputed"},
"pending_close": {"pending_review", "disputed"},
"pending_review": {"completed"},
"disputed": {"pending_review"},
}
func transitionOrderStatus(ctx context.Context, svcCtx *svc.ServiceContext, orderID int64, toStatus string, setAcceptedAt bool, setClosedAt bool, setCompletedAt bool, setCancelledAt bool) error {
current, err := svcCtx.OrderRpc.GetOrdersById(ctx, &orderservice.GetOrdersByIdReq{Id: orderID})
if err != nil {
return err
}
if current.GetOrders() == nil {
return nil
return errors.New("order not found")
}
fromStatus := current.Orders.GetStatus()
allowed, ok := validTransitions[fromStatus]
if !ok {
return fmt.Errorf("order status %q does not allow any transition", fromStatus)
}
found := false
for _, s := range allowed {
if s == toStatus {
found = true
break
}
}
if !found {
return fmt.Errorf("transition from %q to %q is not allowed", fromStatus, toStatus)
}
now := time.Now().Unix()
@@ -87,7 +115,6 @@ func transitionOrderStatus(ctx context.Context, svcCtx *svc.ServiceContext, orde
return err
}
fromStatus := current.Orders.GetStatus()
actorID, _ := contextj.UserIDFrom(ctx)
actorRole := "system"
if actorID > 0 {