refactor(admin): drop the SPA credits asset record browser
「用户近期资产记录」卡片在 SPA 积分配置页里按用户 ID + 资产类型 + 日期查 user meta 历史,再伪装成统一账本行(entries / operation_key / ref_key)。SPA 只承载配置,运营记录归原生 用户 → 积分/余额 屏幕 (CreditsAdmin / BalanceAdmin),这条平行路径删除,不留双读或迁移。 - CmsCredits.vue: 移除卡片、表格、分页及 ledger* 状态与 formatAssetValue/loadLedger/searchLedger/resetLedger - users.js: 删除仅服务该卡片的 getCreditLog() - UserController: 删除 /assets/transactions 路由、rest_get_credits_log() 及其唯一调用方 asset_value_to_minor() - 契约测试改为断言该能力不得回归 points_record / balance_record 本身保留,前端账本与原生后台仍在消费。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
324bcfdadc
commit
1c95f94bca
4 files changed
+15
-179
No files matched your search
@@ -135,20 +135,6 @@ class UserController extends ControllerBase {
|
||||
],
|
||||
]);
|
||||
|
||||
register_rest_route(self::API_NAMESPACE, '/assets/transactions', [
|
||||
'methods' => 'GET',
|
||||
'callback' => [$this, 'rest_get_credits_log'],
|
||||
'permission_callback' => [$this, 'check_permission'],
|
||||
'args' => [
|
||||
'user_id' => ['type' => 'integer', 'minimum' => 1, 'required' => true],
|
||||
'asset' => ['type' => 'string', 'enum' => ['points', 'balance'], 'required' => true],
|
||||
'page' => ['type' => 'integer', 'minimum' => 1, 'default' => 1],
|
||||
'per_page' => ['type' => 'integer', 'minimum' => 1, 'maximum' => 50, 'default' => 10],
|
||||
'date_from' => ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
'date_to' => ['type' => 'string', 'sanitize_callback' => 'sanitize_text_field'],
|
||||
],
|
||||
]);
|
||||
|
||||
// Report ticket list (admin)
|
||||
register_rest_route(self::API_NAMESPACE, '/users/reports', [
|
||||
'methods' => 'GET',
|
||||
@@ -740,54 +726,4 @@ class UserController extends ControllerBase {
|
||||
], 'message' => __('资产调整已保存', 'aksrt')]);
|
||||
}
|
||||
|
||||
public function rest_get_credits_log(\WP_REST_Request $request): \WP_REST_Response {
|
||||
$user_id = max(0, (int) $request->get_param('user_id'));
|
||||
$asset = sanitize_key((string) $request->get_param('asset'));
|
||||
if ($user_id <= 0 || !get_userdata($user_id) || !in_array($asset, ['points', 'balance'], true)) {
|
||||
return $this->error(__('用户或资产类型无效', 'aksrt'), 400);
|
||||
}
|
||||
$meta_key = $asset === 'points' ? 'points_record' : 'balance_record';
|
||||
$records = get_user_meta($user_id, $meta_key, true);
|
||||
$records = is_array($records) ? array_slice($records, 0, 50) : [];
|
||||
$date_from = sanitize_text_field((string) $request->get_param('date_from'));
|
||||
$date_to = sanitize_text_field((string) $request->get_param('date_to'));
|
||||
$records = array_values(array_filter($records, static function ($record) use ($date_from, $date_to): bool {
|
||||
if (!is_array($record)) return false;
|
||||
$day = substr((string) ($record['time'] ?? ''), 0, 10);
|
||||
return ($date_from === '' || $day >= $date_from) && ($date_to === '' || $day <= $date_to);
|
||||
}));
|
||||
$page = max(1, (int) $request->get_param('page'));
|
||||
$per_page = min(50, max(1, (int) $request->get_param('per_page')));
|
||||
$items = [];
|
||||
foreach (array_slice($records, ($page - 1) * $per_page, $per_page) as $index => $record) {
|
||||
$value = $asset === 'points' ? (int) ($record['value'] ?? 0) : $this->asset_value_to_minor((string) ($record['value'] ?? '0'));
|
||||
$after = $asset === 'points' ? (int) ($record['points'] ?? 0) : $this->asset_value_to_minor((string) ($record['balance'] ?? '0'));
|
||||
$items[] = [
|
||||
'id' => (($page - 1) * $per_page) + $index + 1,
|
||||
'operation_key' => (string) ($record['operation_key'] ?? ''),
|
||||
'reason' => (string) ($record['type'] ?? ''),
|
||||
'ref_type' => !empty($record['order_num']) ? 'order' : '',
|
||||
'ref_key' => (string) ($record['order_num'] ?? ''),
|
||||
'actor_user_id' => 0,
|
||||
'assets' => [$asset],
|
||||
'created_at' => (string) ($record['time'] ?? ''),
|
||||
'remark' => (string) ($record['desc'] ?? ''),
|
||||
'entries' => [[
|
||||
'user_id' => $user_id, 'asset' => $asset, 'entry_type' => $value < 0 ? 'debit' : 'credit',
|
||||
'delta' => $value, 'balance_after' => $after, 'remark' => (string) ($record['desc'] ?? ''),
|
||||
]],
|
||||
];
|
||||
}
|
||||
$data = ['items' => $items, 'total' => count($records), 'page' => $page, 'per_page' => $per_page];
|
||||
return $this->success(['data' => $data]);
|
||||
}
|
||||
|
||||
private function asset_value_to_minor(string $value): int {
|
||||
$value = trim($value);
|
||||
$negative = str_starts_with($value, '-');
|
||||
if ($negative) $value = substr($value, 1);
|
||||
try { $minor = \AKSRT\Ledger\AssetAmount::balance($value)->minor(); } catch (\InvalidArgumentException $e) { return 0; }
|
||||
return $negative ? -$minor : $minor;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user