From 83f046708422642c7fdc70d804892ed58eaff82d Mon Sep 17 00:00:00 2001
From: unknown
+
+
+
+
+ ' . esc_html__('暂无待处理申请。', 'aksrt') . '';
+ echo ' ';
+ }
+ }
+
+ /**
+ * @param string|int|float $value
+ */
+ private function render_discount_field_control(string $key, $value, bool $edit): void {
+ $id = esc_attr($key);
+ $name = esc_attr($key);
+ $val = (string) $value;
+
+ if ($key === 'shop_discount_type') {
+ $opts = [
+ 'reduction' => __('立减', 'aksrt'),
+ 'discount' => __('折扣', 'aksrt'),
+ 'gift' => __('赠品', 'aksrt'),
+ ];
+ echo '';
+ return;
+ }
+
+ if ($key === 'shop_discount_scope') {
+ $opts = [
+ 'item' => __('单品', 'aksrt'),
+ 'product' => __('商品', 'aksrt'),
+ 'author' => __('商家', 'aksrt'),
+ 'order' => __('整单', 'aksrt'),
+ ];
+ echo '';
+ return;
+ }
+
+ if ($key === 'shop_discount_user_limit') {
+ $opts = [
+ '' => __('不限', 'aksrt'),
+ 'vip' => __('VIP1', 'aksrt'),
+ 'vip_2' => __('VIP2', 'aksrt'),
+ 'auth' => __('已认证', 'aksrt'),
+ ];
+ echo '';
+ return;
+ }
+
+ if (in_array($key, ['shop_discount_is_important', 'shop_discount_countdown'], true)) {
+ echo '';
+ return;
+ }
+
+ if ($key === 'shop_discount_gift_config') {
+ echo '';
+ return;
+ }
+
+ $type = in_array($key, ['shop_discount_priority'], true) ? 'number' : 'text';
+ if (in_array($key, ['shop_discount_start', 'shop_discount_end'], true)) {
+ $type = 'datetime-local';
+ // Convert mysql-ish values to datetime-local if needed.
+ if ($val !== '' && str_contains($val, ' ')) {
+ $val = str_replace(' ', 'T', substr($val, 0, 16));
+ }
+ }
+
+ printf(
+ '',
+ esc_attr($type),
+ $name,
+ $id,
+ esc_attr($val),
+ $edit ? 'regular-text' : ''
+ );
+ }
+
+ public function save_discount_term_fields(int $term_id): void {
+ if (!current_user_can('manage_categories')) {
+ return;
+ }
+
+ $fields = $this->get_discount_field_definitions();
+ foreach ($fields as $key => $def) {
+ if (in_array($key, ['shop_discount_is_important', 'shop_discount_countdown'], true)) {
+ $raw = isset($_POST[$key]) ? '1' : '';
+ } else {
+ if (!isset($_POST[$key])) {
+ continue;
+ }
+ $raw = wp_unslash($_POST[$key]);
+ }
+
+ if (isset($def['sanitize']) && is_callable($def['sanitize'])) {
+ $value = call_user_func($def['sanitize'], $raw);
+ } else {
+ $value = sanitize_text_field((string) $raw);
+ }
+
+ if (in_array($key, ['shop_discount_start', 'shop_discount_end'], true) && is_string($value) && str_contains($value, 'T')) {
+ $value = str_replace('T', ' ', $value);
+ if (strlen($value) === 16) {
+ $value .= ':00';
+ }
+ }
+
+ update_term_meta($term_id, $key, $value);
+ }
+ }
}
diff --git a/inc/classes/forum/class-aksrt-plate-meta-box.php b/inc/classes/forum/class-aksrt-plate-meta-box.php
new file mode 100644
index 00000000..dbd2ff95
--- /dev/null
+++ b/inc/classes/forum/class-aksrt-plate-meta-box.php
@@ -0,0 +1,140 @@
+get_plate_moderators((int) $post->ID);
+ $applications = $forum->get_plate_moderator_applications((int) $post->ID);
+ } else {
+ $raw = get_post_meta($post->ID, '_aksrt_moderators', true);
+ $moderator_ids = is_array($raw) ? array_map('intval', $raw) : [];
+ $applications = get_post_meta($post->ID, '_aksrt_moderator_applications', true);
+ $applications = is_array($applications) ? $applications : [];
+ }
+
+ $moderator_labels = [];
+ foreach ($moderator_ids as $uid) {
+ $user = get_userdata((int) $uid);
+ $moderator_labels[] = $user
+ ? sprintf('%s (#%d)', $user->user_login, (int) $uid)
+ : (string) (int) $uid;
+ }
+ ?>
+ ';
+ echo ' ';
+ $this->render_discount_field_control($key, $value, true);
+ echo '
+
' . esc_html($user ? $user->display_name . ' (#' . $uid . ')' : (string) $uid) . '+ +
+| + | + | + | + | + |
|---|---|---|---|---|
| + | + | + | + | + |
+ +
+ + post_type !== 'aksrt_product' || !current_user_can('edit_post', $post_id)) { + return; + } + if (!class_exists('AKSRT_Shop')) { + return; + } + + $skus = isset($_POST['aksrt_variant_sku']) && is_array($_POST['aksrt_variant_sku']) ? wp_unslash($_POST['aksrt_variant_sku']) : []; + $attrs = isset($_POST['aksrt_variant_attrs']) && is_array($_POST['aksrt_variant_attrs']) ? wp_unslash($_POST['aksrt_variant_attrs']) : []; + $prices = isset($_POST['aksrt_variant_price']) && is_array($_POST['aksrt_variant_price']) ? wp_unslash($_POST['aksrt_variant_price']) : []; + $stocks = isset($_POST['aksrt_variant_stock']) && is_array($_POST['aksrt_variant_stock']) ? wp_unslash($_POST['aksrt_variant_stock']) : []; + $images = isset($_POST['aksrt_variant_image']) && is_array($_POST['aksrt_variant_image']) ? wp_unslash($_POST['aksrt_variant_image']) : []; + + $variants = []; + $count = max(count($skus), count($attrs), count($prices), count($stocks), count($images)); + for ($i = 0; $i < $count; $i++) { + $sku = sanitize_text_field((string) ($skus[$i] ?? '')); + $attr_raw = sanitize_text_field((string) ($attrs[$i] ?? '')); + $price = max(0, (float) ($prices[$i] ?? 0)); + $stock = max(0, (int) ($stocks[$i] ?? 0)); + $image = esc_url_raw((string) ($images[$i] ?? '')); + + if ($sku === '' && $attr_raw === '' && $price <= 0 && $stock <= 0 && $image === '') { + continue; + } + + $attributes = []; + if ($attr_raw !== '') { + foreach (preg_split('/\s*;\s*/', $attr_raw) ?: [] as $pair) { + if ($pair === '' || !str_contains($pair, ':')) { + continue; + } + [$k, $v] = array_map('trim', explode(':', $pair, 2)); + if ($k !== '') { + $attributes[$k] = $v; + } + } + } + + $variants[] = [ + 'sku' => $sku, + 'attributes' => $attributes, + 'price' => $price, + 'stock' => $stock, + 'image' => $image, + ]; + } + + AKSRT_Shop::get_instance()->save_variants($post_id, $variants); + } +}