/** * 获取文章价格权限信息 * @Author Dadong2g * @date 2023-04-07 * @param [type] $post_id [description] * @return [type] */ function get_post_price_info($post_id = null) { $shop_mod = get_site_shop_mod(); // 当商城模式为VIP模式时,修改所有文章的价格权限为不可购买 if ($shop_mod === 'vip_mod') { return [ 'name' => '仅支持VIP', 'desc' => '仅支持VIP会员模式,不支持单独购买', 'prices' => [ 'no_vip' => false, 'month_vip' => false, 'year_vip' => false, 'permanent_vip' => false ] ]; } $post_info = get_post_pay_data($post_id); $post_price = $post_info['price']; $post_authority = $post_info['authority']; $authoritys = [ 'no' => [ 'name' => '原价购买', 'desc' => '所有用户原价购买', 'prices' => ['no_vip' => $post_price, 'month_vip' => $post_price, 'year_vip' => $post_price, 'permanent_vip' => $post_price], ], 'vip_only' => [ 'name' => 'VIP专属', 'desc' => 'VIP用户可以免费获取,普通用户无法购买', 'prices' => ['no_vip' => false, 'month_vip' => 0, 'year_vip' => 0, 'permanent_vip' => 0], ], 'month_free' => [ 'name' => 'VIP免费', 'desc' => 'VIP免费获取,普通用户无法购买', 'prices' => ['no_vip' => false, 'month_vip' => 0, 'year_vip' => 0, 'permanent_vip' => 0], ], 'year_free' => [ 'name' => '包年/永久VIP免费', 'desc' => '年费或永久VIP免费获取,其他用户无法购买', 'prices' => ['no_vip' => false, 'month_vip' => false, 'year_vip' => 0, 'permanent_vip' => 0], ], 'permanent_free' => [ 'name' => '仅永久VIP免费', 'desc' => '仅永久VIP免费获取,其他用户无法购买', 'prices' => ['no_vip' => false, 'month_vip' => false, 'year_vip' => false, 'permanent_vip' => 0], ], ]; return $authoritys[$post_authority]; } /** * 根据用户id获取用户购买文章实际价格 * @Author Dadong2g * @date 2023-04-07 * @param [type] $user_id [description] * @param [type] $post_id [description] * @return [type] false不可购买 0免费获取 int原价 */ function get_user_pay_post_price($user_id = null, $post_id = null) { // 当商城模式为VIP模式时,所有单品都不可购买 if (get_site_shop_mod() === 'vip_mod') { return false; } $post_prices = get_post_price_info($post_id); $user_type = get_user_vip_type($user_id); return $post_prices['prices'][$user_type]; } /** * 获取购买按钮 * @Author Dadong2g pay_down * @date 2023-04-11 * @param [type] $post_id [int] * @param [type] $order_type [1PSOT 2VIP] * @param [type] $order_info 1PSOT = [pay_down pay_hide pay_video ] 2VIP = [month_vip year_vip permanent_vip ''] * @return [type] */ function zb_get_pay_button($post_id = 0, $order_type = 0, $order_info = '', $button_name = '立即购买') { // 当商城模式为VIP模式且请求的是单品购买时,显示不可购买提示 if (get_site_shop_mod() === 'vip_mod' && $order_type == 1) { return '
仅支持VIP会员购买,请先升级会员
'; } $post_id = (int) $post_id; $order_type = (int) $order_type; $user_price = get_user_pay_post_price(null, $post_id); if ($user_price === false) { return '
无购买权限
'; } $button_class = "btn btn-danger-soft js-pay-action"; $button_icon = ($order_type == 2) ? "far fa-gem" : "fab fa-shopify"; $button_content = "$button_name"; $html = ""; return $html; } 浏览器-阳子湖软件园