From fc75d7b8108ff3781284bd04815170bb21168507 Mon Sep 17 00:00:00 2001 From: kate522 Date: Wed, 7 Oct 2026 08:28:27 +0000 Subject: [PATCH] =?UTF-8?q?chore(admin):=20=E5=88=A0=E9=99=A4=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E9=A1=B5=E4=B8=93=E7=94=A8=E7=9A=84=20get=5Fadmin=5Fo?= =?UTF-8?q?rder=5Fstats=EF=BC=88=E5=B7=B2=E6=97=A0=E8=B0=83=E7=94=A8?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Payment/OrderRepositoryCore.php | 52 +---------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/src/Payment/OrderRepositoryCore.php b/src/Payment/OrderRepositoryCore.php index 852dedae..3fd7e2f3 100644 --- a/src/Payment/OrderRepositoryCore.php +++ b/src/Payment/OrderRepositoryCore.php @@ -709,62 +709,12 @@ trait OrderRepositoryCore { ]; } - /** @return array */ - public function get_admin_order_stats(array $args = []): array { - global $wpdb; - $this->expire_pending_orders(); - $where = []; - $params = []; - foreach (['date_from' => '>=', 'date_to' => '<='] as $key => $operator) { - $date = sanitize_text_field((string) ($args[$key] ?? '')); - if ($date !== '' && preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) { - $where[] = 'created_at ' . $operator . ' %s'; - $params[] = $operator === '>=' ? $date . ' 00:00:00' : $date . ' 23:59:59'; - } - } - $where_sql = $where ? 'WHERE ' . implode(' AND ', $where) : ''; - $sql = "SELECT COUNT(*) AS total, - SUM(status = 'pending') AS pending, - SUM(status IN ('paid','refunding')) AS paid, - SUM(status = 'refunded') AS refunded, - SUM(status = 'closed') AS closed, - SUM(CASE WHEN status IN ('paid','refunding') AND currency <> 'points' THEN amount ELSE 0 END) AS revenue - FROM {$this->table()} {$where_sql}"; - $row = $params ? $wpdb->get_row($wpdb->prepare($sql, $params), ARRAY_A) : $wpdb->get_row($sql, ARRAY_A); - $type_sql = "SELECT product_type, note, COUNT(*) AS total FROM {$this->table()} {$where_sql} GROUP BY product_type, note"; - $type_rows = $params ? $wpdb->get_results($wpdb->prepare($type_sql, $params), ARRAY_A) : $wpdb->get_results($type_sql, ARRAY_A); - $by_type = array_fill_keys(array_keys(\AKSRT\Core\DomainModel::order_product_type_labels()), 0); - foreach ((array) $type_rows as $type_row) { - $meta = json_decode((string) ($type_row['note'] ?? ''), true); - $type = \AKSRT\Core\DomainModel::resolve_order_product_type((string) ($type_row['product_type'] ?? ''), is_array($meta) ? $meta : []); - if (isset($by_type[$type])) { - $by_type[$type] += (int) ($type_row['total'] ?? 0); - } - } - return [ - 'total' => (int) ($row['total'] ?? 0), - 'pending' => (int) ($row['pending'] ?? 0), - 'paid' => (int) ($row['paid'] ?? 0), - 'refunded' => (int) ($row['refunded'] ?? 0), - 'closed' => (int) ($row['closed'] ?? 0), - 'revenue' => $this->cash_decimal((string) ($row['revenue'] ?? '0')), - 'by_type' => $by_type, - 'after_sale_pending' => class_exists(AfterSaleService::class) ? AfterSaleService::get_instance()->count([ - 'status' => AfterSaleService::STATUS_PENDING, - 'date_from' => $args['date_from'] ?? '', - 'date_to' => $args['date_to'] ?? '', - ]) : 0, - ]; - } - - public function dispatch_managed_status_events(): void { + public function dispatch_managed_status_events(): void { $events = $this->status_after_commit_events; $this->status_after_commit_events = []; $this->dispatch_status_events($events); } - - public function has_paid_access(int $user_id, string $product_type, int $product_id): bool { if ($user_id <= 0 || $product_id <= 0) { return false;