fix(payment): close creator income contract gaps
This commit is contained in:
@@ -63,11 +63,11 @@ export const paymentSection = {
|
||||
schemaPage({
|
||||
key: 'payment-revenue',
|
||||
name: 'PaymentRevenue',
|
||||
label: '创作分成',
|
||||
label: '创作中心',
|
||||
route: '/payment/revenue',
|
||||
status: 'available',
|
||||
title: '创作分成',
|
||||
desc: '作者分成比例、结算模式、结算延迟和收益说明。',
|
||||
title: '创作中心',
|
||||
desc: '独立配置现金与积分分成比例、结算周期和结算备注文案。',
|
||||
canonicalDomain: 'payment',
|
||||
section: 'revenue',
|
||||
}),
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<template>
|
||||
<PaymentSectionPage
|
||||
section="revenue"
|
||||
title="收益中心"
|
||||
desc="查看现金与积分收入流水、收益统计和提现记录。"
|
||||
title="创作中心"
|
||||
desc="查看现金与积分收益统计及结算运营入口。"
|
||||
:links="[
|
||||
{ label: 'VIP 会员', path: '/payment/vip' },
|
||||
{ label: '推广返佣', path: '/payment/affiliate' },
|
||||
{ label: '创作分成运营', path: '/payment/income' },
|
||||
]"
|
||||
>
|
||||
<template #before-form>
|
||||
|
||||
@@ -77,7 +77,7 @@ function createSectionRedirectRoutes() {
|
||||
*/
|
||||
const NATIVE_OPS_REDIRECTS = [
|
||||
{ path: '/payment/charge-card', title: '充值卡', nativeAdminPath: 'admin.php?page=aksrt_charge_cards' },
|
||||
{ path: '/payment/revenue', title: '创作分成', nativeAdminPath: 'admin.php?page=aksrt_income' },
|
||||
{ path: '/payment/income', title: '创作分成运营', nativeAdminPath: 'admin.php?page=aksrt_income' },
|
||||
{ path: '/payment/rebate', title: '返佣管理', nativeAdminPath: 'admin.php?page=aksrt_rebate' },
|
||||
{ path: '/users/messages', title: '消息中心', nativeAdminPath: 'users.php?page=aksrt_messages' },
|
||||
{ path: '/users/invite-codes', title: '邀请码运营', nativeAdminPath: 'users.php?page=aksrt_invite_codes' },
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const revenueSchema = {
|
||||
key: 'payment.revenue',
|
||||
title: '创作分成',
|
||||
title: '创作中心',
|
||||
icon: 'fas fa-chart-line',
|
||||
description: '分别配置现金收益和积分收益的会员分成比例,结算周期结束后自动入账。',
|
||||
defaults: {
|
||||
@@ -17,7 +17,7 @@ export const revenueSchema = {
|
||||
groups: [
|
||||
{
|
||||
key: 'basic',
|
||||
title: '创作分成设置',
|
||||
title: '创作中心设置',
|
||||
icon: 'fas fa-cog',
|
||||
fields: [
|
||||
{ key: 'pay_income_s', label: '启用创作分成', type: 'switch', default: false },
|
||||
|
||||
@@ -12,7 +12,7 @@ export const MEDAL_GET_TYPES = [
|
||||
{ label: '文章获赞', value: 'like' },
|
||||
{ label: '评论获赞', value: 'comment_like' },
|
||||
{ label: '内容阅读量', value: 'views' },
|
||||
{ label: '创作分成累计(元)', value: 'pay_income' },
|
||||
{ label: '现金创作分成累计(元)', value: 'pay_income' },
|
||||
{ label: '推广佣金累计(元)', value: 'pay_rebate' },
|
||||
{ label: '仅手动授予', value: 'manually_add' },
|
||||
]
|
||||
|
||||
@@ -24,7 +24,7 @@ export const featuresSchema = {
|
||||
title: '用户中心',
|
||||
icon: 'fas fa-user-shield',
|
||||
fields: [
|
||||
{ key: 'user_center_tabs', label: '用户中心 Tab', type: 'input', default: 'profile,level,posts,comments,favorites,vip,credits,revenue,auth', help: '逗号分隔。level=我的等级;revenue=收益中心;auth=官方认证;等级、VIP、订单、收益中心和认证会按功能开关自动注入' },
|
||||
{ key: 'user_center_tabs', label: '用户中心 Tab', type: 'input', default: 'profile,level,comments,favorites,vip,credits,revenue,auth', help: '逗号分隔。level=我的等级;creator=创作中心;revenue=推广收益中心;auth=官方认证;等级、VIP、订单、创作中心、收益中心和认证会按功能开关自动注入' },
|
||||
{ key: 'user_cover_upload', label: '封面上传', type: 'switch', default: true },
|
||||
{ key: 'user_social_links', label: '社交链接', type: 'switch', default: true },
|
||||
{ key: 'user_desc_std', label: '默认签名', type: 'input', default: '这家伙很懒…', help: '用户未设置个人简介时显示的默认文案' },
|
||||
|
||||
@@ -721,6 +721,7 @@
|
||||
.creator-income-card__metrics small { display: block; }
|
||||
.creator-income-card__metrics strong { color: var(--color-ink); font-size: 18px; font-variant-numeric: tabular-nums; }
|
||||
.creator-income-card__metrics small { margin-top: 4px; color: var(--color-ink-4); font-size: 11px; }
|
||||
.creator-income-card__hint { margin: 12px 0 0; color: var(--color-ink-4); font-size: 12px; line-height: 1.5; }
|
||||
.creator-income__info { padding: 20px; }
|
||||
.creator-income__info h2,
|
||||
.creator-income__toolbar h2 { margin: 0; font-size: 16px; }
|
||||
|
||||
@@ -67,6 +67,9 @@ $currency_labels = [
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if ($unit === 'CNY') : ?>
|
||||
<p class="creator-income-card__hint"><?php esc_html_e('超过 50 元可申请现金提现。', 'aksrt'); ?></p>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
||||
|
||||
@@ -187,10 +187,13 @@ class PayIncome {
|
||||
}
|
||||
}
|
||||
$ids = array_values(array_unique($ids));
|
||||
$ok = !empty($ids)
|
||||
&& class_exists('\\AKSRT\\Payment\\Revenue')
|
||||
&& \AKSRT\Payment\Revenue::get_instance()->settle($ids, get_current_user_id());
|
||||
wp_safe_redirect($this->page_url('aksrt_income', ['aksrt_pay_msg' => $ok ? 'income_batch_settled' : 'income_failed']));
|
||||
$batch_result = !empty($ids) && class_exists('\\AKSRT\\Payment\\Revenue')
|
||||
? \AKSRT\Payment\Revenue::get_instance()->settle_batch($ids, get_current_user_id())
|
||||
: ['settled' => [], 'failed' => $ids];
|
||||
$message = empty($batch_result['settled'])
|
||||
? 'income_failed'
|
||||
: (!empty($batch_result['failed']) ? 'income_batch_partial' : 'income_batch_settled');
|
||||
wp_safe_redirect($this->page_url('aksrt_income', ['aksrt_pay_msg' => $message]));
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -218,12 +221,15 @@ class PayIncome {
|
||||
$map = [
|
||||
'income_settled' => __('分成已结算。', 'aksrt'),
|
||||
'income_batch_settled' => __('选中分成已批量结算。', 'aksrt'),
|
||||
'income_batch_partial' => __('部分分成已结算,失败记录可稍后重试。', 'aksrt'),
|
||||
'income_failed' => __('分成结算失败。', 'aksrt'),
|
||||
];
|
||||
if (!isset($map[$code])) {
|
||||
return;
|
||||
}
|
||||
$class = str_contains($code, 'failed') ? 'notice-error' : 'notice-success';
|
||||
$class = $code === 'income_batch_partial'
|
||||
? 'notice-warning'
|
||||
: (str_contains($code, 'failed') ? 'notice-error' : 'notice-success');
|
||||
echo '<div class="notice ' . esc_attr($class) . ' is-dismissible"><p>' . esc_html($map[$code]) . '</p></div>';
|
||||
}
|
||||
|
||||
|
||||
@@ -163,11 +163,11 @@ class SchemaPayment {
|
||||
],
|
||||
'revenue' => [
|
||||
'key' => 'revenue',
|
||||
'title' => '创作分成',
|
||||
'title' => '创作中心',
|
||||
'version' => '2.0.0',
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'basic', 'title' => '创作分成设置', 'fields' => [
|
||||
['key' => 'basic', 'title' => '创作中心设置', 'fields' => [
|
||||
['key' => 'pay_income_s', 'label' => '启用创作分成', 'type' => 'switch', 'default' => false],
|
||||
['key' => 'payment_revenue_cycle_days', 'label' => '结算周期(天)', 'type' => 'number', 'default' => 30, 'min' => 1, 'max' => 365, 'dependsOn' => ['key' => 'pay_income_s', 'value' => true]],
|
||||
['key' => 'payment_revenue_note', 'label' => '结算备注文案', 'type' => 'textarea', 'sanitize_type' => 'html', 'default' => '<p>订单完成并经过结算周期后,作者分成会自动转入对应的钱包。</p>', 'dependsOn' => ['key' => 'pay_income_s', 'value' => true]],
|
||||
|
||||
@@ -601,7 +601,7 @@ class SchemaUsers {
|
||||
'option_key' => 'aksrt_settings',
|
||||
'groups' => [
|
||||
['key' => 'center', 'title' => '用户中心', 'fields' => [
|
||||
['key' => 'user_center_tabs', 'label' => '用户中心 Tab', 'type' => 'input', 'default' => 'profile,level,posts,comments,favorites,vip,credits,revenue,auth', 'help' => '逗号分隔。level=我的等级;revenue=收益中心;auth=官方认证;等级、VIP、订单、收益中心和认证会按功能开关自动注入'],
|
||||
['key' => 'user_center_tabs', 'label' => '用户中心 Tab', 'type' => 'input', 'default' => 'profile,level,comments,favorites,vip,credits,revenue,auth', 'help' => '逗号分隔。level=我的等级;creator=创作中心;revenue=推广收益中心;auth=官方认证;等级、VIP、订单、创作中心、收益中心和认证会按功能开关自动注入'],
|
||||
['key' => 'user_cover_upload', 'label' => '封面上传', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'user_social_links', 'label' => '社交链接', 'type' => 'switch', 'default' => true],
|
||||
['key' => 'user_desc_std', 'label' => '默认签名', 'type' => 'input', 'default' => '这家伙很懒…', 'desc' => '用户未设置个人简介时显示的默认文案'],
|
||||
|
||||
+33
-28
@@ -30,11 +30,23 @@ class Revenue {
|
||||
public function create_from_paid_order(array $order): int {
|
||||
global $wpdb;
|
||||
|
||||
if (!$this->is_enabled()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$order_number = sanitize_text_field((string) ($order['order_number'] ?? ''));
|
||||
if ($order_number === '' || (string) ($order['status'] ?? '') !== 'completed') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$existing = $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT id FROM {$this->table()} WHERE order_number = %s ORDER BY id ASC LIMIT 1",
|
||||
$order_number
|
||||
));
|
||||
if ((int) $existing > 0) {
|
||||
return (int) $existing;
|
||||
}
|
||||
|
||||
$meta = $this->decode_order_meta($order);
|
||||
if (empty($meta['content_pay'])) {
|
||||
return 0;
|
||||
@@ -95,8 +107,7 @@ class Revenue {
|
||||
if ($inserted === false) {
|
||||
// Duplicate callbacks are a successful no-op by contract.
|
||||
$existing = $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT id FROM {$this->table()} WHERE author_id = %d AND order_number = %s LIMIT 1",
|
||||
$author_id,
|
||||
"SELECT id FROM {$this->table()} WHERE order_number = %s ORDER BY id ASC LIMIT 1",
|
||||
$order_number
|
||||
));
|
||||
return (int) $existing;
|
||||
@@ -113,28 +124,6 @@ class Revenue {
|
||||
return $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy generic insertion retained as the native income page entry point.
|
||||
*/
|
||||
public function add(int $user_id, float $amount, string $order_number = '', string $type = 'income'): int {
|
||||
global $wpdb;
|
||||
if ($user_id <= 0 || $amount <= 0) {
|
||||
return 0;
|
||||
}
|
||||
$order_number = sanitize_text_field($order_number);
|
||||
$wpdb->insert($this->table(), [
|
||||
'author_id' => $user_id,
|
||||
'order_number' => $order_number,
|
||||
'amount' => round($amount, 2),
|
||||
'original_amount' => round($amount, 2),
|
||||
'currency' => 'CNY',
|
||||
'type' => sanitize_key($type),
|
||||
'status' => 'pending',
|
||||
'created_at' => current_time('mysql'),
|
||||
], ['%d', '%s', '%f', '%f', '%s', '%s', '%s', '%s']);
|
||||
return (int) $wpdb->insert_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Settle one or more pending records through matching atomic balance services.
|
||||
*
|
||||
@@ -142,18 +131,34 @@ class Revenue {
|
||||
* @param int $actor_id
|
||||
*/
|
||||
public function settle($record_ids, int $actor_id = 0): bool {
|
||||
$result = $this->settle_batch($record_ids, $actor_id);
|
||||
return !empty($result['settled']) && empty($result['failed']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settle a batch while preserving per-record outcomes for operational feedback.
|
||||
*
|
||||
* @param int|array<int,int> $record_ids
|
||||
* @param int $actor_id
|
||||
* @return array{settled:array<int,int>,failed:array<int,int>}
|
||||
*/
|
||||
public function settle_batch($record_ids, int $actor_id = 0): array {
|
||||
$ids = is_array($record_ids) ? $record_ids : [$record_ids];
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', $ids), static fn (int $id): bool => $id > 0)));
|
||||
if (!$ids || !$this->is_enabled()) {
|
||||
return false;
|
||||
return ['settled' => [], 'failed' => $ids];
|
||||
}
|
||||
|
||||
$settled = [];
|
||||
$failed = [];
|
||||
foreach ($ids as $revenue_id) {
|
||||
if (!$this->settle_one($revenue_id, $actor_id)) {
|
||||
return false;
|
||||
if ($this->settle_one($revenue_id, $actor_id)) {
|
||||
$settled[] = $revenue_id;
|
||||
} else {
|
||||
$failed[] = $revenue_id;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return ['settled' => $settled, 'failed' => $failed];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,14 +83,14 @@ class UserRuntime {
|
||||
*/
|
||||
public static function get_user_center_settings(): array {
|
||||
$settings = Settings::get_all();
|
||||
$raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,posts,comments,credits,revenue,favorites,auth';
|
||||
$raw_tabs = $settings['user_center_tabs'] ?? 'profile,level,comments,credits,revenue,favorites,auth';
|
||||
$tabs = is_array($raw_tabs)
|
||||
? $raw_tabs
|
||||
: preg_split('/[\s,]+/', (string) $raw_tabs, -1, PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
// Built-in switchable panels. VIP is always auto-injected when enabled
|
||||
// by AKSRT\User\Center — keep it allowed for explicit config too.
|
||||
$allowed_tabs = ['profile', 'level', 'posts', 'comments', 'favorites', 'credits', 'revenue', 'vip', 'orders', 'auth', 'settings'];
|
||||
$allowed_tabs = ['profile', 'level', 'comments', 'favorites', 'credits', 'revenue', 'vip', 'orders', 'auth', 'settings'];
|
||||
$normalized_tabs = ['profile'];
|
||||
|
||||
foreach ((array) $tabs as $tab) {
|
||||
@@ -104,8 +104,8 @@ class UserRuntime {
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array('posts', $normalized_tabs, true) && !in_array('comments', $normalized_tabs, true)) {
|
||||
$normalized_tabs[] = 'posts';
|
||||
if (!in_array('comments', $normalized_tabs, true)) {
|
||||
$normalized_tabs[] = 'comments';
|
||||
}
|
||||
|
||||
// Ensure VIP appears in configured tabs when membership is on, even if
|
||||
|
||||
@@ -13,6 +13,7 @@ class Metrics {
|
||||
public const META_COMMENT_LIKE_SUM = 'aksrt_comment_like_sum';
|
||||
public const META_POSTS_VIEWS_SUM = 'aksrt_posts_views_sum';
|
||||
public const META_PAY_INCOME = 'aksrt_pay_income_sum';
|
||||
public const META_PAY_INCOME_POINTS = 'aksrt_pay_income_points_sum';
|
||||
public const META_PAY_REBATE = 'aksrt_pay_rebate_sum';
|
||||
public const META_CHECKIN_ALL_DAY = 'aksrt_checkin_all_day';
|
||||
|
||||
@@ -132,13 +133,14 @@ class Metrics {
|
||||
* @param array $context
|
||||
*/
|
||||
public function on_creator_income_added($user_id, $amount, $context = []): void {
|
||||
unset($context);
|
||||
$currency = sanitize_key((string) ($context['currency'] ?? 'CNY'));
|
||||
$user_id = (int) $user_id;
|
||||
$amount = (float) $amount;
|
||||
if ($user_id <= 0 || $amount <= 0) {
|
||||
return;
|
||||
}
|
||||
self::bump_user_meta($user_id, self::META_PAY_INCOME, $amount);
|
||||
$meta_key = $currency === 'points' ? self::META_PAY_INCOME_POINTS : self::META_PAY_INCOME;
|
||||
self::bump_user_meta($user_id, $meta_key, $amount);
|
||||
self::reevaluate_medals($user_id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user