积分与余额账务系统硬切重构

This commit is contained in:
kate522 committed 2026-08-24 15:59:11 +08:00
1 parent ca12226b39
commit 5cae5b5c93
159 files changed
+7275 -4718

No files matched your search

+10 -11
View File
@@ -48,27 +48,26 @@ if (!function_exists('aksrt_burn_order_coupon')) {
$coupon = is_array($meta['coupon'] ?? null) ? $meta['coupon'] : [];
$coupon_code = sanitize_text_field((string) ($coupon['code'] ?? $meta['coupon_code'] ?? ''));
$coupon_discount = (float) ($meta['coupon_discount'] ?? $meta['discount'] ?? ($coupon['discount'] ?? 0));
$coupon_discount = (string) ($meta['coupon_discount'] ?? $meta['discount'] ?? ($coupon['discount'] ?? '0.00'));
if ($coupon_code === '') {
return false;
}
try {
$coupon_discount = \AKSRT\Ledger\AssetAmount::balance($coupon_discount)->decimal();
} catch (\InvalidArgumentException $e) {
return false;
}
$coupon_api = \AKSRT\Payment\Coupon::get_instance();
$coupon_api->use_coupon($coupon_code);
// Prefer snapshot id: post-increment validate may fail on usage_limit edge.
$coupon_id = (int) ($coupon['id'] ?? 0);
if ($coupon_id <= 0) {
$validated = $coupon_api->validate($coupon_code, max(0.01, $coupon_discount), [
'user_id' => max(0, $buyer_id),
]);
$coupon_id = (int) ($validated['coupon']['id'] ?? 0);
return false;
}
if ($coupon_id > 0) {
$coupon_api->log_usage($coupon_id, max(0, $buyer_id), $order_number, max(0.0, $coupon_discount));
if (!$coupon_api->log_usage($coupon_id, max(0, $buyer_id), $order_number, $coupon_discount)) {
return aksrt_coupon_usage_exists($order_number);
}
return true;
return $coupon_api->use_coupon($coupon_code);
}
}