积分与余额账务系统硬切重构
This commit is contained in:
1 parent
ca12226b39
commit
5cae5b5c93
159 files changed
+7275
-4718
No files matched your search
@@ -1,76 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* AKSRT Credits Helper
|
||||
*
|
||||
* 模板层使用的顶层辅助函数:
|
||||
* aksrt_user_credits($user_id = 0) 读取余额
|
||||
* aksrt_format_credits(int $n) 格式化展示
|
||||
* aksrt_credits_label(string $reason) 流水原因 → 友好文案
|
||||
* Unified asset presentation helpers.
|
||||
*
|
||||
* @package AKSRT
|
||||
*/
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
if (!function_exists('aksrt_user_credits')) {
|
||||
/**
|
||||
* 取用户当前积分余额。
|
||||
*
|
||||
* @param int $user_id 0 表示当前登录用户
|
||||
* @return int
|
||||
*/
|
||||
function aksrt_user_credits(int $user_id = 0): int {
|
||||
if ($user_id <= 0) $user_id = get_current_user_id();
|
||||
if ($user_id <= 0) return 0;
|
||||
if (!class_exists('\AKSRT\Credits\Credits')) return 0;
|
||||
return \AKSRT\Credits\Credits::balance($user_id);
|
||||
}
|
||||
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)
|
||||
: 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_format_credits')) {
|
||||
function aksrt_format_credits(int $n): string {
|
||||
return number_format_i18n($n);
|
||||
}
|
||||
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)
|
||||
: '0.00';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_credits_label')) {
|
||||
/**
|
||||
* 把 reason 字段翻译成展示文案。
|
||||
*/
|
||||
function aksrt_credits_label(string $reason): string {
|
||||
$map = [
|
||||
'register' => __('注册赠送', 'aksrt'),
|
||||
'signin' => __('每日签到', 'aksrt'),
|
||||
'comment' => __('发表评论', 'aksrt'),
|
||||
'referral' => __('推广注册奖励', 'aksrt'),
|
||||
'referral_new_user' => __('推广注册新用户奖励', 'aksrt'),
|
||||
'download' => __('下载消费', 'aksrt'),
|
||||
'admin' => __('管理员调整', 'aksrt'),
|
||||
'refund' => __('退款', 'aksrt'),
|
||||
'free_sign_up' => __('注册奖励', 'aksrt'),
|
||||
'free_sign_in' => __('每日签到', 'aksrt'),
|
||||
'free_login' => __('每日登录', 'aksrt'),
|
||||
'free_followed'=> __('被关注', 'aksrt'),
|
||||
'free_post_new'=> __('发布文章', 'aksrt'),
|
||||
'free_post_like'=> __('文章被赞', 'aksrt'),
|
||||
'free_post_favorite'=> __('文章被收藏', 'aksrt'),
|
||||
'free_comment_new'=> __('发表评论', 'aksrt'),
|
||||
'free_comment_like'=> __('评论被赞', 'aksrt'),
|
||||
'points_exchange_in' => __('余额兑换积分', 'aksrt'),
|
||||
'transfer_in' => __('积分转入', 'aksrt'),
|
||||
'transfer_out' => __('积分转出', 'aksrt'),
|
||||
'transfer_refund' => __('积分转账退款', 'aksrt'),
|
||||
];
|
||||
if (isset($map[$reason])) {
|
||||
return $map[$reason];
|
||||
}
|
||||
if (str_starts_with($reason, 'free_') && class_exists('\AKSRT\Credits\PointsFree')) {
|
||||
$key = substr($reason, 5);
|
||||
$cat = \AKSRT\Credits\PointsFree::catalog();
|
||||
if (isset($cat[$key][0])) {
|
||||
return (string) $cat[$key][0];
|
||||
}
|
||||
}
|
||||
return $reason;
|
||||
}
|
||||
if (!function_exists('aksrt_format_points')) {
|
||||
function aksrt_format_points(int $points): string {
|
||||
return number_format_i18n($points);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('aksrt_asset_reason_label')) {
|
||||
function aksrt_asset_reason_label(string $reason): string {
|
||||
return \AKSRT\Ledger\LedgerPresentation::reason_label($reason);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user