feat(pay): content cashier coupon and rebate discount chain

Wire zibll-style cash content discounts: VIP list price → buyer 推广折扣 → coupon, then commission on final pay. Reuse AKSRT_Coupon, add Invite::get_referrer, cashier UI, and paid-time coupon burn + rebate_log.
This commit is contained in:
kate522 committed 2026-07-14 19:38:05 +08:00
1 parent 9eaddce457
commit 5d7b138c2c
11 files changed
+724 -22

No files matched your search

+68
View File
@@ -491,6 +491,74 @@ if (!function_exists('aksrt_get_user_pay_price')) {
}
}
/**
* Whether content cashier may accept coupons for this post (zibll coupon_post_s || coupon_s).
*/
if (!function_exists('aksrt_is_content_coupon_allowed')) {
function aksrt_is_content_coupon_allowed($post = null): bool {
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
if (!empty($meta['coupon_s'])) {
return true;
}
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_content_coupon_settings')) {
$cfg = AKSRT_Settings::get_content_coupon_settings();
return !empty($cfg['enabled']);
}
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_paid_content_settings')) {
$paid = AKSRT_Settings::get_paid_content_settings();
return !empty($paid['coupon_post_s']);
}
return false;
}
}
/**
* Buyer-facing 推广折扣 amount for a post (0 if no eligible referrer).
* Cash only; mirrors zibpay_get_post_rebate_discount.
*/
if (!function_exists('aksrt_get_post_rebate_discount')) {
function aksrt_get_post_rebate_discount($post = null, int $user_id = 0): float {
$meta = function_exists('aksrt_get_pay_meta') ? aksrt_get_pay_meta($post) : [];
$fixed = max(0.0, (float) ($meta['pay_rebate_discount'] ?? 0));
if ($fixed <= 0) {
return 0.0;
}
if (!class_exists('AKSRT_Settings') || !method_exists('AKSRT_Settings', 'get_payment_affiliate_settings')) {
return 0.0;
}
$aff = AKSRT_Settings::get_payment_affiliate_settings();
if (empty($aff['enabled'])) {
return 0.0;
}
$uid = $user_id > 0 ? $user_id : (function_exists('get_current_user_id') ? (int) get_current_user_id() : 0);
$referrer_id = 0;
if (class_exists('AKSRT_Invite') && method_exists(AKSRT_Invite::get_instance(), 'get_referrer')) {
$referrer_id = (int) AKSRT_Invite::get_instance()->get_referrer($uid);
}
if ($referrer_id <= 0) {
return 0.0;
}
// Need a positive ratio for referrer (VIP tier of referrer preferred).
$ratio = (int) ($aff['ratio'] ?? 0);
$user_ratio = is_array($aff['user_ratio'] ?? null) ? $aff['user_ratio'] : [];
$ref_vip = 0;
if (function_exists('aksrt_get_user_vip_level')) {
$ref_vip = (int) aksrt_get_user_vip_level($referrer_id);
}
if ($ref_vip >= 2 && !empty($user_ratio['vip2'])) {
$ratio = (int) $user_ratio['vip2'];
} elseif ($ref_vip >= 1 && !empty($user_ratio['vip1'])) {
$ratio = (int) $user_ratio['vip1'];
} elseif (isset($user_ratio['user'])) {
$ratio = (int) $user_ratio['user'];
}
if ($ratio <= 0) {
return 0.0;
}
return round($fixed, 2);
}
}
// ============================================================
// 状态判断
// ============================================================