chore(admin): 删除统计页专用的 get_admin_order_stats(已无调用)

This commit is contained in:
2026-10-07 08:28:27 +00:00
parent b3012b3133
commit fc75d7b810
-50
View File
@@ -709,62 +709,12 @@ trait OrderRepositoryCore {
];
}
/** @return array<string,mixed> */
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 {
$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;