feat(pay): enforce VIP free-download daily quota like zibll
This commit is contained in:
1 parent
7cce3ff275
commit
8b50687e9d
4 files changed
+199
-4
No files matched your search
@@ -171,6 +171,14 @@ class AKSRT_Content_Visibility {
|
||||
]);
|
||||
}
|
||||
|
||||
// Zibll daily free-download quota.
|
||||
if ($cost <= 0 && function_exists('aksrt_check_free_download_quota')) {
|
||||
$quota = aksrt_check_free_download_quota($uid, $cost);
|
||||
if (is_wp_error($quota)) {
|
||||
return $quota;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($paid_settings['download_credit']) && $cost > 0) {
|
||||
$balance = class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0;
|
||||
if ($balance < $cost) {
|
||||
|
||||
@@ -124,10 +124,13 @@ class AKSRT_Download {
|
||||
'post_id' => $post_id,
|
||||
'price' => (float) $meta['price'],
|
||||
'cost' => $cost,
|
||||
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']),
|
||||
'require_login' => !empty($paid_settings['download_login']) || !empty($meta['require_login']) || (!empty($paid_settings['free_logged_show']) && $cost <= 0),
|
||||
'require_captcha' => $need_captcha,
|
||||
'logged_in' => $uid > 0,
|
||||
'balance' => $uid > 0 && class_exists('AKSRT_Credits') ? AKSRT_Credits::balance($uid) : 0,
|
||||
'free_limit' => $uid > 0 && function_exists('aksrt_get_user_free_download_limit') ? aksrt_get_user_free_download_limit($uid) : 0,
|
||||
'free_used' => $uid > 0 && function_exists('aksrt_get_user_free_downloaded_number') ? aksrt_get_user_free_downloaded_number($uid) : 0,
|
||||
'free_surplus' => $uid > 0 && function_exists('aksrt_get_free_download_surplus') ? aksrt_get_free_download_surplus($uid) : null,
|
||||
'sources' => array_map(function ($row, $idx) {
|
||||
$extract_code = trim((string) ($row['extract_code'] ?? ''));
|
||||
return [
|
||||
@@ -162,6 +165,17 @@ class AKSRT_Download {
|
||||
if (is_wp_error($gate)) return $gate;
|
||||
|
||||
$paid_settings = AKSRT_Settings::get_paid_content_settings();
|
||||
$uid = get_current_user_id();
|
||||
$cost = aksrt_resource_download_cost($post);
|
||||
|
||||
// Daily free-download quota (Zibll).
|
||||
if ($cost <= 0 && $uid > 0 && function_exists('aksrt_check_free_download_quota')) {
|
||||
$quota = aksrt_check_free_download_quota($uid, $cost);
|
||||
if (is_wp_error($quota)) {
|
||||
return $quota;
|
||||
}
|
||||
}
|
||||
|
||||
$need_captcha = !empty($paid_settings['download_captcha']) || !empty($meta['require_captcha']);
|
||||
// 下载双开关:cms_features.download_captcha(或单资源强制)且场景未停用。
|
||||
if ($need_captcha && function_exists('aksrt_require_captcha')) {
|
||||
@@ -176,8 +190,6 @@ class AKSRT_Download {
|
||||
}
|
||||
}
|
||||
|
||||
$uid = get_current_user_id();
|
||||
$cost = aksrt_resource_download_cost($post);
|
||||
if ($cost > 0 && $uid > 0 && class_exists('AKSRT_Credits')) {
|
||||
$deducted = AKSRT_Credits::deduct($uid, $cost, 'download', ['type' => 'post', 'id' => $post_id]);
|
||||
if (is_wp_error($deducted)) return $deducted;
|
||||
@@ -191,6 +203,11 @@ class AKSRT_Download {
|
||||
return $token;
|
||||
}
|
||||
|
||||
// Record free download against daily quota after token issued.
|
||||
if ($cost <= 0 && $uid > 0 && function_exists('aksrt_record_user_free_download')) {
|
||||
aksrt_record_user_free_download($uid, $post_id);
|
||||
}
|
||||
|
||||
$dl_url = home_url('/' . self::ENDPOINT . '/' . $token);
|
||||
if ($uid > 0 && function_exists('aksrt_add_user_notification')) {
|
||||
aksrt_add_user_notification($uid, [
|
||||
|
||||
Reference in new issue
Block a user