feat(admin): clear closed orders and bulk content-pay edit

Add zibll-style clear/delete for closed orders and bulk/quick fields
for post pay_type, modo, prices, and virtual_sales.
This commit is contained in:
kate522 committed 2026-07-15 11:49:30 +08:00
1 parent f197745830
commit 73fdc479be
4 files changed
+204 -2

No files matched your search

+105
View File
@@ -381,9 +381,20 @@ class AKSRT_Post_Meta_Box {
// §3.8 Quick / Bulk edit — separate code path (merge mode)
if (!empty($_POST['aksrt_qe_flag'])) {
$this->save_quick_edit($post_id);
// Bulk pay fields may be submitted together with QE flag on bulk form.
$this->save_bulk_pay_fields($post_id);
return;
}
// Bulk-only pay fields without aksrt_qe_flag (when only pay row used).
if (!empty($_POST['aksrt_bulk_pay_flag'])) {
$this->save_bulk_pay_fields($post_id);
// Continue only if full meta also posted; otherwise done.
if (!isset($_POST['aksrt_post_meta'])) {
return;
}
}
$raw = $_POST['aksrt_post_meta'] ?? [];
$sanitized = [
'cover_images' => isset($raw['cover_images']) ? sanitize_text_field($raw['cover_images']) : '',
@@ -653,11 +664,105 @@ class AKSRT_Post_Meta_Box {
<input type="number" name="aksrt_qe_maxheight" min="0" step="100" value="" class="aksrt-qe-maxheight" placeholder="<?php esc_attr_e('0=不限', 'aksrt'); ?>">
</label>
<br class="clear">
<h4 style="margin-top:10px;"><?php esc_html_e('内容付费(批量)', 'aksrt'); ?></h4>
<input type="hidden" name="aksrt_bulk_pay_flag" value="1">
<label class="alignleft">
<span class="title"><?php esc_html_e('付费类型', 'aksrt'); ?></span>
<select name="aksrt_bulk_pay_type" class="aksrt-bulk-pay-type">
<option value="-1"><?php esc_html_e('— 不更改 —', 'aksrt'); ?></option>
<?php
$pay_labels = class_exists('AKSRT_Domain_Model') ? AKSRT_Domain_Model::pay_type_labels() : [];
foreach ($pay_labels as $k => $lab) :
?>
<option value="<?php echo esc_attr($k); ?>"><?php echo esc_html($lab); ?></option>
<?php endforeach; ?>
</select>
</label>
<label class="alignleft">
<span class="title"><?php esc_html_e('支付方式', 'aksrt'); ?></span>
<select name="aksrt_bulk_pay_modo" class="aksrt-bulk-pay-modo">
<option value="-1"><?php esc_html_e('— 不更改 —', 'aksrt'); ?></option>
<option value="0"><?php esc_html_e('现金', 'aksrt'); ?></option>
<option value="points"><?php esc_html_e('积分', 'aksrt'); ?></option>
</select>
</label>
<label class="alignleft">
<span class="title"><?php esc_html_e('现金价', 'aksrt'); ?></span>
<input type="number" min="0" step="0.01" name="aksrt_bulk_pay_price" value="" class="aksrt-bulk-pay-price" placeholder="<?php esc_attr_e('留空=不改', 'aksrt'); ?>">
</label>
<label class="alignleft">
<span class="title"><?php esc_html_e('积分价', 'aksrt'); ?></span>
<input type="number" min="0" step="1" name="aksrt_bulk_points_price" value="" class="aksrt-bulk-points-price" placeholder="<?php esc_attr_e('留空=不改', 'aksrt'); ?>">
</label>
<label class="alignleft">
<span class="title"><?php esc_html_e('虚拟销量', 'aksrt'); ?></span>
<input type="number" min="0" step="1" name="aksrt_bulk_virtual_sales" value="" class="aksrt-bulk-virtual-sales" placeholder="<?php esc_attr_e('留空=不改', 'aksrt'); ?>">
</label>
<br class="clear">
</div>
</fieldset>
<?php
}
/**
* Bulk/quick merge update for content pay meta (_aksrt_pay + denormalized keys).
* Only non-sentinel fields are written; omit to keep existing.
*/
private function save_bulk_pay_fields(int $post_id): void {
if (!class_exists('AKSRT_Domain_Model') || !function_exists('aksrt_get_pay_meta')) {
return;
}
if (!current_user_can('edit_post', $post_id)) {
return;
}
$type_raw = isset($_POST['aksrt_bulk_pay_type']) ? (string) wp_unslash($_POST['aksrt_bulk_pay_type']) : '-1';
$modo_raw = isset($_POST['aksrt_bulk_pay_modo']) ? (string) wp_unslash($_POST['aksrt_bulk_pay_modo']) : '-1';
$price_raw = isset($_POST['aksrt_bulk_pay_price']) ? trim((string) wp_unslash($_POST['aksrt_bulk_pay_price'])) : '';
$points_raw = isset($_POST['aksrt_bulk_points_price']) ? trim((string) wp_unslash($_POST['aksrt_bulk_points_price'])) : '';
$virtual_raw = isset($_POST['aksrt_bulk_virtual_sales']) ? trim((string) wp_unslash($_POST['aksrt_bulk_virtual_sales'])) : '';
$has_change = ($type_raw !== '' && $type_raw !== '-1')
|| ($modo_raw !== '' && $modo_raw !== '-1')
|| $price_raw !== ''
|| $points_raw !== ''
|| $virtual_raw !== '';
if (!$has_change) {
return;
}
$meta = aksrt_get_pay_meta($post_id);
if ($type_raw !== '' && $type_raw !== '-1') {
$meta['pay_type'] = AKSRT_Domain_Model::normalize_pay_type(sanitize_key($type_raw));
}
if ($modo_raw !== '' && $modo_raw !== '-1') {
$modo = sanitize_key($modo_raw);
$meta['pay_modo'] = ($modo === 'points') ? 'points' : '0';
}
if ($price_raw !== '' && is_numeric($price_raw)) {
$meta['price'] = max(0, (float) $price_raw);
}
if ($points_raw !== '' && is_numeric($points_raw)) {
$meta['points_price'] = max(0, (int) $points_raw);
}
if ($virtual_raw !== '' && is_numeric($virtual_raw)) {
$meta['virtual_sales'] = max(0, (int) $virtual_raw);
}
$meta = AKSRT_Domain_Model::sanitize_pay_meta($meta);
update_post_meta($post_id, AKSRT_Domain_Model::PAY_META_KEY, $meta);
update_post_meta($post_id, AKSRT_Domain_Model::PAY_TYPE_KEY, (string) ($meta['pay_type'] ?? AKSRT_Domain_Model::PAY_TYPE_NO));
update_post_meta($post_id, AKSRT_Domain_Model::PAY_PRICE_KEY, (float) ($meta['price'] ?? 0));
if (class_exists('AKSRT_Domain_Model') && method_exists('AKSRT_Domain_Model', 'is_resource_pay_type')) {
update_post_meta(
$post_id,
AKSRT_Domain_Model::RESOURCE_MARKER_KEY,
AKSRT_Domain_Model::is_resource_pay_type((string) ($meta['pay_type'] ?? 'no')) ? 1 : 0
);
}
}
/**
* §3.8 Quick / Bulk edit merge-mode save.
* Only updates fields that were actually submitted (non-sentinel, non-empty).