feat(ticket): replace the after-sale flow with a general ticket system

The old 售后 flow was an order-refund appendage: tickets were hard-bound to an
order number, users could only file them from 「我的订单」against a paid order,
and the admin action bottomed out at 「标记订单已退款」. It could not carry
account questions or feature requests that have nothing to do with an order.

Replace it with a general ticket system modelled on 魔方财务云's idcsmart_ticket:
title + department + description are required, linking an order is optional
(user's own paid orders only). Add departments, custom statuses, preset replies
and internal admin notes as four configuration surfaces. Conversation history
moves off the ticket row's JSON log into dedicated ticket_reply rows, which
unlocks quoted replies. Front end gets a 工单中心 panel under 我的服务; back end
moves from 支付中心 → 售后服务 to users.php → 工单管理.

Per CLAUDE.md's rewrite-over-compatibility rule: drop the old table, build new
ones, delete the old code. No dual paths, no data migration. The upstream
plugin's upstream/downstream delivery and internal-ticket conversion are
deliberately left out — both are multi-provider platform concerns with no
meaning on a single WordPress site.

Data: order_aftersale becomes six aksrt_ticket* tables (ticket, ticket_reply,
ticket_status, ticket_type, ticket_prereply, ticket_note). SCHEMA_VERSION
2.6.0 -> 3.0.0. Status and department seeds are idempotent; the default status
「待接单」is flagged as non-editable.

Domain: new src/Ticket/ (13 files, all under 460 lines). Attachments reuse
UserController::rest_upload_comment_image with a ticket-specific permission
callback, mirroring the existing /report/upload-image route rather than
growing a second upload path.

Notifications go through AKSRT\Messages\Message::send() and deep-link to the
right surface; email/SMS stay out of scope since the theme's mail and SMS
stacks are separate implementations.

Refund gate opens up: marking an order refunded no longer requires an in-flight
ticket, only that the order is paid.

Also generalise a hardcoded special case in tools/audit-admin-contracts.php —
schema domain inference now reads the parent directory instead of matching
"PostList" by name, so new leaf schema files need no per-name exception.

Verification:
  php tools/audit-admin-contracts.php   exit 0, errors=0
  node --test (widget-system + admin)   664 pass / 0 fail
  php -l over all new/changed files     clean
  node --check over all JS              clean
  npm run build + build:public          clean

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kate522andClaude Opus 5 committed 2026-10-25 23:29:51 +08:00
1 parent 761c84d70f
commit dbb7de41e9
81 files changed
+5812 -4179

No files matched your search

-81
View File
@@ -569,87 +569,6 @@ class PaymentRuntime {
return false;
}
/**
* 售后策略(后台「支付&付费 → 售后策略」分区)的运行时读取。
*
* read_domain 走 SchemaProvider 的带默认读取:用户从未保存过该分区时,
* 预置原因 / 所需材料 / 文案等键仍取 schema 默认值(语义对齐
* UserRuntime::ban_settings 对禁封/举报分区的读取)。
*
* @return array{
* enabled:bool,time_limit:int,expired_text:string,
* reasons:array<int,array{slug:string,name:string}>,materials:string[],
* desc:string,img_enabled:bool,reason_placeholder:string
* }
*/
public static function get_after_sale_settings(): array {
$s = class_exists('\AKSRT\Admin\SchemaProvider')
? Settings::read_domain('payment', 'after_sale')
: Settings::get_all();
if (!is_array($s)) {
$s = [];
}
$reasons = [];
foreach ((array) ($s['after_sale_reasons'] ?? []) as $row) {
$text = trim((string) (is_array($row) ? ($row['t'] ?? '') : $row));
if ($text === '') {
continue;
}
$reasons[] = ['slug' => self::after_sale_slug($text), 'name' => sanitize_text_field($text)];
}
$materials = [];
foreach ((array) ($s['after_sale_materials'] ?? []) as $row) {
$text = trim((string) (is_array($row) ? ($row['t'] ?? '') : $row));
if ($text !== '') {
$materials[] = sanitize_text_field($text);
}
}
return [
'enabled' => !isset($s['after_sale_s']) || !empty($s['after_sale_s']),
'time_limit' => max(0, min(3650, (int) ($s['after_sale_time_limit'] ?? 7))),
'expired_text' => wp_kses_post((string) ($s['after_sale_expired_text'] ?? '')),
'reasons' => $reasons,
'materials' => $materials,
'desc' => wp_kses_post((string) ($s['after_sale_desc'] ?? '')),
'img_enabled' => !empty($s['after_sale_img_s']),
'reason_placeholder' => sanitize_text_field((string) ($s['after_sale_reason_placeholder'] ?? '')),
];
}
/**
* 订单是否已超过售后申请时效(自支付时间起算;时效 <=0 或缺支付时间视为未过期)。
*
* 时区口径与 UserOrders::get_order_countdown 保持一致:均以站点本地时间
* 比较存储的 DATETIME 与当前时间。
*/
public static function after_sale_expired(string $paid_at): bool {
$limit = (int) (self::get_after_sale_settings()['time_limit'] ?? 0);
if ($limit <= 0) {
return false;
}
$paid_at = trim($paid_at);
if ($paid_at === '') {
return false;
}
$paid_timestamp = strtotime($paid_at);
if ($paid_timestamp === false) {
return false;
}
return current_time('timestamp') > $paid_timestamp + $limit * DAY_IN_SECONDS;
}
/**
* 预置原因 slug:sanitize_key 无法处理中文标签(会被清洗成空串),
* 与 UserRuntime::ban_settings 同策略——ASCII 标签取 key,其余取稳定短哈希。
*/
private static function after_sale_slug(string $text): string {
$key = sanitize_key($text);
return $key !== '' ? $key : substr(md5($text), 0, 12);
}
private static function count_structured_lines(string $raw): int {
$lines = preg_split('/[\r\n]+/', $raw, -1, PREG_SPLIT_NO_EMPTY);
$count = 0;