积分与余额账务系统硬切重构
This commit is contained in:
+133
-93
@@ -31,34 +31,35 @@ trait PayHelpers {
|
||||
$uid = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
$priced = function_exists('aksrt_get_user_pay_price')
|
||||
? aksrt_get_user_pay_price($post, $uid)
|
||||
: ['amount' => 0.0, 'base' => 0.0, 'modo' => '0', 'currency' => '¥', 'is_free' => true, 'pay_limit' => 0, 'vip_level' => 0, 'original' => 0.0, 'vip1' => 0.0, 'vip2' => 0.0];
|
||||
: ['amount' => '0.00', 'base' => '0.00', 'modo' => '0', 'currency' => '¥', 'is_free' => true, 'pay_limit' => 0, 'vip_level' => 0, 'original' => '0.00', 'vip1' => '0.00', 'vip2' => '0.00'];
|
||||
|
||||
$pay_modo = (($priced['modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
|
||||
// Optional overbuy override for preview display.
|
||||
if ($price_type === 'download_limit_over') {
|
||||
$over = max(0.0, (float) ($meta['download_limit_over_price'] ?? 0));
|
||||
if ($over > 0) {
|
||||
$priced['amount'] = $over;
|
||||
$priced['base'] = $over;
|
||||
$over_minor = $this->parse_asset_minor($meta['download_limit_over_price'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo);
|
||||
if ($over_minor > 0) {
|
||||
$priced['amount'] = $this->asset_value($over_minor, $pay_modo);
|
||||
$priced['base'] = $this->asset_value($over_minor, $pay_modo);
|
||||
$priced['is_free'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$pay_modo = (($priced['modo'] ?? '0') === 'points') ? 'points' : '0';
|
||||
$pay_limit = (int) ($priced['pay_limit'] ?? 0);
|
||||
$vip_level = (int) ($priced['vip_level'] ?? 0);
|
||||
$amount = (float) ($priced['amount'] ?? 0);
|
||||
$base = (float) ($priced['base'] ?? $amount);
|
||||
$over_price = max(0.0, (float) ($meta['download_limit_over_price'] ?? 0));
|
||||
$amount_minor = $this->parse_asset_minor($priced['amount'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo);
|
||||
$base_minor = $this->parse_asset_minor($priced['base'] ?? $priced['amount'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo);
|
||||
$over_minor = $this->parse_asset_minor($meta['download_limit_over_price'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo);
|
||||
|
||||
$list_amount = $amount;
|
||||
$rebate_discount = 0.0;
|
||||
$coupon_discount = 0.0;
|
||||
$list_minor = $amount_minor;
|
||||
$rebate_discount_minor = 0;
|
||||
$coupon_discount_minor = 0;
|
||||
$coupon_payload = null;
|
||||
$coupon_error = '';
|
||||
$referrer_active = false;
|
||||
$referrer_id = 0;
|
||||
$rebate_price = 0.0;
|
||||
$payable = $amount;
|
||||
$rebate_price_minor = 0;
|
||||
$payable_minor = $amount_minor;
|
||||
|
||||
$coupon_allowed = $pay_modo !== 'points' && $this->is_coupon_allowed($post_id, $meta);
|
||||
$coupon_desc = '';
|
||||
@@ -77,15 +78,15 @@ trait PayHelpers {
|
||||
$discounted = $this->apply_cash_discounts($priced, $post, $meta, $uid, '', true);
|
||||
}
|
||||
if (!is_wp_error($discounted)) {
|
||||
$list_amount = (float) ($discounted['list_amount'] ?? $amount);
|
||||
$rebate_discount = (float) ($discounted['rebate_discount'] ?? 0);
|
||||
$coupon_discount = (float) ($discounted['coupon_discount'] ?? 0);
|
||||
$list_minor = (int) ($discounted['list_minor'] ?? $amount_minor);
|
||||
$rebate_discount_minor = (int) ($discounted['rebate_discount_minor'] ?? 0);
|
||||
$coupon_discount_minor = (int) ($discounted['coupon_discount_minor'] ?? 0);
|
||||
$coupon_payload = $discounted['coupon'] ?? null;
|
||||
$payable = (float) ($discounted['payable'] ?? $amount);
|
||||
$payable_minor = (int) ($discounted['payable_minor'] ?? $amount_minor);
|
||||
$referrer_id = (int) ($discounted['referrer_id'] ?? 0);
|
||||
$referrer_active = $referrer_id > 0;
|
||||
$rebate_price = (float) ($discounted['rebate_price'] ?? 0);
|
||||
$amount = $payable;
|
||||
$rebate_price_minor = (int) ($discounted['rebate_price_minor'] ?? 0);
|
||||
$amount_minor = $payable_minor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,19 +122,16 @@ trait PayHelpers {
|
||||
: '¥'));
|
||||
|
||||
// Points cashier uses Credits; cash cashier uses wallet (元). Keep both for UI.
|
||||
$points_balance = ($uid > 0 && class_exists('\AKSRT\Credits\Credits'))
|
||||
? (int) \AKSRT\Credits\Credits::balance($uid)
|
||||
: 0;
|
||||
$wallet_balance = ($uid > 0 && class_exists('\AKSRT\Credits\Balance') && \AKSRT\Credits\Balance::enabled())
|
||||
? (float) \AKSRT\Credits\Balance::balance($uid)
|
||||
: 0.0;
|
||||
$points_balance = $uid > 0 ? \AKSRT\Ledger\LedgerService::get_instance()->balance($uid, \AKSRT\Ledger\AssetType::POINTS) : 0;
|
||||
$wallet_minor = $uid > 0 ? \AKSRT\Ledger\LedgerService::get_instance()->balance($uid, \AKSRT\Ledger\AssetType::BALANCE) : 0;
|
||||
$wallet_balance = \AKSRT\Ledger\AssetAmount::decimal_from_minor($wallet_minor);
|
||||
$balance = $pay_modo === 'points' ? $points_balance : $wallet_balance;
|
||||
$methods = $this->available_payment_methods($pay_modo, $uid > 0);
|
||||
|
||||
$amount_label = $this->format_amount_label($amount, $pay_modo, $currency);
|
||||
$base_label = $this->format_amount_label($base, $pay_modo, $currency);
|
||||
$list_label = $this->format_amount_label($list_amount, $pay_modo, $currency);
|
||||
$over_label = $over_price > 0 ? $this->format_amount_label($over_price, $pay_modo, $currency) : '';
|
||||
$amount_label = $this->format_amount_label($amount_minor, $pay_modo, $currency);
|
||||
$base_label = $this->format_amount_label($base_minor, $pay_modo, $currency);
|
||||
$list_label = $this->format_amount_label($list_minor, $pay_modo, $currency);
|
||||
$over_label = $over_minor > 0 ? $this->format_amount_label($over_minor, $pay_modo, $currency) : '';
|
||||
|
||||
$vip_page = function_exists('aksrt_get_user_center_tab_url')
|
||||
? aksrt_get_user_center_tab_url('credits')
|
||||
@@ -147,10 +145,10 @@ trait PayHelpers {
|
||||
? aksrt_get_user_free_downloaded_number($uid) : 0;
|
||||
$quota_over = $free_limit > 0 && $free_used >= $free_limit;
|
||||
|
||||
$payable_amount = $pay_modo === 'points' ? (int) ceil($payable) : round($payable, 2);
|
||||
$payable_amount = $this->asset_value($payable_minor, $pay_modo);
|
||||
$balance_enough = $pay_modo === 'points'
|
||||
? ($points_balance >= (int) ceil($amount))
|
||||
: ($wallet_balance + 0.0001 >= (float) $payable_amount);
|
||||
? ($points_balance >= $payable_minor)
|
||||
: ($wallet_minor >= $payable_minor);
|
||||
|
||||
return [
|
||||
'post_id' => $post_id,
|
||||
@@ -161,36 +159,38 @@ trait PayHelpers {
|
||||
'pay_modo' => $pay_modo,
|
||||
'pay_limit' => $pay_limit,
|
||||
'vip_level' => $vip_level,
|
||||
'amount' => $pay_modo === 'points' ? (int) ceil($amount) : round($amount, 2),
|
||||
'base' => $pay_modo === 'points' ? (int) ceil($base) : round($base, 2),
|
||||
'list_amount' => $pay_modo === 'points' ? (int) ceil($list_amount) : round($list_amount, 2),
|
||||
'amount' => $this->asset_value($amount_minor, $pay_modo),
|
||||
'base' => $this->asset_value($base_minor, $pay_modo),
|
||||
'list_amount' => $this->asset_value($list_minor, $pay_modo),
|
||||
'list_amount_label' => $list_label,
|
||||
'payable' => $payable_amount,
|
||||
'original' => (float) ($priced['original'] ?? 0),
|
||||
'vip1' => (float) ($priced['vip1'] ?? 0),
|
||||
'vip2' => (float) ($priced['vip2'] ?? 0),
|
||||
'original' => $this->asset_value($this->parse_asset_minor($priced['original'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo), $pay_modo),
|
||||
'vip1' => $this->asset_value($this->parse_asset_minor($priced['vip1'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo), $pay_modo),
|
||||
'vip2' => $this->asset_value($this->parse_asset_minor($priced['vip2'] ?? ($pay_modo === 'points' ? 0 : '0'), $pay_modo), $pay_modo),
|
||||
'currency' => $currency,
|
||||
'amount_label' => $amount_label,
|
||||
'base_label' => $base_label,
|
||||
'is_free' => !empty($priced['is_free']) || $amount <= 0,
|
||||
'is_free' => !empty($priced['is_free']) || $amount_minor <= 0,
|
||||
'has_paid_access' => $has_paid,
|
||||
'paid_order' => $paid_order ? [
|
||||
'order_number' => (string) ($paid_order['order_number'] ?? ''),
|
||||
'paid_at' => (string) ($paid_order['paid_at'] ?? $paid_order['created_at'] ?? ''),
|
||||
'amount' => (float) ($paid_order['amount'] ?? 0),
|
||||
'amount' => (string) ($paid_order['currency'] ?? '') === 'points'
|
||||
? (int) ($paid_order['amount'] ?? 0)
|
||||
: (string) ($paid_order['amount'] ?? '0.00'),
|
||||
'currency' => (string) ($paid_order['currency'] ?? ''),
|
||||
'payment_method' => (string) ($paid_order['payment_method'] ?? ''),
|
||||
] : null,
|
||||
'pending_order' => $pending_order ? [
|
||||
'order_number' => (string) ($pending_order['order_number'] ?? ''),
|
||||
'amount' => (float) ($pending_order['amount'] ?? 0),
|
||||
'amount' => (string) ($pending_order['amount'] ?? '0.00'),
|
||||
'payment_method' => (string) ($pending_order['payment_method'] ?? ''),
|
||||
'created_at' => (string) ($pending_order['created_at'] ?? ''),
|
||||
] : null,
|
||||
'need_login' => $uid <= 0 && !$allow_guest,
|
||||
'allow_guest' => $allow_guest,
|
||||
'need_vip' => $need_vip,
|
||||
'need_purchase' => !$has_paid && !$need_vip && $amount > 0,
|
||||
'need_purchase' => !$has_paid && !$need_vip && $amount_minor > 0,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $balance,
|
||||
'wallet_balance' => $wallet_balance,
|
||||
@@ -200,9 +200,9 @@ trait PayHelpers {
|
||||
'login_url' => wp_login_url(get_permalink($post)),
|
||||
'vip_url' => $vip_page,
|
||||
'credits_url' => $vip_page,
|
||||
'download_limit_over_price' => $pay_modo === 'points' ? (int) ceil($over_price) : round($over_price, 2),
|
||||
'download_limit_over_price' => $this->asset_value($over_minor, $pay_modo),
|
||||
'download_limit_over_label' => $over_label,
|
||||
'allow_limit_over' => $over_price > 0,
|
||||
'allow_limit_over' => $over_minor > 0,
|
||||
'quota_over' => $quota_over,
|
||||
'free_limit' => $free_limit,
|
||||
'free_used' => $free_used,
|
||||
@@ -211,18 +211,18 @@ trait PayHelpers {
|
||||
'coupon_code' => $coupon_code,
|
||||
'coupon' => $coupon_payload,
|
||||
'coupon_error' => $coupon_error,
|
||||
'rebate_discount' => round($rebate_discount, 2),
|
||||
'rebate_discount_label' => $rebate_discount > 0 ? ('-' . $this->format_amount_label($rebate_discount, $pay_modo, $currency)) : '',
|
||||
'coupon_discount' => round($coupon_discount, 2),
|
||||
'coupon_discount_label' => $coupon_discount > 0 ? ('-' . $this->format_amount_label($coupon_discount, $pay_modo, $currency)) : '',
|
||||
'rebate_discount' => $this->asset_value($rebate_discount_minor, $pay_modo),
|
||||
'rebate_discount_label' => $rebate_discount_minor > 0 ? ('-' . $this->format_amount_label($rebate_discount_minor, $pay_modo, $currency)) : '',
|
||||
'coupon_discount' => $this->asset_value($coupon_discount_minor, $pay_modo),
|
||||
'coupon_discount_label' => $coupon_discount_minor > 0 ? ('-' . $this->format_amount_label($coupon_discount_minor, $pay_modo, $currency)) : '',
|
||||
'referrer_active' => $referrer_active,
|
||||
'discounts' => [
|
||||
'list_amount' => round($list_amount, 2),
|
||||
'rebate_discount' => round($rebate_discount, 2),
|
||||
'coupon_discount' => round($coupon_discount, 2),
|
||||
'total_discount' => round(max(0, $list_amount - $payable), 2),
|
||||
'payable' => round($payable, 2),
|
||||
'rebate_price' => round($rebate_price, 2),
|
||||
'list_amount' => $this->asset_value($list_minor, $pay_modo),
|
||||
'rebate_discount' => $this->asset_value($rebate_discount_minor, $pay_modo),
|
||||
'coupon_discount' => $this->asset_value($coupon_discount_minor, $pay_modo),
|
||||
'total_discount' => $this->asset_value(max(0, $list_minor - $payable_minor), $pay_modo),
|
||||
'payable' => $this->asset_value($payable_minor, $pay_modo),
|
||||
'rebate_price' => $this->asset_value($rebate_price_minor, $pay_modo),
|
||||
],
|
||||
// legacy: points_deduction runtime hard-off; card_pass not a content payment method.
|
||||
'points_deduction_allowed' => function_exists('aksrt_is_allow_points_deduction')
|
||||
@@ -269,18 +269,18 @@ trait PayHelpers {
|
||||
|
||||
$priced = function_exists('aksrt_get_user_pay_price')
|
||||
? aksrt_get_user_pay_price($post, $user_id)
|
||||
: ['amount' => 0.0, 'modo' => '0', 'pay_limit' => 0, 'vip_level' => 0, 'is_free' => true, 'base' => 0.0];
|
||||
: ['amount' => '0.00', 'modo' => '0', 'pay_limit' => 0, 'vip_level' => 0, 'is_free' => true, 'base' => '0.00'];
|
||||
|
||||
// Free daily quota overbuy: override amount, ignore VIP discount (legacy).
|
||||
if ($price_type === 'download_limit_over') {
|
||||
$over = max(0.0, (float) ($meta['download_limit_over_price'] ?? 0));
|
||||
if ($over <= 0) {
|
||||
$over_minor = $this->parse_asset_minor($meta['download_limit_over_price'] ?? ($pay_modo_meta === 'points' ? 0 : '0'), $pay_modo_meta);
|
||||
if ($over_minor <= 0) {
|
||||
return new \WP_Error('aksrt_no_overbuy', __('未开放超额下载购买。', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$priced['amount'] = $over;
|
||||
$priced['base'] = $over;
|
||||
$priced['amount'] = $this->asset_value($over_minor, $pay_modo_meta);
|
||||
$priced['base'] = $this->asset_value($over_minor, $pay_modo_meta);
|
||||
$priced['is_free'] = false;
|
||||
$priced['vip_amount'] = -1.0;
|
||||
$priced['vip_amount'] = null;
|
||||
}
|
||||
|
||||
$pay_limit = (int) ($priced['pay_limit'] ?? 0);
|
||||
@@ -365,10 +365,10 @@ trait PayHelpers {
|
||||
|
||||
|
||||
/**
|
||||
* @return array{id:int,ratio:float}
|
||||
* @return array{id:int,ratio:int}
|
||||
*/
|
||||
private function resolve_referrer_context(int $user_id): array {
|
||||
$empty = ['id' => 0, 'ratio' => 0.0];
|
||||
$empty = ['id' => 0, 'ratio' => 0];
|
||||
if (!class_exists('\AKSRT\Settings\Settings') || !method_exists('\AKSRT\Settings\Settings', 'get_payment_affiliate_settings')) {
|
||||
return $empty;
|
||||
}
|
||||
@@ -383,7 +383,7 @@ trait PayHelpers {
|
||||
return $empty;
|
||||
}
|
||||
|
||||
$ratio = (float) \AKSRT\Settings\Settings::affiliate_ratio_for_user($referrer_id);
|
||||
$ratio = (int) \AKSRT\Settings\Settings::affiliate_ratio_for_user($referrer_id);
|
||||
if ($ratio <= 0) {
|
||||
return $empty;
|
||||
}
|
||||
@@ -400,21 +400,21 @@ trait PayHelpers {
|
||||
* @return array|\WP_Error
|
||||
*/
|
||||
private function apply_cash_discounts(array $priced, \WP_Post $post, array $meta, int $user_id, string $coupon_code = '', bool $soft_coupon = false) {
|
||||
$list_amount = round(max(0.0, (float) ($priced['amount'] ?? 0)), 2);
|
||||
$pay = $list_amount;
|
||||
$rebate_discount = 0.0;
|
||||
$coupon_discount = 0.0;
|
||||
$list_minor = $this->parse_asset_minor($priced['amount'] ?? '0', '0');
|
||||
$pay_minor = $list_minor;
|
||||
$rebate_discount_minor = 0;
|
||||
$coupon_discount_minor = 0;
|
||||
$coupon_meta = [];
|
||||
|
||||
$ref = $this->resolve_referrer_context($user_id);
|
||||
$referrer_id = (int) ($ref['id'] ?? 0);
|
||||
$ratio = (float) ($ref['ratio'] ?? 0);
|
||||
$ratio = max(0, min(100, (int) ($ref['ratio'] ?? 0)));
|
||||
|
||||
// 1) Buyer-facing 推广折扣 (fixed).
|
||||
$fixed = max(0.0, (float) ($meta['pay_rebate_discount'] ?? 0));
|
||||
if ($referrer_id > 0 && $ratio > 0 && $fixed > 0 && $pay > 0) {
|
||||
$rebate_discount = round(min($pay, $fixed), 2);
|
||||
$pay = round(max(0.0, $pay - $rebate_discount), 2);
|
||||
$fixed_minor = $this->parse_asset_minor($meta['pay_rebate_discount'] ?? '0', '0');
|
||||
if ($referrer_id > 0 && $ratio > 0 && $fixed_minor > 0 && $pay_minor > 0) {
|
||||
$rebate_discount_minor = min($pay_minor, $fixed_minor);
|
||||
$pay_minor -= $rebate_discount_minor;
|
||||
}
|
||||
|
||||
// 2) Coupon after rebate discount.
|
||||
@@ -431,11 +431,15 @@ trait PayHelpers {
|
||||
return $err;
|
||||
}
|
||||
} else {
|
||||
$result = \AKSRT\Payment\Coupon::get_instance()->validate($coupon_code, $pay, [
|
||||
$result = \AKSRT\Payment\Coupon::get_instance()->validate(
|
||||
$coupon_code,
|
||||
\AKSRT\Ledger\AssetAmount::decimal_from_minor($pay_minor),
|
||||
[
|
||||
'user_id' => max(0, $user_id),
|
||||
'product_ids' => [(int) $post->ID],
|
||||
'context' => 'content',
|
||||
]);
|
||||
]
|
||||
);
|
||||
if (empty($result['valid'])) {
|
||||
$err = new \WP_Error(
|
||||
'aksrt_coupon_error',
|
||||
@@ -446,47 +450,50 @@ trait PayHelpers {
|
||||
return $err;
|
||||
}
|
||||
} else {
|
||||
$coupon_discount = round(max(0.0, (float) ($result['discount'] ?? 0)), 2);
|
||||
if ($coupon_discount > $pay) {
|
||||
$coupon_discount = $pay;
|
||||
}
|
||||
$pay = round(max(0.0, $pay - $coupon_discount), 2);
|
||||
$coupon_discount_minor = min($pay_minor, max(0, (int) ($result['discount_minor'] ?? 0)));
|
||||
$pay_minor -= $coupon_discount_minor;
|
||||
$c = is_array($result['coupon'] ?? null) ? $result['coupon'] : [];
|
||||
$coupon_meta = [
|
||||
'id' => (int) ($c['id'] ?? 0),
|
||||
'code' => (string) ($c['code'] ?? $coupon_code),
|
||||
'type' => (string) ($c['type'] ?? ''),
|
||||
'value' => (float) ($c['value'] ?? 0),
|
||||
'discount' => $coupon_discount,
|
||||
'value' => $c['value'] ?? 0,
|
||||
'discount' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($coupon_discount_minor),
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$payable = round(max(0.0, $pay), 2);
|
||||
$rebate_price = 0.0;
|
||||
if ($referrer_id > 0 && $ratio > 0 && $payable > 0) {
|
||||
$rebate_price = round($payable * $ratio / 100, 2);
|
||||
$payable_minor = max(0, $pay_minor);
|
||||
$rebate_price_minor = 0;
|
||||
if ($referrer_id > 0 && $ratio > 0 && $payable_minor > 0) {
|
||||
$rebate_price_minor = \AKSRT\Ledger\AssetAmount::percentage($payable_minor, $ratio);
|
||||
}
|
||||
|
||||
return [
|
||||
'list_amount' => $list_amount,
|
||||
'rebate_discount' => $rebate_discount,
|
||||
'coupon_discount' => $coupon_discount,
|
||||
'list_amount' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($list_minor),
|
||||
'list_minor' => $list_minor,
|
||||
'rebate_discount' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($rebate_discount_minor),
|
||||
'rebate_discount_minor' => $rebate_discount_minor,
|
||||
'coupon_discount' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($coupon_discount_minor),
|
||||
'coupon_discount_minor' => $coupon_discount_minor,
|
||||
'coupon' => $coupon_meta,
|
||||
'payable' => $payable,
|
||||
'payable' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($payable_minor),
|
||||
'payable_minor' => $payable_minor,
|
||||
'referrer_id' => $referrer_id,
|
||||
'rebate_price' => $rebate_price,
|
||||
'rebate_price' => \AKSRT\Ledger\AssetAmount::decimal_from_minor($rebate_price_minor),
|
||||
'rebate_price_minor' => $rebate_price_minor,
|
||||
'ratio' => $ratio,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function format_amount_label(float $amount, string $pay_modo, string $currency): string {
|
||||
if ($amount <= 0) {
|
||||
private function format_amount_label(int $minor, string $pay_modo, string $currency): string {
|
||||
if ($minor <= 0) {
|
||||
return (string) __('免费', 'aksrt');
|
||||
}
|
||||
$amount = $this->asset_value($minor, $pay_modo);
|
||||
$n = function_exists('aksrt_format_price') ? aksrt_format_price($amount) : (string) $amount;
|
||||
if ($pay_modo === 'points') {
|
||||
return $n . ' ' . $currency;
|
||||
@@ -494,4 +501,37 @@ trait PayHelpers {
|
||||
return $currency . $n;
|
||||
}
|
||||
|
||||
private function parse_asset_minor($value, string $pay_modo): int {
|
||||
if ($pay_modo === 'points') {
|
||||
if (is_int($value)) {
|
||||
return max(0, $value);
|
||||
}
|
||||
if (!is_string($value) || !preg_match('/^(0|[1-9]\d*)$/', trim($value))) {
|
||||
return 0;
|
||||
}
|
||||
$value = trim($value);
|
||||
if (strlen($value) > strlen((string) PHP_INT_MAX)
|
||||
|| (strlen($value) === strlen((string) PHP_INT_MAX) && strcmp($value, (string) PHP_INT_MAX) > 0)
|
||||
) {
|
||||
return 0;
|
||||
}
|
||||
return \AKSRT\Ledger\AssetAmount::points((int) $value)->minor();
|
||||
}
|
||||
|
||||
if (!is_string($value)) {
|
||||
return 0;
|
||||
}
|
||||
try {
|
||||
return \AKSRT\Ledger\AssetAmount::balance_minor($value);
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private function asset_value(int $minor, string $pay_modo) {
|
||||
return $pay_modo === 'points'
|
||||
? $minor
|
||||
: \AKSRT\Ledger\AssetAmount::decimal_from_minor($minor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user