feat(ECR-009): Ops-D order filters, plan display prices, refund status

LOOP-RUN-002 sample: admin order multi-filter, membership display
price catalog, read-only refund_status. No real payment or RBAC.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
jackyu66git
2026-08-07 02:45:32 +08:00
co-authored by Cursor
parent 7ab9add5dd
commit ca3b13554c
37 changed files with 2169 additions and 25 deletions
+49 -4
View File
@@ -168,7 +168,11 @@ func (s *Service) GetUser(ctx context.Context, userID uuid.UUID) (*UserDetail, e
if err != nil {
return nil, err
}
orders, err := s.Repo.ListOrders(ctx, &userID, 10, 0)
orders, err := s.Repo.ListOrders(ctx, repository.OrderListFilter{
UserID: &userID,
Limit: 10,
Offset: 0,
})
if err != nil {
return nil, err
}
@@ -231,9 +235,23 @@ func (s *Service) GrantAskQuota(ctx context.Context, adminID, userID uuid.UUID,
return s.Repo.GrantAskQuotaWithAudit(ctx, adminID, userID, delta, meta)
}
// ListOrders lists commerce orders.
func (s *Service) ListOrders(ctx context.Context, limit, offset int) ([]repository.OrderListItem, error) {
return s.Repo.ListOrders(ctx, nil, limit, offset)
// ListOrders lists commerce orders with Ops-D filters.
func (s *Service) ListOrders(ctx context.Context, f repository.OrderListFilter) ([]repository.OrderListItem, error) {
return s.Repo.ListOrders(ctx, f)
}
// ListPlanPrices returns membership catalog display prices.
func (s *Service) ListPlanPrices(ctx context.Context) ([]repository.PlanPrice, error) {
return s.Repo.ListPlanPrices(ctx)
}
// UpsertPlanPrices updates display prices (not historical order amounts).
func (s *Service) UpsertPlanPrices(ctx context.Context, adminID uuid.UUID, items []repository.PlanPrice) error {
if len(items) == 0 {
return ErrInvalidPlan
}
meta, _ := json.Marshal(map[string]any{"count": len(items)})
return s.Repo.UpsertPlanPricesWithAudit(ctx, adminID, items, meta)
}
// ListAuditLogs lists audit entries.
@@ -261,3 +279,30 @@ func newToken() (string, error) {
}
return "adm_" + hex.EncodeToString(b), nil
}
// OrderFilterFromQuery builds repository filter from HTTP query strings.
func OrderFilterFromQuery(userID, status, kind, from, to string, limit, offset int) repository.OrderListFilter {
f := repository.OrderListFilter{
Status: status,
Kind: kind,
Limit: limit,
Offset: offset,
}
if userID != "" {
if id, err := uuid.Parse(userID); err == nil {
f.UserID = &id
}
}
if from != "" {
if t, err := time.Parse("2006-01-02", from); err == nil {
f.From = &t
}
}
if to != "" {
if t, err := time.Parse("2006-01-02", to); err == nil {
end := t.Add(24 * time.Hour)
f.To = &end
}
}
return f
}