*/ private function pages(): array { return [ 'overview' => [ 'slug' => self::MENU_SLUG, 'title' => __('概览', 'aksrt'), 'callback' => [$this, 'render_overview_page'], ], 'orders' => [ 'slug' => 'aksrt_orders', 'title' => __('订单', 'aksrt'), 'callback' => [$this, 'render_orders_page'], ], 'shipping' => [ 'slug' => 'aksrt_shipping', 'title' => __('发货及物流', 'aksrt'), 'callback' => [$this, 'render_shipping_page'], ], 'after_sale' => [ 'slug' => 'aksrt_after_sale', 'title' => __('售后管理', 'aksrt'), 'callback' => [$this, 'render_after_sale_page'], ], 'coupons' => [ 'slug' => 'aksrt_coupons', 'title' => __('优惠码', 'aksrt'), 'callback' => [$this, 'render_coupons_page'], ], 'charge_cards' => [ 'slug' => 'aksrt_charge_cards', 'title' => __('卡密管理', 'aksrt'), 'callback' => [$this, 'render_charge_cards_page'], ], 'income' => [ 'slug' => 'aksrt_income', 'title' => __('创作分成', 'aksrt'), 'callback' => [$this, 'render_income_page'], ], 'rebate' => [ 'slug' => 'aksrt_rebate', 'title' => __('推广返佣', 'aksrt'), 'callback' => [$this, 'render_rebate_page'], ], 'withdraw' => [ 'slug' => 'aksrt_withdraw', 'title' => __('提现审核', 'aksrt'), 'callback' => [$this, 'render_withdrawals_page'], ], ]; } public function register_menus(): void { if (!current_user_can(self::CAPABILITY)) { return; } add_menu_page( __('支付中心', 'aksrt'), __('支付中心', 'aksrt'), self::CAPABILITY, self::MENU_SLUG, [$this, 'render_overview_page'], 'dashicons-cart', 36 ); foreach ($this->pages() as $key => $page) { $parent = self::MENU_SLUG; // First item reuses top-level slug (WP pattern). add_submenu_page( $parent, $page['title'], $page['title'], self::CAPABILITY, $page['slug'], $page['callback'] ); } } public function pending_notices(): void { if (!current_user_can(self::CAPABILITY)) { return; } $page = isset($_GET['page']) ? sanitize_key((string) wp_unslash($_GET['page'])) : ''; if ($page !== 'aksrt_withdraw' && class_exists('AKSRT_Withdrawal')) { $pending = (int) AKSRT_Withdrawal::get_instance()->get_count(['status' => AKSRT_Withdrawal::STATUS_PENDING]); if ($pending > 0) { $url = admin_url('admin.php?page=aksrt_withdraw&status=pending'); echo '
'; echo '

' . esc_html__('提现申请待处理', 'aksrt') . '

'; echo '

' . esc_html(sprintf( /* translators: %d: pending withdrawal count */ __('您有 %d 个提现申请待处理', 'aksrt'), $pending )) . '

'; echo '

' . esc_html__('立即处理', 'aksrt') . '

'; echo '
'; } } if ($page !== 'aksrt_after_sale' && class_exists('AKSRT_After_Sale')) { $as_stats = AKSRT_After_Sale::get_instance()->get_stats(); $pending_as = (int) ($as_stats['pending'] ?? 0); if ($pending_as > 0) { $url = admin_url('admin.php?page=aksrt_after_sale&status=pending'); echo '
'; echo '

' . esc_html__('售后工单待处理', 'aksrt') . '

'; echo '

' . esc_html(sprintf( /* translators: %d: pending after-sale count */ __('您有 %d 个售后工单待处理', 'aksrt'), $pending_as )) . '

'; echo '

' . esc_html__('去处理', 'aksrt') . '

'; echo '
'; } } } /* ------------------------------------------------------------------ * Page shells * ----------------------------------------------------------------*/ private function ensure_cap(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('您没有权限访问此页面。', 'aksrt')); } } private function render_header(string $title): void { echo '
'; echo '

' . esc_html($title) . '

'; $this->render_flash(); } private function render_footer(): void { echo '
'; } private function render_flash(): void { if (empty($_GET['aksrt_pay_msg'])) { return; } $code = sanitize_key((string) wp_unslash($_GET['aksrt_pay_msg'])); $map = [ 'order_updated' => __('订单状态已更新。', 'aksrt'), 'order_failed' => __('订单状态更新失败。', 'aksrt'), 'order_note_updated' => __('订单备注已保存。', 'aksrt'), 'order_note_failed' => __('订单备注保存失败。', 'aksrt'), 'after_sale_action_ok' => __('售后操作已完成。', 'aksrt'), 'after_sale_action_failed' => __('售后操作失败。', 'aksrt'), 'withdraw_updated' => __('提现状态已更新。', 'aksrt'), 'withdraw_failed' => __('提现状态更新失败。', 'aksrt'), 'card_disabled' => __('充值卡已禁用。', 'aksrt'), 'card_failed' => __('充值卡禁用失败。', 'aksrt'), 'card_batch_ok' => __('卡密批量生成完成。', 'aksrt'), 'card_batch_failed' => __('卡密批量生成失败。', 'aksrt'), 'shipping_updated' => __('物流状态已更新。', 'aksrt'), 'shipping_failed' => __('物流状态更新失败。', 'aksrt'), 'shipping_created' => __('发货记录已创建。', 'aksrt'), 'shipping_create_failed' => __('发货记录创建失败。', 'aksrt'), 'express_ok' => __('物流轨迹已更新。', 'aksrt'), 'express_failed' => __('物流轨迹查询失败。', 'aksrt'), 'after_sale_updated' => __('售后状态已更新。', 'aksrt'), 'after_sale_failed' => __('售后状态更新失败。', 'aksrt'), 'after_sale_created' => __('售后工单已创建。', 'aksrt'), 'after_sale_create_failed' => __('售后工单创建失败。', 'aksrt'), 'coupon_created' => __('优惠码已创建。', 'aksrt'), 'coupon_create_failed'=> __('优惠码创建失败(可能重复)。', 'aksrt'), 'coupon_batch_ok' => __('优惠码批量生成完成。', 'aksrt'), 'coupon_batch_failed' => __('优惠码批量生成失败。', 'aksrt'), 'coupon_disabled' => __('优惠码已禁用。', 'aksrt'), 'coupon_enabled' => __('优惠码已启用。', 'aksrt'), 'coupon_failed' => __('优惠码操作失败。', 'aksrt'), 'income_settled' => __('分成已结算。', 'aksrt'), 'income_failed' => __('分成结算失败。', 'aksrt'), 'rebate_settled' => __('返佣已结算。', 'aksrt'), 'rebate_cancelled' => __('返佣已取消。', 'aksrt'), 'rebate_failed' => __('返佣操作失败。', 'aksrt'), ]; if (!isset($map[$code])) { return; } $class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success'; echo '

' . esc_html($map[$code]) . '

'; } private function page_url(string $slug, array $args = []): string { return add_query_arg(array_merge(['page' => $slug], $args), admin_url('admin.php')); } public function render_overview_page(): void { $this->ensure_cap(); $this->render_header(__('支付中心', 'aksrt')); $order_stats = class_exists('AKSRT_Order_Repository') ? AKSRT_Order_Repository::get_instance()->get_stats() : []; $withdraw_stats = class_exists('AKSRT_Withdrawal') ? AKSRT_Withdrawal::get_instance()->get_stats() : []; $card_stats = class_exists('AKSRT_Charge_Card') ? AKSRT_Charge_Card::get_instance()->get_stats() : []; echo '

' . esc_html__('运营数据入口(对齐 zibll 商城中心)。配置项仍在 AKSRT 主题设置 SPA。', 'aksrt') . '

'; echo '
'; $pending_ship = 0; if (class_exists('AKSRT_Order_Repository')) { $pending_ship = (int) (AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders(['limit' => 1])['total'] ?? 0); } $this->stat_card(__('订单总数', 'aksrt'), (string) (int) ($order_stats['total'] ?? 0), $this->page_url('aksrt_orders')); $this->stat_card(__('待支付', 'aksrt'), (string) (int) ($order_stats['pending'] ?? 0), $this->page_url('aksrt_orders', ['status' => 'pending'])); $this->stat_card(__('已支付', 'aksrt'), (string) (int) ($order_stats['paid'] ?? 0), $this->page_url('aksrt_orders', ['status' => 'paid'])); $this->stat_card(__('待发货', 'aksrt'), (string) $pending_ship, $this->page_url('aksrt_shipping', ['view' => 'pending'])); $this->stat_card(__('营收', 'aksrt'), number_format((float) ($order_stats['revenue'] ?? 0), 2), $this->page_url('aksrt_orders')); $this->stat_card(__('待审提现', 'aksrt'), (string) (int) ($withdraw_stats['pending'] ?? 0), $this->page_url('aksrt_withdraw', ['status' => 'pending'])); $this->stat_card(__('可用卡密', 'aksrt'), (string) (int) ($card_stats['active'] ?? 0), $this->page_url('aksrt_charge_cards', ['status' => 'active'])); echo '
'; echo '

' . esc_html__('快捷入口', 'aksrt') . '

'; $spa = admin_url('admin.php?page=aksrt-settings#/payment/gateway'); echo '

' . esc_html__('打开支付配置(SPA)', 'aksrt') . '

'; $this->render_footer(); } private function stat_card(string $label, string $value, string $url): void { echo ''; echo '
' . esc_html($label) . '
'; echo '
' . esc_html($value) . '
'; echo '
'; } /* ------------------------------------------------------------------ * Orders * ----------------------------------------------------------------*/ public function render_orders_page(): void { $this->ensure_cap(); $this->render_header(__('订单', 'aksrt')); if (!class_exists('AKSRT_Order_Repository')) { echo '

' . esc_html__('订单服务不可用。', 'aksrt') . '

'; $this->render_footer(); return; } $detail_order = isset($_GET['order']) ? sanitize_text_field((string) wp_unslash($_GET['order'])) : ''; if ($detail_order !== '') { $this->render_order_detail_page($detail_order); $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $repo = AKSRT_Order_Repository::get_instance(); $args = [ 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]; if ($status !== '' && $status !== 'all') { $args['status'] = $status; } $items = $repo->get_orders_admin($args, $search); $total = $repo->get_orders_count($args, $search); $pages = max(1, (int) ceil($total / $per_page)); $labels = class_exists('AKSRT_Domain_Model') ? AKSRT_Domain_Model::order_status_labels() : []; echo '
'; echo ''; echo ' '; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $order_number = (string) ($row['order_number'] ?? ''); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $status_key = (string) ($row['status'] ?? ''); $status_label = $labels[$status_key] ?? $status_key; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html__('订单号', 'aksrt') . '' . esc_html__('用户', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('金额', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无订单', 'aksrt') . '
' . esc_html($order_number) . '' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '' . esc_html((string) ($row['product_type'] ?? '')) . '' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . ' ' . esc_html((string) ($row['currency'] ?? '')) . '' . esc_html($status_label) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; echo '' . esc_html__('详情', 'aksrt') . ''; $this->render_order_quick_status_buttons($order_number, $status_key); echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_order_status_' . $order_number); echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; echo '
'; if ($pages > 1) { echo '
'; echo paginate_links([ 'base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page_num, ]); echo '
'; } $this->render_footer(); } private function render_order_detail_page(string $order_number): void { $repo = AKSRT_Order_Repository::get_instance(); $order = $repo->get($order_number); if (!$order) { echo '

' . esc_html__('订单不存在。', 'aksrt') . '

'; echo '

' . esc_html__('返回订单列表', 'aksrt') . '

'; return; } $labels = class_exists('AKSRT_Domain_Model') ? AKSRT_Domain_Model::order_status_labels() : []; $context = $repo->get_admin_order_context($order_number); $user_id = (int) ($order['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $status = (string) ($order['status'] ?? ''); $meta = is_array($order['meta_payload'] ?? null) ? $order['meta_payload'] : []; $customer_note = (string) ($context['customer_note'] ?? $order['note_text'] ?? ''); $admin_note = is_array($meta) ? (string) ($meta['admin_note'] ?? '') : ''; if ($admin_note === '' && $customer_note === '' && !empty($order['note']) && !is_array(json_decode((string) $order['note'], true))) { $admin_note = (string) $order['note']; } $shipping_items = class_exists('AKSRT_Shipping') ? AKSRT_Shipping::get_instance()->get_by_order($order_number) : []; $after_sale = class_exists('AKSRT_After_Sale') ? (AKSRT_After_Sale::get_instance()->get_list(['order_number' => $order_number, 'limit' => 20])['items'] ?? []) : []; echo '

← ' . esc_html__('返回订单列表', 'aksrt') . '

'; echo ''; $rows = [ __('订单号', 'aksrt') => $order_number, __('用户', 'aksrt') => $user ? $user->display_name . ' (#' . $user_id . ')' : (string) $user_id, __('商品类型', 'aksrt') => (string) ($order['product_type'] ?? ''), __('商品 ID', 'aksrt') => (string) ($order['product_id'] ?? ''), __('金额', 'aksrt') => number_format((float) ($order['amount'] ?? 0), 2) . ' ' . (string) ($order['currency'] ?? ''), __('状态', 'aksrt') => $labels[$status] ?? $status, __('支付方式', 'aksrt') => (string) ($order['payment_method'] ?? ''), __('交易号', 'aksrt') => (string) ($order['payment_transaction_id'] ?? ''), __('创建时间', 'aksrt') => (string) ($order['created_at'] ?? ''), __('支付时间', 'aksrt') => (string) ($order['paid_at'] ?? ''), __('买家备注', 'aksrt') => $customer_note, ]; foreach ($rows as $label => $value) { echo ''; } if (!empty($context)) { echo ''; } echo '
' . esc_html($label) . '' . esc_html((string) $value) . '
' . esc_html__('附加上下文', 'aksrt') . '
' . esc_html(wp_json_encode($context, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)) . '
'; echo '

' . esc_html__('运营备注', 'aksrt') . '

'; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_order_note_' . $order_number); echo '

'; submit_button(__('保存备注', 'aksrt'), 'secondary', '', false); echo '
'; echo '

' . esc_html__('更新状态', 'aksrt') . '

'; echo '
'; $this->render_order_quick_status_buttons($order_number, $status, true); echo '
'; echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_order_status_' . $order_number); echo ' '; submit_button(__('保存状态', 'aksrt'), 'primary', '', false); echo '
'; echo '

' . esc_html__('物流记录', 'aksrt') . '

'; echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_create_shipping_' . $order_number); echo '

'; echo '

'; echo '

'; submit_button(__('创建发货', 'aksrt'), 'secondary', '', false); echo ' ' . esc_html__('物流管理', 'aksrt') . ''; echo '
'; if (!$shipping_items) { echo '

' . esc_html__('暂无物流记录。', 'aksrt') . '

'; } else { $status_options = $this->shipping_status_options(false); echo ''; foreach ($shipping_items as $item) { $sid = (int) ($item['id'] ?? 0); $st = (string) ($item['status'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('承运商', 'aksrt') . '' . esc_html__('运单号', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html((string) $sid) . '' . esc_html((string) ($item['carrier'] ?? '')) . '' . esc_html((string) ($item['tracking_no'] ?? '')) . '' . esc_html($status_options[$st] ?? $st) . '' . esc_html((string) ($item['created_at'] ?? '')) . '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_shipping_' . $sid); echo ''; echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; } echo '

' . esc_html__('售后工单', 'aksrt') . '

'; echo '
'; echo ''; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_create_after_sale_' . $order_number); echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('创建售后', 'aksrt'), 'secondary', '', false); echo ' ' . esc_html__('售后管理', 'aksrt') . ''; echo '
'; if (!$after_sale) { echo '

' . esc_html__('暂无售后工单。', 'aksrt') . '

'; } else { echo ''; foreach ($after_sale as $item) { $tid = (int) ($item['id'] ?? 0); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('类型', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html((string) $tid) . '' . esc_html((string) ($item['type_label'] ?? $item['type'] ?? '')) . '' . esc_html((string) ($item['status_label'] ?? $item['status'] ?? '')) . '' . esc_html((string) ($item['created_at'] ?? '')) . '' . esc_html__('在售后页处理', 'aksrt') . '
'; } } public function handle_update_order_status(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : ''; $new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : ''; check_admin_referer('aksrt_pay_update_order_status_' . $order_number); $ok = false; if ($order_number !== '' && $new_status !== '' && class_exists('AKSRT_Order_Repository')) { $ok = AKSRT_Order_Repository::get_instance()->update_status($order_number, $new_status, ['force' => true]); } $args = ['aksrt_pay_msg' => $ok ? 'order_updated' : 'order_failed']; $redirect_order = isset($_POST['redirect_order']) ? sanitize_text_field((string) wp_unslash($_POST['redirect_order'])) : ''; if ($redirect_order !== '') { $args['order'] = $redirect_order; } wp_safe_redirect($this->page_url('aksrt_orders', $args)); exit; } public function handle_update_order_note(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : ''; $admin_note = isset($_POST['admin_note']) ? sanitize_textarea_field((string) wp_unslash($_POST['admin_note'])) : ''; check_admin_referer('aksrt_pay_update_order_note_' . $order_number); $ok = false; if ($order_number !== '' && class_exists('AKSRT_Order_Repository')) { $ok = AKSRT_Order_Repository::get_instance()->update_admin_note($order_number, $admin_note); } wp_safe_redirect($this->page_url('aksrt_orders', [ 'order' => $order_number, 'aksrt_pay_msg' => $ok ? 'order_note_updated' : 'order_note_failed', ])); exit; } public function render_withdrawals_page(): void { $this->ensure_cap(); $this->render_header(__('提现审核', 'aksrt')); if (!class_exists('AKSRT_Withdrawal')) { echo '

' . esc_html__('提现模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Withdrawal::get_instance(); $stats = $svc->get_stats(); echo '

' . esc_html(sprintf( /* translators: 1: total 2: pending 3: completed 4: paid */ __('共 %1$d 条 · 待处理 %2$d · 已完成 %3$d · 已打款 %4$s', 'aksrt'), (int) ($stats['total'] ?? 0), (int) ($stats['pending'] ?? 0), (int) ($stats['completed'] ?? 0), number_format((float) ($stats['total_paid'] ?? 0), 2) )) . '

'; echo '
'; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $items = $svc->get_all([ 'status' => $status, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $total = $svc->get_count(['status' => $status]); $pages = max(1, (int) ceil($total / $per_page)); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $st = (string) ($row['status'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('用户', 'aksrt') . '' . esc_html__('金额', 'aksrt') . '' . esc_html__('方式', 'aksrt') . '' . esc_html__('账户', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('申请时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无提现记录', 'aksrt') . '
' . esc_html((string) $id) . '' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . '' . esc_html((string) ($row['method'] ?? '')) . '' . esc_html((string) ($row['account_info'] ?? '')) . '' . esc_html($status_options[$st] ?? $st) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_withdrawal_' . $id); echo ''; echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; echo '
'; if ($pages > 1) { echo '
'; echo paginate_links([ 'base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page_num, ]); echo '
'; } $this->render_footer(); } public function handle_update_withdrawal(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['withdrawal_id']) ? (int) $_POST['withdrawal_id'] : 0; $new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : ''; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; check_admin_referer('aksrt_pay_update_withdrawal_' . $id); $ok = false; if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Withdrawal')) { $ok = AKSRT_Withdrawal::get_instance()->update_status($id, $new_status, $note); } wp_safe_redirect($this->page_url('aksrt_withdraw', [ 'aksrt_pay_msg' => $ok ? 'withdraw_updated' : 'withdraw_failed', ])); exit; } /* ------------------------------------------------------------------ * Charge cards * ----------------------------------------------------------------*/ public function render_charge_cards_page(): void { $this->ensure_cap(); $this->render_header(__('卡密管理', 'aksrt')); if (!class_exists('AKSRT_Charge_Card')) { echo '

' . esc_html__('卡密模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : ''; $search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Charge_Card::get_instance(); $stats = $svc->get_stats(); $type_labels = [ 'balance' => __('余额', 'aksrt'), 'vip' => __('VIP', 'aksrt'), 'credits' => __('积分', 'aksrt'), 'points' => __('积分', 'aksrt'), ]; $status_labels = [ 'active' => __('可用', 'aksrt'), 'used' => __('已用', 'aksrt'), 'disabled' => __('已禁用', 'aksrt'), 'expired' => __('已过期', 'aksrt'), ]; echo '

' . esc_html(sprintf( /* translators: 1: total 2: active 3: used */ __('共 %1$d 张 · 可用 %2$d · 已用 %3$d', 'aksrt'), (int) ($stats['total'] ?? 0), (int) ($stats['active'] ?? 0), (int) ($stats['used'] ?? 0) )) . '

'; echo '

' . esc_html__('批量生成卡密', 'aksrt') . '

'; echo '
'; echo ''; wp_nonce_field('aksrt_pay_batch_charge_cards'); echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('生成', 'aksrt'), 'primary', '', false); echo '
'; if (!empty($_GET['aksrt_generated'])) { $generated = (int) $_GET['aksrt_generated']; echo '

' . esc_html(sprintf( /* translators: %d count */ __('成功生成 %d 张卡密。', 'aksrt'), $generated )) . '

'; } $generated_codes = get_transient('aksrt_pay_card_codes_' . get_current_user_id()); if (is_array($generated_codes) && $generated_codes) { delete_transient('aksrt_pay_card_codes_' . get_current_user_id()); echo '

' . esc_html__('本次生成卡密(请及时复制保存):', 'aksrt') . '

'; echo ''; echo '
'; } echo '
'; echo ''; echo ' '; echo ' '; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $result = $svc->get_list([ 'status' => $status, 'type' => $type, 'search' => $search, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ($result['max_pages'] ?? 1)); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $st = (string) ($row['status'] ?? ''); $row_type = (string) ($row['type'] ?? ''); $user_id = (int) ($row['used_by'] ?? $row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('类型', 'aksrt') . '' . esc_html__('密码', 'aksrt') . '' . esc_html__('面额', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('过期', 'aksrt') . '' . esc_html__('使用者', 'aksrt') . '' . esc_html__('创建时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无卡密', 'aksrt') . '
' . esc_html((string) $id) . '' . esc_html($type_labels[$row_type] ?? $row_type) . '' . esc_html((string) ($row['password'] ?? $row['code'] ?? '')) . '' . esc_html((string) ($row['amount'] ?? '')) . '' . esc_html($status_labels[$st] ?? $st) . '' . esc_html((string) ($row['expires_at'] ?? '—')) . '' . ($user ? esc_html($user->display_name) : '—') . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; if ($st === 'active') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_disable_charge_card_' . $id); submit_button(__('禁用', 'aksrt'), 'small', '', false); echo '
'; } else { echo '—'; } echo '
'; if ($pages > 1) { echo '
'; echo paginate_links([ 'base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page_num, ]); echo '
'; } $this->render_footer(); } public function handle_disable_charge_card(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['card_id']) ? (int) $_POST['card_id'] : 0; check_admin_referer('aksrt_pay_disable_charge_card_' . $id); $ok = false; if ($id > 0 && class_exists('AKSRT_Charge_Card')) { $ok = AKSRT_Charge_Card::get_instance()->disable($id); } wp_safe_redirect($this->page_url('aksrt_charge_cards', [ 'aksrt_pay_msg' => $ok ? 'card_disabled' : 'card_failed', ])); exit; } public function handle_batch_charge_cards(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } check_admin_referer('aksrt_pay_batch_charge_cards'); if (!class_exists('AKSRT_Charge_Card')) { wp_safe_redirect($this->page_url('aksrt_charge_cards', ['aksrt_pay_msg' => 'card_batch_failed'])); exit; } $type = isset($_POST['type']) ? sanitize_key((string) wp_unslash($_POST['type'])) : 'balance'; $count = isset($_POST['count']) ? (int) $_POST['count'] : 10; $length = isset($_POST['length']) ? (int) $_POST['length'] : 16; $prefix = isset($_POST['prefix']) ? sanitize_text_field((string) wp_unslash($_POST['prefix'])) : ''; $amount = isset($_POST['amount']) ? (float) wp_unslash($_POST['amount']) : 0; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; $level = isset($_POST['vip_level']) ? max(1, min(2, (int) $_POST['vip_level'])) : 1; $days = isset($_POST['vip_days']) ? max(1, (int) $_POST['vip_days']) : 30; $expires = isset($_POST['expires_at']) ? sanitize_text_field((string) wp_unslash($_POST['expires_at'])) : ''; if ($expires !== '') { $expires = str_replace('T', ' ', $expires); if (strlen($expires) === 16) { $expires .= ':00'; } } if ($type === 'points') { $type = 'credits'; } $meta = []; if ($type === 'balance') { $meta['amount'] = max(0, $amount); } elseif ($type === 'credits') { $meta['points'] = max(0, (int) $amount); } elseif ($type === 'vip') { $meta['level'] = $level; $meta['days'] = $days; } $codes = AKSRT_Charge_Card::get_instance()->batch_create($type, $meta, $count, $length, $prefix, $expires, $note); $ok = !empty($codes); if ($ok) { set_transient('aksrt_pay_card_codes_' . get_current_user_id(), $codes, 10 * MINUTE_IN_SECONDS); } wp_safe_redirect($this->page_url('aksrt_charge_cards', [ 'aksrt_pay_msg' => $ok ? 'card_batch_ok' : 'card_batch_failed', 'aksrt_generated' => count($codes), ])); exit; } /* ------------------------------------------------------------------ * Shipping * ----------------------------------------------------------------*/ public function render_shipping_page(): void { $this->ensure_cap(); $this->render_header(__('发货及物流', 'aksrt')); if (!class_exists('AKSRT_Shipping')) { echo '

' . esc_html__('物流模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $view = isset($_GET['view']) ? sanitize_key((string) wp_unslash($_GET['view'])) : 'records'; if (!in_array($view, ['records', 'pending'], true)) { $view = 'records'; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Shipping::get_instance(); $stats = $svc->get_stats(); $status_options = $this->shipping_status_options(true); $pending_total = 0; if (class_exists('AKSRT_Order_Repository')) { $pending_total = (int) (AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders(['limit' => 1, 'search' => ''])['total'] ?? 0); } echo '

' . esc_html(sprintf( /* translators: 1: shipping records 2: pending shipment orders */ __('物流记录 %1$d 条 · 待发货订单 %2$d', 'aksrt'), (int) ($stats['total'] ?? 0), $pending_total )) . '

'; echo ''; if ($view === 'pending') { $this->render_pending_shipment_board($search, $page_num, $per_page); $this->render_footer(); return; } echo '

' . esc_html__('新建发货', 'aksrt') . '

'; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_create_shipping'); echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('创建发货', 'aksrt'), 'primary', '', false); echo '
'; echo '
'; echo ''; echo ''; echo ' '; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $args = [ 'status' => $status, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]; if ($search !== '') { if (preg_match('/^[A-Za-z0-9_-]+$/', $search)) { $args['order_number'] = $search; } else { $args['tracking_no'] = $search; } } $result = $svc->get_list($args); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ceil(max(1, $total) / $per_page)); $row_status_options = $this->shipping_status_options(false); $show_express_id = isset($_GET['express_id']) ? (int) $_GET['express_id'] : 0; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $st = (string) ($row['status'] ?? ''); $order_number = (string) ($row['order_number'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ($show_express_id === $id) { echo ''; } } echo '
ID' . esc_html__('订单号', 'aksrt') . '' . esc_html__('承运商', 'aksrt') . '' . esc_html__('运单号', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无物流记录', 'aksrt') . '
' . esc_html((string) $id) . '' . esc_html($order_number) . '' . esc_html((string) ($row['carrier'] ?? '')) . '' . esc_html((string) ($row['tracking_no'] ?? '')) . '' . esc_html($row_status_options[$st] ?? $st) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_shipping_' . $id); echo ''; echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_query_express_' . $id); submit_button(__('查物流', 'aksrt'), 'small', '', false); echo '
'; echo '' . esc_html__('轨迹', 'aksrt') . ''; echo '
'; $this->render_express_timeline_panel($id); echo '
'; $this->render_pagination($pages, $page_num); $this->render_footer(); } private function render_pending_shipment_board(string $search, int $page_num, int $per_page): void { if (!class_exists('AKSRT_Order_Repository')) { echo '

' . esc_html__('订单服务不可用。', 'aksrt') . '

'; return; } echo '
'; echo ''; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $result = AKSRT_Order_Repository::get_instance()->get_pending_shipment_orders([ 'search' => $search, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ($result['max_pages'] ?? 1)); $labels = class_exists('AKSRT_Domain_Model') ? AKSRT_Domain_Model::order_status_labels() : []; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $order_number = (string) ($row['order_number'] ?? ''); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $status_key = (string) ($row['status'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
' . esc_html__('订单号', 'aksrt') . '' . esc_html__('用户', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('金额', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('支付时间', 'aksrt') . '' . esc_html__('立即发货', 'aksrt') . '
' . esc_html__('暂无待发货订单', 'aksrt') . '
' . esc_html($order_number) . '' . ($user ? esc_html($user->display_name . ' (#' . $user_id . ')') : esc_html((string) $user_id)) . '' . esc_html((string) ($row['product_type'] ?? '')) . '' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . ' ' . esc_html((string) ($row['currency'] ?? '')) . '' . esc_html($labels[$status_key] ?? $status_key) . '' . esc_html((string) ($row['paid_at'] ?? $row['created_at'] ?? '')) . ''; echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_create_shipping_' . $order_number); $this->render_carrier_field(''); echo ''; echo ''; submit_button(__('发货', 'aksrt'), 'primary small', '', false); echo '
'; echo '
'; $this->render_pagination($pages, $page_num); } public function handle_update_shipping(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0; $new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : ''; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; check_admin_referer('aksrt_pay_update_shipping_' . $id); $ok = false; if ($id > 0 && $new_status !== '' && class_exists('AKSRT_Shipping')) { $ok = AKSRT_Shipping::get_instance()->update_status($id, $new_status, $note, get_current_user_id()); } $redirect_order = isset($_POST['redirect_order']) ? sanitize_text_field((string) wp_unslash($_POST['redirect_order'])) : ''; if ($redirect_order !== '') { wp_safe_redirect($this->page_url('aksrt_orders', [ 'order' => $redirect_order, 'aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed', ])); exit; } wp_safe_redirect($this->page_url('aksrt_shipping', [ 'view' => 'records', 'aksrt_pay_msg' => $ok ? 'shipping_updated' : 'shipping_failed', ])); exit; } public function handle_query_express(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['shipping_id']) ? (int) $_POST['shipping_id'] : 0; $force = !empty($_POST['force']); check_admin_referer('aksrt_pay_query_express_' . $id); $ok = false; $order_number = ''; if ($id > 0 && class_exists('AKSRT_Shipping')) { $svc = AKSRT_Shipping::get_instance(); $record = $svc->get($id); $order_number = is_array($record) ? (string) ($record['order_number'] ?? '') : ''; $result = $svc->query_express($id, $force); $ok = !empty($result['success']); } wp_safe_redirect($this->page_url('aksrt_shipping', [ 'view' => 'records', 'express_id' => $id, 's' => $order_number, 'aksrt_pay_msg' => $ok ? 'express_ok' : 'express_failed', ])); exit; } public function handle_create_shipping(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : ''; $redirect_page = isset($_POST['redirect_page']) ? sanitize_key((string) wp_unslash($_POST['redirect_page'])) : 'order'; $nonce_action = $redirect_page === 'shipping' ? 'aksrt_pay_create_shipping' : ('aksrt_pay_create_shipping_' . $order_number); check_admin_referer($nonce_action); $ok = false; if ($order_number !== '' && class_exists('AKSRT_Shipping')) { if (class_exists('AKSRT_Order_Repository')) { $order = AKSRT_Order_Repository::get_instance()->get($order_number); if (!$order) { $this->redirect_shipping_create_result(false, $order_number, $redirect_page); } } $id = AKSRT_Shipping::get_instance()->create([ 'order_number' => $order_number, 'carrier' => sanitize_text_field((string) wp_unslash($_POST['carrier'] ?? '')), 'tracking_no' => sanitize_text_field((string) wp_unslash($_POST['tracking_no'] ?? '')), 'note' => sanitize_textarea_field((string) wp_unslash($_POST['note'] ?? '')), 'operator_id' => get_current_user_id(), ]); $ok = $id > 0; } $this->redirect_shipping_create_result($ok, $order_number, $redirect_page); } private function redirect_shipping_create_result(bool $ok, string $order_number, string $redirect_page): void { $msg = $ok ? 'shipping_created' : 'shipping_create_failed'; if ($redirect_page === 'shipping') { wp_safe_redirect($this->page_url('aksrt_shipping', [ 'view' => 'records', 'aksrt_pay_msg' => $msg, 's' => $order_number, ])); exit; } if ($redirect_page === 'pending') { wp_safe_redirect($this->page_url('aksrt_shipping', [ 'view' => 'pending', 'aksrt_pay_msg' => $msg, ])); exit; } wp_safe_redirect($this->page_url('aksrt_orders', [ 'order' => $order_number, 'aksrt_pay_msg' => $msg, ])); exit; } public function handle_create_after_sale(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $order_number = isset($_POST['order_number']) ? sanitize_text_field((string) wp_unslash($_POST['order_number'])) : ''; $redirect_page = isset($_POST['redirect_page']) ? sanitize_key((string) wp_unslash($_POST['redirect_page'])) : 'order'; $nonce_action = $redirect_page === 'after_sale' ? 'aksrt_pay_create_after_sale' : ('aksrt_pay_create_after_sale_' . $order_number); check_admin_referer($nonce_action); $ok = false; if ($order_number !== '' && class_exists('AKSRT_After_Sale')) { $user_id = isset($_POST['user_id']) ? (int) $_POST['user_id'] : 0; if ($user_id <= 0 && class_exists('AKSRT_Order_Repository')) { $order = AKSRT_Order_Repository::get_instance()->get($order_number); $user_id = (int) ($order['user_id'] ?? 0); } $id = AKSRT_After_Sale::get_instance()->create([ 'order_number' => $order_number, 'user_id' => $user_id, 'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'refund')), 'reason' => sanitize_textarea_field((string) wp_unslash($_POST['reason'] ?? '')), 'amount' => (float) ($_POST['amount'] ?? 0), 'note' => sanitize_textarea_field((string) wp_unslash($_POST['note'] ?? '')), ]); $ok = $id > 0; } $msg = $ok ? 'after_sale_created' : 'after_sale_create_failed'; if ($redirect_page === 'after_sale') { wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $msg, 's' => $order_number])); exit; } wp_safe_redirect($this->page_url('aksrt_orders', [ 'order' => $order_number, 'aksrt_pay_msg' => $msg, ])); exit; } public function render_after_sale_page(): void { $this->ensure_cap(); $this->render_header(__('售后管理', 'aksrt')); if (!class_exists('AKSRT_After_Sale')) { echo '

' . esc_html__('售后模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $type = isset($_GET['type']) ? sanitize_key((string) wp_unslash($_GET['type'])) : ''; $search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; if ($search === '' && isset($_GET['order_number'])) { $search = sanitize_text_field((string) wp_unslash($_GET['order_number'])); } $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_After_Sale::get_instance(); $stats = $svc->get_stats(); $status_options = $this->after_sale_status_options(true); $type_options = $this->after_sale_type_options(true); echo '

' . esc_html(sprintf( /* translators: 1: total 2: pending */ __('售后工单共 %1$d · 待处理 %2$d', 'aksrt'), (int) ($stats['total'] ?? 0), (int) ($stats['pending'] ?? 0) )) . '

'; echo '

' . esc_html__('新建售后', 'aksrt') . '

'; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_create_after_sale'); echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('创建售后', 'aksrt'), 'primary', '', false); echo '
'; echo '
'; echo ''; echo ' '; echo ' '; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $list_args = [ 'status' => $status, 'type' => $type, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]; if ($search !== '') { $list_args['order_number'] = $search; } $result = $svc->get_list($list_args); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ceil(max(1, $total) / $per_page)); $row_status_options = $this->after_sale_status_options(false); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $st = (string) ($row['status'] ?? ''); $order_number = (string) ($row['order_number'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('订单号', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('用户', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无售后工单', 'aksrt') . '
' . esc_html((string) $id) . '' . esc_html($order_number) . '' . esc_html((string) ($row['type_label'] ?? $type_options[$row['type'] ?? ''] ?? $row['type'] ?? '')) . '' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '' . esc_html((string) ($row['status_label'] ?? $row_status_options[$st] ?? $st)) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; if ($st === 'pending') { echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_after_sale_action_' . $id); submit_button(__('同意', 'aksrt'), 'small', '', false); echo '
'; echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_after_sale_action_' . $id); echo ''; echo '
'; } if ($st === 'processing') { echo '
'; echo ''; echo ''; echo ''; wp_nonce_field('aksrt_pay_after_sale_action_' . $id); submit_button(__('确认收货', 'aksrt'), 'small', '', false); echo '
'; } echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_update_after_sale_' . $id); echo ''; echo ''; submit_button(__('更新', 'aksrt'), 'small', '', false); echo '
'; echo '
'; $this->render_pagination($pages, $page_num); $this->render_footer(); } public function handle_update_after_sale(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['ticket_id']) ? (int) $_POST['ticket_id'] : 0; $new_status = isset($_POST['new_status']) ? sanitize_key((string) wp_unslash($_POST['new_status'])) : ''; $note = isset($_POST['note']) ? sanitize_textarea_field((string) wp_unslash($_POST['note'])) : ''; check_admin_referer('aksrt_pay_update_after_sale_' . $id); $ok = false; if ($id > 0 && $new_status !== '' && class_exists('AKSRT_After_Sale')) { $ok = AKSRT_After_Sale::get_instance()->update_status($id, $new_status, get_current_user_id(), $note); } wp_safe_redirect($this->page_url('aksrt_after_sale', ['aksrt_pay_msg' => $ok ? 'after_sale_updated' : 'after_sale_failed'])); exit; } public function handle_after_sale_action(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['ticket_id']) ? (int) $_POST['ticket_id'] : 0; $as_action = isset($_POST['as_action']) ? sanitize_key((string) wp_unslash($_POST['as_action'])) : ''; check_admin_referer('aksrt_pay_after_sale_action_' . $id); $ok = false; if ($id > 0 && class_exists('AKSRT_After_Sale')) { $svc = AKSRT_After_Sale::get_instance(); $operator_id = get_current_user_id(); if ($as_action === 'approve') { $ok = $svc->merchant_approve($id, $operator_id); } elseif ($as_action === 'reject') { $ok = $svc->merchant_reject($id, $operator_id, __('商家拒绝', 'aksrt')); } elseif ($as_action === 'confirm_return') { $ok = $svc->merchant_confirm_return($id, $operator_id); } } wp_safe_redirect($this->page_url('aksrt_after_sale', [ 'aksrt_pay_msg' => $ok ? 'after_sale_action_ok' : 'after_sale_action_failed', ])); exit; } public function render_coupons_page(): void { $this->ensure_cap(); $this->render_header(__('优惠码', 'aksrt')); if (!class_exists('AKSRT_Coupon')) { echo '

' . esc_html__('优惠码模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $search = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Coupon::get_instance(); $type_labels = [ 'fixed' => __('固定金额', 'aksrt'), 'percent' => __('折扣百分比', 'aksrt'), ]; $status_labels = [ 'active' => __('可用', 'aksrt'), 'disabled' => __('已禁用', 'aksrt'), ]; echo '

' . esc_html__('新建优惠码', 'aksrt') . '

'; echo '
'; echo ''; wp_nonce_field('aksrt_pay_create_coupon'); echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('创建', 'aksrt'), 'primary', '', false); echo '
'; echo '

' . esc_html__('批量生成优惠码', 'aksrt') . '

'; echo '
'; echo ''; wp_nonce_field('aksrt_pay_batch_coupons'); echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; echo '

'; submit_button(__('批量生成', 'aksrt'), 'secondary', '', false); echo '
'; if (!empty($_GET['aksrt_coupon_generated'])) { $generated = (int) $_GET['aksrt_coupon_generated']; echo '

' . esc_html(sprintf( /* translators: %d count */ __('成功生成 %d 个优惠码。', 'aksrt'), $generated )) . '

'; } $generated_codes = get_transient('aksrt_pay_coupon_codes_' . get_current_user_id()); if (is_array($generated_codes) && $generated_codes) { delete_transient('aksrt_pay_coupon_codes_' . get_current_user_id()); echo '

' . esc_html__('本次生成优惠码(请及时复制保存):', 'aksrt') . '

'; echo ''; echo '
'; } echo '
'; echo ''; echo ' '; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $result = $svc->get_list([ 'status' => $status, 'search' => $search, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ($result['total_pages'] ?? 1)); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $st = (string) ($row['status'] ?? ''); $row_type = (string) ($row['type'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('代码', 'aksrt') . '' . esc_html__('类型', 'aksrt') . '' . esc_html__('面值', 'aksrt') . '' . esc_html__('门槛/封顶', 'aksrt') . '' . esc_html__('范围', 'aksrt') . '' . esc_html__('已用/上限/每人', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('过期', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无优惠码', 'aksrt') . '
' . esc_html((string) $id) . '' . esc_html((string) ($row['code'] ?? '')) . '' . esc_html($type_labels[$row_type] ?? $row_type) . '' . esc_html((string) ($row['value'] ?? '')) . ($row_type === 'percent' ? '%' : '') . '' . esc_html((string) ($row['min_amount'] ?? 0)) . ' / ' . esc_html((string) ($row['max_discount'] ?? 0)) . '' . esc_html($this->format_coupon_scope_label($row['product_scope'] ?? [])) . '' . esc_html((string) ((int) ($row['used_count'] ?? 0)) . '/' . (string) ((int) ($row['usage_limit'] ?? 0)) . '/' . (string) ((int) ($row['per_user_limit'] ?? 0))) . '' . esc_html($status_labels[$st] ?? $st) . '' . esc_html((string) ($row['expires_at'] ?? '')) . ''; if ($st === 'active') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_disable_coupon_' . $id); submit_button(__('禁用', 'aksrt'), 'small', '', false); echo '
'; } elseif ($st === 'disabled') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_enable_coupon_' . $id); submit_button(__('启用', 'aksrt'), 'small', '', false); echo '
'; } else { echo '—'; } echo '
'; $this->render_pagination($pages, $page_num); $this->render_footer(); } public function handle_create_coupon(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } check_admin_referer('aksrt_pay_create_coupon'); $ok = false; if (class_exists('AKSRT_Coupon')) { $expires = isset($_POST['expires_at']) ? sanitize_text_field((string) wp_unslash($_POST['expires_at'])) : ''; if ($expires !== '') { $expires = str_replace('T', ' ', $expires); if (strlen($expires) === 16) { $expires .= ':00'; } } $id = AKSRT_Coupon::get_instance()->create([ 'code' => sanitize_text_field((string) wp_unslash($_POST['code'] ?? '')), 'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')), 'value' => (float) ($_POST['value'] ?? 0), 'min_amount' => (float) ($_POST['min_amount'] ?? 0), 'max_discount' => (float) ($_POST['max_discount'] ?? 0), 'usage_limit' => (int) ($_POST['usage_limit'] ?? 0), 'per_user_limit' => (int) ($_POST['per_user_limit'] ?? 0), 'product_scope' => $this->parse_coupon_product_scope_from_request(), 'expires_at' => $expires, ]); $ok = $id > 0; } wp_safe_redirect($this->page_url('aksrt_coupons', ['aksrt_pay_msg' => $ok ? 'coupon_created' : 'coupon_create_failed'])); exit; } public function handle_batch_coupons(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } check_admin_referer('aksrt_pay_batch_coupons'); $ok = false; $created = 0; $codes = []; if (class_exists('AKSRT_Coupon')) { $expires = isset($_POST['expires_at']) ? sanitize_text_field((string) wp_unslash($_POST['expires_at'])) : ''; if ($expires !== '') { $expires = str_replace('T', ' ', $expires); if (strlen($expires) === 16) { $expires .= ':00'; } } $result = AKSRT_Coupon::get_instance()->batch_create([ 'type' => sanitize_key((string) wp_unslash($_POST['type'] ?? 'fixed')), 'value' => (float) ($_POST['value'] ?? 0), 'min_amount' => (float) ($_POST['min_amount'] ?? 0), 'max_discount' => (float) ($_POST['max_discount'] ?? 0), 'usage_limit' => (int) ($_POST['usage_limit'] ?? 0), 'per_user_limit' => (int) ($_POST['per_user_limit'] ?? 0), 'expires_at' => $expires, ], (int) ($_POST['count'] ?? 10), (int) ($_POST['length'] ?? 10), sanitize_text_field((string) wp_unslash($_POST['prefix'] ?? ''))); $created = (int) ($result['created'] ?? 0); $codes = is_array($result['codes'] ?? null) ? $result['codes'] : []; $ok = $created > 0; if ($ok) { set_transient('aksrt_pay_coupon_codes_' . get_current_user_id(), $codes, 10 * MINUTE_IN_SECONDS); } } wp_safe_redirect($this->page_url('aksrt_coupons', [ 'aksrt_pay_msg' => $ok ? 'coupon_batch_ok' : 'coupon_batch_failed', 'aksrt_coupon_generated' => $created, ])); exit; } public function handle_disable_coupon(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['coupon_id']) ? (int) $_POST['coupon_id'] : 0; check_admin_referer('aksrt_pay_disable_coupon_' . $id); $ok = $id > 0 && class_exists('AKSRT_Coupon') && AKSRT_Coupon::get_instance()->disable($id); wp_safe_redirect($this->page_url('aksrt_coupons', ['aksrt_pay_msg' => $ok ? 'coupon_disabled' : 'coupon_failed'])); exit; } public function handle_enable_coupon(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['coupon_id']) ? (int) $_POST['coupon_id'] : 0; check_admin_referer('aksrt_pay_enable_coupon_' . $id); $ok = $id > 0 && class_exists('AKSRT_Coupon') && AKSRT_Coupon::get_instance()->enable($id); wp_safe_redirect($this->page_url('aksrt_coupons', ['aksrt_pay_msg' => $ok ? 'coupon_enabled' : 'coupon_failed'])); exit; } /* ------------------------------------------------------------------ * Income / rebate * ----------------------------------------------------------------*/ public function render_income_page(): void { $this->ensure_cap(); $this->render_header(__('创作分成', 'aksrt')); if (!class_exists('AKSRT_Revenue')) { echo '

' . esc_html__('分成模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Revenue::get_instance(); $stats = $svc->get_stats(); echo '

' . esc_html(sprintf( /* translators: 1: total 2: pending 3: settled */ __('合计 %1$s · 待结算 %2$s · 已结算 %3$s', 'aksrt'), number_format((float) ($stats['total'] ?? 0), 2), number_format((float) ($stats['pending'] ?? 0), 2), number_format((float) ($stats['settled'] ?? 0), 2) )) . '

'; echo '
'; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $result = $svc->get_list([ 'status' => $status, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ($result['max_pages'] ?? 1)); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $st = (string) ($row['status'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('用户', 'aksrt') . '' . esc_html__('订单号', 'aksrt') . '' . esc_html__('金额', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无分成记录', 'aksrt') . '
' . esc_html((string) $id) . '' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '' . esc_html((string) ($row['order_number'] ?? '')) . '' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . '' . esc_html($st) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; if ($st === 'pending') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_settle_income_' . $id); submit_button(__('结算', 'aksrt'), 'small', '', false); echo '
'; } else { echo '—'; } echo '
'; $this->render_pagination($pages, $page_num); $this->render_footer(); } public function handle_settle_income(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['revenue_id']) ? (int) $_POST['revenue_id'] : 0; check_admin_referer('aksrt_pay_settle_income_' . $id); $ok = $id > 0 && class_exists('AKSRT_Revenue') && AKSRT_Revenue::get_instance()->settle($id); wp_safe_redirect($this->page_url('aksrt_income', ['aksrt_pay_msg' => $ok ? 'income_settled' : 'income_failed'])); exit; } public function render_rebate_page(): void { $this->ensure_cap(); $this->render_header(__('推广返佣', 'aksrt')); if (!class_exists('AKSRT_Rebate')) { echo '

' . esc_html__('返佣模块未初始化。', 'aksrt') . '

'; $this->render_footer(); return; } $status = isset($_GET['status']) ? sanitize_key((string) wp_unslash($_GET['status'])) : ''; $page_num = max(1, (int) ($_GET['paged'] ?? 1)); $per_page = 20; $svc = AKSRT_Rebate::get_instance(); $stats = $svc->get_stats(); echo '

' . esc_html(sprintf( /* translators: 1: total 2: pending 3: settled amount */ __('记录 %1$d · 待结算 %2$d · 已结算金额 %3$s', 'aksrt'), (int) ($stats['total'] ?? 0), (int) ($stats['pending'] ?? 0), number_format((float) ($stats['settled_amount'] ?? 0), 2) )) . '

'; echo '
'; echo ''; echo ' '; submit_button(__('筛选', 'aksrt'), 'secondary', '', false); echo '
'; $result = $svc->get_list([ 'status' => $status, 'limit' => $per_page, 'offset' => ($page_num - 1) * $per_page, ]); $items = $result['items'] ?? []; $total = (int) ($result['total'] ?? 0); $pages = max(1, (int) ceil(max(1, $total) / $per_page)); echo ''; echo ''; echo ''; if (!$items) { echo ''; } foreach ($items as $row) { $id = (int) ($row['id'] ?? 0); $user_id = (int) ($row['user_id'] ?? 0); $user = $user_id > 0 ? get_userdata($user_id) : null; $st = (string) ($row['status'] ?? ''); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; } echo '
ID' . esc_html__('用户', 'aksrt') . '' . esc_html__('订单号', 'aksrt') . '' . esc_html__('金额', 'aksrt') . '' . esc_html__('状态', 'aksrt') . '' . esc_html__('时间', 'aksrt') . '' . esc_html__('操作', 'aksrt') . '
' . esc_html__('暂无返佣记录', 'aksrt') . '
' . esc_html((string) $id) . '' . ($user ? esc_html($user->display_name) : esc_html((string) $user_id)) . '' . esc_html((string) ($row['order_number'] ?? '')) . '' . esc_html(number_format((float) ($row['amount'] ?? 0), 2)) . '' . esc_html($st) . '' . esc_html((string) ($row['created_at'] ?? '')) . ''; if ($st === 'pending') { echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_settle_rebate_' . $id); submit_button(__('结算', 'aksrt'), 'small', '', false); echo '
'; echo '
'; echo ''; echo ''; wp_nonce_field('aksrt_pay_cancel_rebate_' . $id); submit_button(__('取消', 'aksrt'), 'small', '', false); echo '
'; } else { echo '—'; } echo '
'; $this->render_pagination($pages, $page_num); $this->render_footer(); } public function handle_settle_rebate(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0; check_admin_referer('aksrt_pay_settle_rebate_' . $id); $ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->settle($id); wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_settled' : 'rebate_failed'])); exit; } public function handle_cancel_rebate(): void { if (!current_user_can(self::CAPABILITY)) { wp_die(esc_html__('权限不足', 'aksrt')); } $id = isset($_POST['rebate_id']) ? (int) $_POST['rebate_id'] : 0; check_admin_referer('aksrt_pay_cancel_rebate_' . $id); $ok = $id > 0 && class_exists('AKSRT_Rebate') && AKSRT_Rebate::get_instance()->cancel($id); wp_safe_redirect($this->page_url('aksrt_rebate', ['aksrt_pay_msg' => $ok ? 'rebate_cancelled' : 'rebate_failed'])); exit; } /** * @return array */ private function shipping_status_options(bool $include_all = false): array { $options = []; if ($include_all) { $options[''] = __('全部状态', 'aksrt'); } if (class_exists('AKSRT_Shipping')) { foreach (AKSRT_Shipping::get_status_options() as $item) { $value = (string) ($item['value'] ?? ''); if ($value === '') { continue; } $options[$value] = (string) ($item['label'] ?? $value); } } if (count($options) === (int) $include_all) { $options = array_merge($options, [ 'shipped' => __('已发货', 'aksrt'), 'in_transit' => __('运输中', 'aksrt'), 'delivered' => __('已签收', 'aksrt'), 'returned' => __('已退回', 'aksrt'), ]); } return $options; } /** * @return array */ private function after_sale_status_options(bool $include_all = false): array { $options = []; if ($include_all) { $options[''] = __('全部状态', 'aksrt'); } if (class_exists('AKSRT_After_Sale')) { foreach (AKSRT_After_Sale::get_status_options() as $item) { $value = (string) ($item['value'] ?? ''); if ($value === '') { continue; } $options[$value] = (string) ($item['label'] ?? $value); } } return $options; } /** * @return array */ private function after_sale_type_options(bool $include_all = false): array { $options = []; if ($include_all) { $options[''] = __('全部类型', 'aksrt'); } // Keep operational create options broader than public get_type_options(). $defaults = [ 'refund' => __('仅退款', 'aksrt'), 'refund_return' => __('退货退款', 'aksrt'), 'exchange' => __('换货', 'aksrt'), 'repair' => __('维修', 'aksrt'), ]; if (class_exists('AKSRT_After_Sale')) { foreach (AKSRT_After_Sale::get_type_options() as $item) { $value = (string) ($item['value'] ?? ''); if ($value === '') { continue; } $defaults[$value] = (string) ($item['label'] ?? $value); } } return array_merge($options, $defaults); } private function render_carrier_field(string $selected = ''): void { $options = []; if (class_exists('AKSRT_Shipping')) { foreach (AKSRT_Shipping::get_carrier_options() as $item) { $value = (string) ($item['value'] ?? ''); $label = (string) ($item['label'] ?? $value); if ($value !== '') { $options[$value] = $label; } } } if ($options) { echo ''; return; } echo ''; } private function render_order_quick_status_buttons(string $order_number, string $current_status, bool $redirect_detail = false): void { $actions = [ 'completed' => __('完成', 'aksrt'), 'refunded' => __('退款', 'aksrt'), 'cancelled' => __('关闭', 'aksrt'), ]; foreach ($actions as $status => $label) { if ($status === $current_status) { continue; } $confirm = ''; if ($status === 'refunded') { $confirm = __('确认将该订单标记为已退款?', 'aksrt'); } elseif ($status === 'cancelled') { $confirm = __('确认关闭该订单?', 'aksrt'); } elseif ($status === 'completed') { $confirm = __('确认完成该订单?', 'aksrt'); } echo '
'; echo ''; echo ''; echo ''; if ($redirect_detail) { echo ''; } wp_nonce_field('aksrt_pay_update_order_status_' . $order_number); printf( '', $confirm !== '' ? ' onclick="return confirm(\'' . esc_js($confirm) . '\');"' : '', esc_html($label) ); echo '
'; } } private function render_express_timeline_panel(int $shipping_id): void { if ($shipping_id <= 0 || !class_exists('AKSRT_Shipping')) { echo '

' . esc_html__('无法加载物流轨迹。', 'aksrt') . '

'; return; } $svc = AKSRT_Shipping::get_instance(); // Prefer cached data; do not force remote query on pure view. $timeline = $svc->build_express_timeline($shipping_id); $record = $svc->get($shipping_id); echo '
'; echo '

' . esc_html__('物流轨迹', 'aksrt') . ' · '; echo esc_html((string) ($record['carrier'] ?? '')) . ' / ' . esc_html((string) ($record['tracking_no'] ?? '')); echo '

'; if (!$timeline) { echo '

' . esc_html__('暂无轨迹,可点击「查物流」拉取快递 API。', 'aksrt') . '

'; echo '
'; return; } echo '
    '; // newest first for operators $timeline = array_reverse($timeline); foreach ($timeline as $item) { $time = (string) ($item['time'] ?? ''); $label = (string) ($item['label'] ?? ''); echo '
  1. ' . esc_html($time) . ' ' . esc_html($label) . '
  2. '; } echo '
'; } /** * @return array */ private function parse_coupon_product_scope_from_request(): array { $type = isset($_POST['scope_type']) ? sanitize_key((string) wp_unslash($_POST['scope_type'])) : ''; if ($type === '' || !in_array($type, ['include', 'exclude', 'category'], true)) { return []; } $raw = isset($_POST['scope_ids']) ? (string) wp_unslash($_POST['scope_ids']) : ''; $parts = preg_split('/[\s,;]+/', $raw) ?: []; $ids = array_values(array_unique(array_filter(array_map('intval', $parts)))); if (!$ids) { return []; } $scope = [ 'type' => $type, 'ids' => $ids, ]; if ($type === 'category') { $scope['taxonomies'] = ['aksrt_product_cat', 'category']; } return $scope; } /** * @param mixed $scope */ private function format_coupon_scope_label($scope): string { if (is_string($scope) && $scope !== '') { $decoded = json_decode($scope, true); $scope = is_array($decoded) ? $decoded : []; } if (!is_array($scope) || empty($scope)) { return __('全部', 'aksrt'); } $type = sanitize_key((string) ($scope['type'] ?? '')); $ids = array_map('intval', (array) ($scope['ids'] ?? [])); $id_text = $ids ? implode(',', $ids) : '—'; $map = [ 'include' => __('含商品', 'aksrt'), 'exclude' => __('排除商品', 'aksrt'), 'category' => __('分类', 'aksrt'), ]; $label = $map[$type] ?? $type; return $label . ':' . $id_text; } private function render_pagination(int $pages, int $page_num): void { if ($pages <= 1) { return; } echo '
'; echo paginate_links([ 'base' => add_query_arg('paged', '%#%'), 'format' => '', 'prev_text' => '«', 'next_text' => '»', 'total' => $pages, 'current' => $page_num, ]); echo '
'; } }