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:
1 parent
9eaddce457
commit
5d7b138c2c
11 files changed
+724
-22
No files matched your search
@@ -293,6 +293,57 @@ class AKSRT_Invite {
|
||||
* 公开 API:根据邀请码反查邀请人 user_id(不存在返回 0)。
|
||||
* 给注册流程在 wp_create_user 之前做"邀请码是否合法"的预校验用。
|
||||
*/
|
||||
/**
|
||||
* Resolve affiliate / invite referrer for a buyer (zibll-style).
|
||||
*
|
||||
* Priority:
|
||||
* 1. Logged-in: inviter_id from aksrt_invite table for this invitee
|
||||
* 2. Cookie invite code → resolve_code
|
||||
*
|
||||
* Respects pay_rebate_self_s when available (via affiliate settings).
|
||||
*/
|
||||
public function get_referrer(int $user_id = 0): int {
|
||||
$uid = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
$referrer_id = 0;
|
||||
|
||||
if ($uid > 0) {
|
||||
global $wpdb;
|
||||
$table = AKSRT_DB_Migrator::table('invite');
|
||||
if ($table) {
|
||||
$referrer_id = (int) $wpdb->get_var($wpdb->prepare(
|
||||
"SELECT inviter_id FROM {$table} WHERE invitee_id = %d AND inviter_id > 0 ORDER BY id DESC LIMIT 1",
|
||||
$uid
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
if ($referrer_id <= 0) {
|
||||
$code = '';
|
||||
if (!empty($_COOKIE[self::COOKIE_NAME])) {
|
||||
$code = sanitize_key((string) $_COOKIE[self::COOKIE_NAME]);
|
||||
}
|
||||
if ($code !== '') {
|
||||
$referrer_id = $this->resolve_code($code);
|
||||
}
|
||||
}
|
||||
|
||||
if ($referrer_id <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Self-purchase rebate gate (default allow, matching pay_rebate_self_s default true).
|
||||
$allow_self = true;
|
||||
if (class_exists('AKSRT_Settings') && method_exists('AKSRT_Settings', 'get_payment_affiliate_settings')) {
|
||||
$aff = AKSRT_Settings::get_payment_affiliate_settings();
|
||||
$allow_self = !isset($aff['self_s']) || !empty($aff['self_s']);
|
||||
}
|
||||
if ($uid > 0 && $referrer_id === $uid && !$allow_self) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $referrer_id;
|
||||
}
|
||||
|
||||
public function resolve_code(string $code): int {
|
||||
$code = sanitize_key($code);
|
||||
if ($code === '') return 0;
|
||||
|
||||
Reference in new issue
Block a user