feat(payment): rebuild order details and asset records
This commit is contained in:
@@ -11,7 +11,7 @@ if (!function_exists('aksrt_user_points')) {
|
||||
function aksrt_user_points(int $user_id = 0): int {
|
||||
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
return $user_id > 0
|
||||
? \AKSRT\Ledger\LedgerService::get_instance()->balance($user_id, \AKSRT\Ledger\AssetType::POINTS)
|
||||
? \AKSRT\Credits\MetaAssetService::get_instance()->balance_points($user_id)
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ if (!function_exists('aksrt_user_balance_decimal')) {
|
||||
function aksrt_user_balance_decimal(int $user_id = 0): string {
|
||||
$user_id = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
return $user_id > 0
|
||||
? \AKSRT\Ledger\LedgerService::get_instance()->balance_decimal($user_id)
|
||||
? \AKSRT\Credits\MetaAssetService::get_instance()->balance_decimal($user_id)
|
||||
: '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,13 +319,12 @@ if (!function_exists('aksrt_get_user_content_paid_order')) {
|
||||
return null;
|
||||
}
|
||||
$orders = \AKSRT\Payment\OrderRepository::get_instance()->get_user_orders($uid, [
|
||||
'product_type' => \AKSRT\Core\DomainModel::ORDER_PRODUCT_RESOURCE,
|
||||
'status' => '',
|
||||
'limit' => 20,
|
||||
'offset' => 0,
|
||||
]);
|
||||
foreach ($orders as $order) {
|
||||
if ((int) ($order['product_id'] ?? 0) !== $post_id) {
|
||||
if ((int) ($order['product_id'] ?? 0) !== $post_id || !\AKSRT\Core\DomainModel::is_resource_product_type((string) ($order['product_type'] ?? ''))) {
|
||||
continue;
|
||||
}
|
||||
$status = (string) ($order['status'] ?? '');
|
||||
|
||||
@@ -188,7 +188,6 @@ add_action('wp_ajax_aksrt_submit_tip', function (): void {
|
||||
|
||||
wp_send_json_success([
|
||||
'message' => __('赞赏成功,金额已进入对方余额', 'aksrt'),
|
||||
'transaction_id' => $result->transaction_id,
|
||||
'replayed' => $result->replayed,
|
||||
'balance' => \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, $result->balance($sender_id, \AKSRT\Ledger\AssetType::BALANCE))->decimal(),
|
||||
]);
|
||||
|
||||
@@ -21,12 +21,14 @@ defined('ABSPATH') || exit;
|
||||
$credits_page = ($asset_request['asset'] ?? '') === 'points'
|
||||
? max(1, (int) ($asset_request['page'] ?? 1))
|
||||
: 1;
|
||||
$log = \AKSRT\Ledger\LedgerQuery::get_instance()->history(['user_id' => $user_id, 'asset' => 'points', 'page' => $credits_page, 'per_page' => 10]);
|
||||
if (!empty($log['items'])) :
|
||||
$history = get_user_meta((int) $user_id, 'points_record', true);
|
||||
$history = is_array($history) ? array_slice($history, 0, 50) : [];
|
||||
$items = array_slice($history, ($credits_page - 1) * 10, 10);
|
||||
if ($items) :
|
||||
?>
|
||||
<div class="uc-transactions__list">
|
||||
<?php foreach ($log['items'] as $row) :
|
||||
$delta = (int) $row['delta_minor'];
|
||||
<?php foreach ($items as $row) :
|
||||
$delta = (int) ($row['value'] ?? 0);
|
||||
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
||||
?>
|
||||
<div class="uc-transactions__item">
|
||||
@@ -35,12 +37,12 @@ defined('ABSPATH') || exit;
|
||||
</div>
|
||||
<div class="uc-transactions__info">
|
||||
<div class="uc-transactions__reason">
|
||||
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
|
||||
<?php echo esc_html((string) ($row['desc'] ?? '') !== '' ? (string) $row['desc'] : aksrt_asset_reason_label((string) ($row['type'] ?? ''))); ?>
|
||||
</div>
|
||||
<div class="uc-transactions__time">
|
||||
<?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?>
|
||||
<?php echo esc_html((string) ($row['time'] ?? '')); ?>
|
||||
</div>
|
||||
<?php if (!empty($row['counterparty_user_id'])) : ?><div class="muted-2-color em09"><?php printf(esc_html__('对方用户 #%d', 'aksrt'), (int) $row['counterparty_user_id']); ?></div><?php endif; ?>
|
||||
<?php if (!empty($row['order_num'])) : ?><div class="muted-2-color em09"><?php echo esc_html__('订单号:', 'aksrt') . esc_html((string) $row['order_num']); ?></div><?php endif; ?>
|
||||
</div>
|
||||
<div class="uc-transactions__amount">
|
||||
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>">
|
||||
@@ -51,7 +53,7 @@ defined('ABSPATH') || exit;
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
$total_pages = (int) ceil((int) ($log['total'] ?? 0) / 10);
|
||||
$total_pages = (int) ceil(count($history) / 10);
|
||||
if ($total_pages > 1 && function_exists('aksrt_render_asset_pagination')) {
|
||||
aksrt_render_asset_pagination($total_pages, $credits_page, 'points');
|
||||
}
|
||||
@@ -61,7 +63,7 @@ defined('ABSPATH') || exit;
|
||||
<div class="uc-transactions__empty-icon">
|
||||
<i class="fa fas fa-file-alt" aria-hidden="true"></i>
|
||||
</div>
|
||||
<p><?php echo esc_html(sprintf(__('还没有任何%s流水', 'aksrt'), $currency_name)); ?></p>
|
||||
<p><?php echo esc_html(sprintf(__('还没有任何%s记录', 'aksrt'), $currency_name)); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
@@ -13,12 +13,9 @@ $asset_request = is_array($asset_request ?? null) ? $asset_request : [];
|
||||
$wallet_page = ($asset_request['asset'] ?? '') === 'balance'
|
||||
? max(1, (int) ($asset_request['page'] ?? 1))
|
||||
: 1;
|
||||
$wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history([
|
||||
'user_id' => (int) ($user_id ?? 0),
|
||||
'asset' => 'balance',
|
||||
'page' => $wallet_page,
|
||||
'per_page' => 10,
|
||||
]);
|
||||
$history = get_user_meta((int) ($user_id ?? 0), 'balance_record', true);
|
||||
$history = is_array($history) ? array_slice($history, 0, 50) : [];
|
||||
$items = array_slice($history, ($wallet_page - 1) * 10, 10);
|
||||
?>
|
||||
<div class="uc-transactions uc-transactions--wallet">
|
||||
<div class="uc-transactions__header">
|
||||
@@ -27,12 +24,14 @@ $wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history([
|
||||
<?php esc_html_e('余额记录', 'aksrt'); ?>
|
||||
</h3>
|
||||
</div>
|
||||
<?php if (!empty($wlog['items'])) : ?>
|
||||
<?php if ($items) : ?>
|
||||
<div class="uc-transactions__list">
|
||||
<?php foreach ($wlog['items'] as $row) :
|
||||
$delta = (int) $row['delta_minor'];
|
||||
<?php foreach ($items as $row) :
|
||||
$raw_delta = (string) ($row['value'] ?? '0');
|
||||
try { $delta_minor = \AKSRT\Ledger\AssetAmount::balance($raw_delta)->minor(); } catch (\InvalidArgumentException $e) { $delta_minor = 0; }
|
||||
$delta = $delta_minor;
|
||||
$delta_class = $delta >= 0 ? 'is-positive' : 'is-negative';
|
||||
$delta_txt = ($delta > 0 ? '+' : '-') . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
||||
$delta_txt = ($delta > 0 ? '+' : ($delta < 0 ? '-' : '')) . \AKSRT\Ledger\AssetAmount::from_minor(\AKSRT\Ledger\AssetType::BALANCE, abs($delta))->formatted();
|
||||
?>
|
||||
<div class="uc-transactions__item">
|
||||
<div class="uc-transactions__icon <?php echo esc_attr($delta_class); ?>">
|
||||
@@ -40,9 +39,10 @@ $wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history([
|
||||
</div>
|
||||
<div class="uc-transactions__info">
|
||||
<div class="uc-transactions__reason">
|
||||
<?php echo esc_html(aksrt_asset_reason_label((string) $row['reason'])); ?>
|
||||
<?php echo esc_html((string) ($row['desc'] ?? '') !== '' ? (string) $row['desc'] : aksrt_asset_reason_label((string) ($row['type'] ?? ''))); ?>
|
||||
</div>
|
||||
<div class="uc-transactions__time"><?php echo esc_html(get_date_from_gmt((string) $row['created_at'], 'Y-m-d H:i')); ?></div>
|
||||
<div class="uc-transactions__time"><?php echo esc_html((string) ($row['time'] ?? '')); ?></div>
|
||||
<?php if (!empty($row['order_num'])) : ?><div class="muted-2-color em09"><?php echo esc_html__('订单号:', 'aksrt') . esc_html((string) $row['order_num']); ?></div><?php endif; ?>
|
||||
</div>
|
||||
<div class="uc-transactions__amount">
|
||||
<span class="uc-transactions__delta <?php echo esc_attr($delta_class); ?>"><?php echo esc_html($delta_txt); ?></span>
|
||||
@@ -51,7 +51,7 @@ $wlog = \AKSRT\Ledger\LedgerQuery::get_instance()->history([
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
$total_pages = (int) ceil((int) ($wlog['total'] ?? 0) / 10);
|
||||
$total_pages = (int) ceil(count($history) / 10);
|
||||
if ($total_pages > 1 && function_exists('aksrt_render_asset_pagination')) {
|
||||
aksrt_render_asset_pagination($total_pages, $wallet_page, 'balance');
|
||||
}
|
||||
|
||||
@@ -39,7 +39,6 @@ $status_options = [
|
||||
'all' => __('全部', 'aksrt'),
|
||||
'pending' => __('待支付', 'aksrt'),
|
||||
'paid' => __('已支付', 'aksrt'),
|
||||
'refunding' => __('退款中', 'aksrt'),
|
||||
'refunded' => __('已退款', 'aksrt'),
|
||||
'closed' => __('已关闭', 'aksrt'),
|
||||
];
|
||||
@@ -58,13 +57,15 @@ $status_options = [
|
||||
<div class="aksrt-orders-page__stat"><span><?php esc_html_e('全部', 'aksrt'); ?></span><strong><?php echo esc_html((string) (int) ($stats['total'] ?? 0)); ?></strong></div>
|
||||
<div class="aksrt-orders-page__stat"><span><?php esc_html_e('待支付', 'aksrt'); ?></span><strong class="is-pending"><?php echo esc_html((string) (int) ($stats['pending'] ?? 0)); ?></strong></div>
|
||||
<div class="aksrt-orders-page__stat"><span><?php esc_html_e('已支付', 'aksrt'); ?></span><strong class="is-paid"><?php echo esc_html((string) (int) ($stats['paid'] ?? 0)); ?></strong></div>
|
||||
<div class="aksrt-orders-page__stat"><span><?php esc_html_e('已退款', 'aksrt'); ?></span><strong><?php echo esc_html((string) (int) ($stats['refunded'] ?? 0)); ?></strong></div>
|
||||
<div class="aksrt-orders-page__stat"><span><?php esc_html_e('售后待处理', 'aksrt'); ?></span><strong><?php echo esc_html((string) (int) ($stats['after_sale_pending'] ?? 0)); ?></strong></div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<form class="aksrt-orders-page__search" data-aksrt-orders-search>
|
||||
<label class="screen-reader-text" for="aksrt-order-number"><?php esc_html_e('按流水号查找', 'aksrt'); ?></label>
|
||||
<label class="screen-reader-text" for="aksrt-order-number"><?php esc_html_e('按订单号查找', 'aksrt'); ?></label>
|
||||
<i class="fa fas fa-search" aria-hidden="true"></i>
|
||||
<input id="aksrt-order-number" value="<?php echo esc_attr($order_number); ?>" maxlength="32" placeholder="<?php esc_attr_e('输入流水号开头快速查找', 'aksrt'); ?>">
|
||||
<input id="aksrt-order-number" value="<?php echo esc_attr($order_number); ?>" maxlength="22" placeholder="<?php esc_attr_e('输入订单号查找', 'aksrt'); ?>">
|
||||
<button class="btn-primary" type="submit"><?php esc_html_e('查找', 'aksrt'); ?></button>
|
||||
<button class="aksrt-orders-page__filter-toggle" type="button" data-aksrt-orders-filter-toggle aria-expanded="false" aria-controls="aksrt-orders-filter-panel"><i class="fa fas fa-sliders-h" aria-hidden="true"></i> <?php esc_html_e('筛选', 'aksrt'); ?></button>
|
||||
</form>
|
||||
@@ -112,7 +113,7 @@ $status_options = [
|
||||
<div class="aksrt-orders-page__card-rail"><span><?php echo esc_html((string) ($order['product_type_label'] ?? '')); ?></span><time><?php echo esc_html((string) ($order['created_at'] ?? '')); ?></time><span class="aksrt-orders-page__card-status is-<?php echo esc_attr((string) ($order['status_group'] ?? '')); ?>"><?php echo esc_html((string) ($order['status_label'] ?? '')); ?></span></div>
|
||||
<div class="aksrt-orders-page__card-main">
|
||||
<?php if (!empty($order['image'])) : ?><img class="aksrt-orders-page__card-img" src="<?php echo esc_url((string) $order['image']); ?>" alt=""><?php else : ?><div class="aksrt-orders-page__card-art" aria-hidden="true"><i class="fa fas fa-book"></i></div><?php endif; ?>
|
||||
<div class="aksrt-orders-page__card-copy"><h3><?php echo esc_html((string) ($order['product_name'] ?? __('订单', 'aksrt'))); ?></h3><p><?php printf(esc_html__('流水号 %s', 'aksrt'), esc_html($number)); ?></p></div>
|
||||
<div class="aksrt-orders-page__card-copy"><h3><?php echo esc_html((string) ($order['product_name'] ?? __('订单', 'aksrt'))); ?></h3><p><?php printf(esc_html__('订单号 %s', 'aksrt'), esc_html($number)); ?></p></div>
|
||||
<div class="aksrt-orders-page__card-value"><strong><?php echo $amount; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></strong><span><?php esc_html_e('实付', 'aksrt'); ?></span></div>
|
||||
</div>
|
||||
<footer class="aksrt-orders-page__card-actions">
|
||||
@@ -120,6 +121,7 @@ $status_options = [
|
||||
<button class="btn-outline" type="button" data-aksrt-order-detail="<?php echo esc_attr($number); ?>"><?php esc_html_e('订单详情', 'aksrt'); ?></button>
|
||||
<?php if (!empty($actions['can_cancel'])) : ?><button class="btn-ghost" type="button" data-aksrt-order-cancel="<?php echo esc_attr($number); ?>"><?php esc_html_e('关闭订单', 'aksrt'); ?></button><?php endif; ?>
|
||||
<?php if (!empty($actions['can_pay'])) : ?><button class="btn-primary" type="button" data-aksrt-order-pay="<?php echo esc_attr($number); ?>" data-aksrt-order-method="<?php echo esc_attr((string) ($order['payment_method']['value'] ?? '')); ?>"><?php esc_html_e('继续支付', 'aksrt'); ?></button><?php endif; ?>
|
||||
<?php if (!empty($actions['can_after_sale'])) : ?><button class="btn-outline" type="button" data-aksrt-order-detail="<?php echo esc_attr($number); ?>"><?php esc_html_e('申请售后', 'aksrt'); ?></button><?php endif; ?>
|
||||
</footer>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
|
||||
Reference in New Issue
Block a user