feat(user-center): add cash wallet balance separate from credits
Introduce AKSRT_Balance (user_meta aksrt_balance + balance_log) for Zibll-like pay_balance wallet. User center assets panel shows wallet and points; balance gateway/card-pass/refunds credit cash when enabled.
This commit is contained in:
1 parent
f043d2c1ab
commit
8e0f9d989d
16 files changed
+637
-74
No files matched your search
@@ -419,21 +419,40 @@ class AKSRT_Charge_Card {
|
||||
*/
|
||||
private function fulfill(int $user_id, string $type, array $meta, string $order_number, int $card_id) {
|
||||
if ($type === self::TYPE_BALANCE) {
|
||||
$amount = (int) round((float) ($meta['amount'] ?? 0));
|
||||
if ($amount <= 0 || !class_exists('AKSRT_Credits')) {
|
||||
$amount = round((float) ($meta['amount'] ?? 0), 2);
|
||||
if ($amount <= 0) {
|
||||
return new WP_Error('aksrt_card_amount', __('当前卡密可充值金额为0', 'aksrt'), ['status' => 400]);
|
||||
}
|
||||
$new = AKSRT_Credits::add($user_id, $amount, 'card_pass_balance', [
|
||||
// Cash wallet first (Zibll pay_balance); fall back to points if wallet class missing.
|
||||
if (class_exists('AKSRT_Balance')) {
|
||||
$new = AKSRT_Balance::add($user_id, $amount, 'card_pass_balance', [
|
||||
'type' => 'charge_card',
|
||||
'id' => $card_id,
|
||||
'order' => $order_number,
|
||||
], sprintf(__('卡密充值 %s 元', 'aksrt'), (string) $amount));
|
||||
if (is_wp_error($new)) {
|
||||
return new WP_Error('aksrt_balance_fail', $new->get_error_message() ?: __('余额入账失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
return [
|
||||
'message' => sprintf(__('卡密充值成功,充值金额:%s 元', 'aksrt'), (string) $amount),
|
||||
'amount' => (float) $amount,
|
||||
];
|
||||
}
|
||||
if (!class_exists('AKSRT_Credits')) {
|
||||
return new WP_Error('aksrt_card_amount', __('余额系统不可用', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
$pts = (int) round($amount);
|
||||
$new = AKSRT_Credits::add($user_id, $pts, 'card_pass_balance', [
|
||||
'ref_type' => 'charge_card',
|
||||
'ref_id' => $card_id,
|
||||
'order' => $order_number,
|
||||
], sprintf(__('卡密充值 %d', 'aksrt'), $amount));
|
||||
if ($new === null || $new === false) {
|
||||
], sprintf(__('卡密充值 %d', 'aksrt'), $pts));
|
||||
if ($new === null || $new === false || is_wp_error($new)) {
|
||||
return new WP_Error('aksrt_credit_fail', __('余额入账失败', 'aksrt'), ['status' => 500]);
|
||||
}
|
||||
return [
|
||||
'message' => sprintf(__('卡密充值成功,充值金额:%s', 'aksrt'), (string) $amount),
|
||||
'amount' => (float) $amount,
|
||||
'message' => sprintf(__('卡密充值成功,充值金额:%s', 'aksrt'), (string) $pts),
|
||||
'amount' => (float) $pts,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user