__('添加邀请码', 'aksrt'), 'dialog' => 'aksrt-inv-add', 'primary' => true, 'icon' => 'dashicons-plus-alt2'], ['label' => __('导出邀请码', 'aksrt'), 'dialog' => 'aksrt-inv-export', 'icon' => 'dashicons-download'], ] ); $settings = $service->registration_settings(); if (empty($settings['enabled'])) { $settings_url = admin_url('admin.php?page=aksrt-settings#/users/auth'); echo '

' . esc_html__('邀请码注册尚未启用,已添加的邀请码暂不能用于注册。', 'aksrt') . ' ' . esc_html__('前往登录注册设置', 'aksrt') . '

'; } $title = isset($_GET['aksrt_inv_title']) ? sanitize_text_field(rawurldecode((string) wp_unslash($_GET['aksrt_inv_title']))) : ''; $message = isset($_GET['aksrt_inv_msg']) ? sanitize_text_field(rawurldecode((string) wp_unslash($_GET['aksrt_inv_msg']))) : ''; $type = ($_GET['aksrt_inv_type'] ?? '') === 'error' ? 'error' : 'success'; if ($title !== '') { echo '

' . esc_html($title) . '' . ($message !== '' ? ' ' . esc_html($message) : '') . '

'; } $this->render_invite_codes_list($service, $this_url, $nonce); $this->render_invite_codes_add($nonce); $this->render_invite_codes_export($nonce); echo '
'; NativeUi::page_close(); } private function render_invite_codes_list(\AKSRT\Payment\InviteCode $service, string $this_url, string $nonce): void { $status = in_array(($_GET['status'] ?? 'all'), ['all', 'unused', 'used'], true) ? (string) $_GET['status'] : 'all'; $s = isset($_GET['s']) ? sanitize_text_field((string) wp_unslash($_GET['s'])) : ''; $remark = isset($_GET['remark']) ? sanitize_text_field((string) wp_unslash($_GET['remark'])) : ''; $data = $service->list_codes([ 'page' => isset($_GET['paged']) ? max(1, (int) $_GET['paged']) : 1, 'status' => $status, 's' => $s, 'remark' => $remark, 'orderby' => isset($_GET['orderby']) ? sanitize_key((string) wp_unslash($_GET['orderby'])) : '', 'desc' => isset($_GET['desc']) ? sanitize_key((string) wp_unslash($_GET['desc'])) : '', ]); $filters = ['status' => $status, 's' => $s, 'remark' => $remark, 'orderby' => $data['orderby'], 'desc' => $data['desc']]; $filter_url = add_query_arg($filters, $this_url); NativeUi::card_open('', '', false, 'aksrt-inv-toolbar'); echo '
'; echo ''; foreach (array_diff_key($filters, ['s' => '']) as $key => $value) { echo ''; } echo ''; echo ''; echo '
'; if ($s !== '' || $remark !== '' || $status !== 'all') { echo '
'; if ($s !== '') { echo '' . esc_html(sprintf(__('关键词:%s', 'aksrt'), $s)) . ''; } if ($remark !== '') { echo '' . esc_html(sprintf(__('标识:%s', 'aksrt'), $remark)) . ''; } echo '' . esc_html__('清除筛选', 'aksrt') . '
'; } NativeUi::card_close(); echo '
'; echo ''; $bulk = '
' . '' . '' . '
'; NativeUi::table_card_open(__('邀请码列表', 'aksrt'), $bulk); echo ''; $columns = [ 'code' => __('邀请码', 'aksrt'), 'rewards' => __('使用奖励', 'aksrt'), 'created_at' => __('创建时间', 'aksrt'), 'updated_at' => __('更新时间', 'aksrt'), 'used_count' => __('使用状态', 'aksrt'), 'remark' => __('标识', 'aksrt'), ]; foreach ($columns as $key => $label) { $active = $key === $data['orderby']; $sort = $data['desc'] === 'ASC' ? 'ascending' : 'descending'; echo ''; } echo ''; if ($data['items'] === []) { echo NativeUi::empty_row(7, __('暂无符合条件的邀请码', 'aksrt'), __('调整筛选条件,或点击“添加邀请码”生成、导入新的邀请码。', 'aksrt')); } foreach ($data['items'] as $item) { $used = (int) $item['used_count']; $max_uses = (int) $item['max_uses']; echo ''; echo ''; echo ''; echo ''; } echo '
'; echo ''; if ($key === 'rewards') { echo esc_html($label); } else { $next = $active && $data['desc'] === 'ASC' ? 'DESC' : 'ASC'; $url = add_query_arg(['orderby' => $key, 'desc' => $next], $filter_url); $icon = $active && $data['desc'] === 'ASC' ? 'dashicons-arrow-up-alt2' : 'dashicons-arrow-down-alt2'; echo '' . esc_html($label) . ''; } echo '
' . wp_kses((string) $item['reward_text'], ['br' => []]) . '' . esc_html($item['created_at']) . '' . esc_html($item['updated_at']) . ''; $label = $used > 0 && $max_uses > 0 && $used < $max_uses ? sprintf(__('已使用 %1$d/%2$d', 'aksrt'), $used, $max_uses) : ($used > 0 ? __('已使用', 'aksrt') : __('未使用', 'aksrt')); echo NativeUi::badge($label, $used > 0 ? 'neutral' : 'success'); foreach ((array) $item['recent_users'] as $user) { echo ''; } echo ''; if ($item['remark'] !== '') { echo '' . esc_html($item['remark']) . ''; } else { echo '—'; } echo '
'; NativeUi::table_wrap_close(); echo '
' . esc_html(sprintf(__('共 %s 项', 'aksrt'), number_format_i18n((int) $data['total']))) . ''; if ((int) $data['max_pages'] > 1) { echo paginate_links([ 'base' => add_query_arg('paged', '%#%', $filter_url), 'format' => '', 'current' => (int) $data['page'], 'total' => (int) $data['max_pages'], 'type' => 'plain', 'prev_text' => '«', 'next_text' => '»', ]); } echo '
'; NativeUi::card_close(); echo '
'; } }