fix(pay): unify download gate on cashier unlock not per-download credits
Route can_download/Download_State/permission card through Content_Visibility need_purchase; drop download_credit as a second toll; clarify admin labels for points purchase mode.
This commit is contained in:
+18
-16
@@ -653,9 +653,8 @@ if (!function_exists('aksrt_can_download')) {
|
||||
/**
|
||||
* 下载授权门禁 —— 单一合同。
|
||||
*
|
||||
* 实际判定全部交给 AKSRT_Content_Visibility::can_download_resource()
|
||||
* (由 inc/helpers/aksrt-resource.php 的同名 helper 在更早加载时定义)。
|
||||
* 此处仅作为该 helper 不可用时的兜底,避免出现第二套下载真相。
|
||||
* 实际判定交给 AKSRT_Content_Visibility::can_download_resource()。
|
||||
* 不再使用 download_credit 做按次扣积分门禁。
|
||||
*
|
||||
* @param int|WP_Post|null $post
|
||||
* @param int $user_id 0 表示当前用户
|
||||
@@ -672,13 +671,13 @@ if (!function_exists('aksrt_can_download')) {
|
||||
}
|
||||
|
||||
$meta = aksrt_get_pay_meta($p);
|
||||
if ($meta['pay_type'] !== AKSRT_PAY_TYPE_DOWNLOAD) {
|
||||
if (($meta['pay_type'] ?? '') !== AKSRT_PAY_TYPE_DOWNLOAD) {
|
||||
return new WP_Error('aksrt_not_downloadable', __('该内容不是可下载资源。', 'aksrt'));
|
||||
}
|
||||
|
||||
$paid_settings = class_exists('AKSRT_Settings')
|
||||
? AKSRT_Settings::get_paid_content_settings()
|
||||
: ['download_login' => true, 'download_credit' => true];
|
||||
: ['download_login' => true];
|
||||
|
||||
$uid = $user_id > 0 ? $user_id : get_current_user_id();
|
||||
|
||||
@@ -687,18 +686,21 @@ if (!function_exists('aksrt_can_download')) {
|
||||
return new WP_Error('aksrt_need_login', __('请先登录。', 'aksrt'), ['login_url' => $login_url]);
|
||||
}
|
||||
|
||||
if ($uid > 0 && aksrt_has_paid_access($p, $uid)) return true;
|
||||
if ($uid > 0 && function_exists('aksrt_is_vip_exempt') && aksrt_is_vip_exempt($uid)) return true;
|
||||
if ($uid > 0 && function_exists('aksrt_has_paid_access') && aksrt_has_paid_access($p, $uid)) {
|
||||
return true;
|
||||
}
|
||||
if ($uid > 0 && function_exists('aksrt_is_vip_exempt') && aksrt_is_vip_exempt($uid)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$cost = aksrt_get_download_cost($p);
|
||||
if ($cost > 0 && !empty($paid_settings['download_credit'])) {
|
||||
$balance = function_exists('aksrt_user_credits') ? aksrt_user_credits($uid) : 0;
|
||||
if ($balance < $cost) {
|
||||
return new WP_Error('aksrt_credits_insufficient', __('积分不足。', 'aksrt'), [
|
||||
'balance' => $balance,
|
||||
'cost' => $cost,
|
||||
]);
|
||||
}
|
||||
// Fallback without Content_Visibility: require purchase when priced.
|
||||
$cost = function_exists('aksrt_get_download_cost') ? aksrt_get_download_cost($p) : 0;
|
||||
if ($cost > 0) {
|
||||
return new WP_Error('aksrt_need_purchase', __('请先购买后再下载。', 'aksrt'), [
|
||||
'status' => 402,
|
||||
'cost' => $cost,
|
||||
'post_id'=> (int) $p->ID,
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user