1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-11 18:56:50 +02:00

积分可见功能

This commit is contained in:
云落 2020-02-26 11:31:45 +08:00
parent f449e96cc4
commit 36b0871ab3
5 changed files with 65 additions and 47 deletions

View file

@ -541,6 +541,24 @@ jQuery(function ($) { /**声明加载jQuery */
});
/**
* 积分可见
*/
$("#pay_points").click(function () {
var ajax_data = {
action: $("#pay_points").data("action"),
userid : $("#pay_points").data("userid"),
id : $("#pay_points").data("id"),
point : $("#pay_points").data("point")
};
$.post(ajax.url, ajax_data, function (b) {
b = $.trim(b);
if ('' !== b) {
show_hide_content('#hide_notice', b);
}
});
});

View file

@ -63,50 +63,37 @@ class GDK_Points_Shortcodes {
public static function pay($atts, $content = null) {
global $wpdb;
$user_id = get_current_user_id();
$description = get_the_ID();
$result = $wpdb->get_row("SELECT description FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $description . " AND status='accepted' LIMIT 0, 3;", ARRAY_A )['description']; //验证是否支付
$pid = get_the_ID();
$result = $wpdb->get_row("SELECT description FROM " . GDK_Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $pid . " AND status='accepted' LIMIT 0, 3;", ARRAY_A )['description']; //验证是否支付
extract(shortcode_atts(['point' => "10"], $atts));
$notice = '';
$pay_content = get_post_meta($description, 'pay_content', true);
if (!empty($pay_content) && $pay_content != $content) {
update_post_meta($description, 'pay_content', $content, true);
} else {
add_post_meta($description, 'pay_content', $content, true);
}
add_post_meta($pid, '_point_content', $content, true) or update_post_meta($pid, '_point_content', $content);//没有新建,有就更新
if (is_user_logged_in()) {
if ($result == $description || current_user_can('administrator')) {
$notice.= '<div class="alert alert-info"">';
if ($result == $pid || current_user_can('administrator')) {
$notice.= '<div class="cm-alert success">';
$notice.= $content;
$notice.= '</div>';
$notice.= '</div>';
} else {
if (GDK_Points::get_user_total_points($user_id, 'accepted') < $point) {
$notice.= '<div class="alert alert-info"">';
$notice.= '<p style="color:red;">本段内容需要支付 ' . $point . '金币查看</p>';
$notice.= '<p style="color:red;">您当前拥有 <em><strong>' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币,您的金币不足,请充值</p>';
$notice.= '<p><a class="lhb" href="' . get_permalink(gdk_page_id('chongzhi')) . '" target="_blank" rel="nofollow" data-original-title="立即充值" title="">立即充值</a></p>';
$notice.= '</div>';
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
$notice.= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币,金币不足,请充值</p>';
$notice.= buy_points();
$notice.= '</fieldset>';
} else {
$notice.= '<div id="pay_notice" class="alert alert-info"">';
$notice.= '<p style="color:red;">本段内容需要付费查看,您当前拥有 <em><strong>' . GDK_Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币</p>';
$notice.= '<p><a class="lhb" style="cursor: pointer;" onclick="pay_point();">点击购买</a></p>';
$notice.= '</div>';
$notice.= '<p id="pay_success"></p>';
echo '<script type="text/javascript">
function pay_point() {
ajax.post("' . admin_url('admin-ajax.php') . '", "action=gdk_pay_buy&point=' . $point . '&userid=' . $user_id . '&id=' . $description . '", function(n) {
null != n && (document.getElementById("pay_notice").style.display = "none", document.getElementById("pay_success").innerHTML = "<div class=\"alert alert-info\">" + n + "</div>");
});
}</script>';
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
$notice.= '<p>您当前拥有<span class="red">'.GDK_Points::get_user_total_points($user_id, 'accepted').'</span>金币</p>';
$notice.= '<p><button class="cm-btn primary" id="pay_points" data-point="'.$point.'" data-userid="'.$user_id.'" data-action="gdk_pay_buy" data-id="'.$pid.'">点击购买</button></p>';
$notice.= '</fieldset>';
}
}
} else {
global $wp;
$current_url = home_url(add_query_arg([] , $wp->request));
$login_uri = '<a href="' . esc_url(wp_login_url($current_url)) . '" data-original-title="点击登录">点击登录</a>';
$notice.= '<div class="alert alert-info"">';
$notice.= '<p style="color:red;">查看本段内容需要支付 ' . $point . ' 金币</p>';
$notice.= '<p style="color:red;">您尚未登录,请 ' . $login_uri . ' 或者 <a href="' . esc_url(wp_registration_url()) . '">立即注册</a> </p>';
$notice.= '</div>';
$notice.= '<fieldset id="hide_notice" class="fieldset"><legend class="legend">付费内容</legend>';
$notice.= '<p>当前隐藏内容需要支付</p><span class="cm-coin">'.$point.'金币</span>';
$notice.= '<p>您当前尚未登陆,请登陆后查看</p>';
$notice.= weixin_login_btn();
$notice.= '</fieldset>';
}
return $notice;
}

View file

@ -259,3 +259,19 @@ function bind_email_check(){
add_action( 'wp_ajax_bind_email_check', 'bind_email_check' );
add_action( 'wp_ajax_nopriv_bind_email_check', 'bind_email_check' );
function point_buy(){
if (isset($_POST['point']) && isset($_POST['userid']) &&isset($_POST['id']) && $_POST['action'] == 'gdk_pay_buy') {
GDK_Points::set_points( -$_POST['point'],
$_POST['userid'],
array(
'description' => $_POST['id'],
'status' => get_option( 'points-points_status', 'accepted' )
)
);//扣除金币
$pay_content = get_post_meta($_POST['id'], '_point_content', true);
exit($pay_content);
}
}
add_action( 'wp_ajax_gdk_pay_buy', 'point_buy' );
add_action( 'wp_ajax_nopriv_gdk_pay_buy', 'point_buy' );

View file

@ -5,6 +5,7 @@
* 获取摘要
*/
function gdk_print_excerpt($length, $post = null, $echo = true, $more = '...') {
global $post;
$text = $post->post_excerpt;
@ -144,7 +145,7 @@ function nc_like_init($key, $direct = false)
if ($action == 'do') {
$expire = time() + 99999999;
if (!isset($_COOKIE[$key.'_'.$id]) || $direct) {
setcookie($key.'_'.$id, $id, $expire, '/', $domain, false);
gdk_set_cookie($key.'_'.$id, $id, $expire);
if (!$lh_raters || !is_numeric($lh_raters)) {
update_post_meta($id, $key, 1);
} else {
@ -155,7 +156,7 @@ function nc_like_init($key, $direct = false)
if ($action == 'undo' && !$direct) {
$expire = time() - 1;
if (isset($_COOKIE[$key.'_'.$id])) {
setcookie($key.'_'.$id, $id, $expire, '/', $domain, false);
gdk_set_cookie($key.'_'.$id, $id, $expire);
update_post_meta($id, $key, ($lh_raters - 1));
}
}
@ -997,7 +998,7 @@ function buy_points(){
</p>
</form>';
}else{// no login
$result = '<div class=\'cm-alert error\'>本页面需要您登录才可以操作,请先 <a target="_blank" href="'.esc_url( wp_login_url( get_permalink() ) ).'">点击登录</a> 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
$result = '<div class=\'cm-alert error\'>本页面需要您登录才可以操作,请先 '.weixin_login_btn().' 或者<a href="'.esc_url( wp_registration_url() ).'">立即注册</a></div>';
}
return $result;
}
@ -1059,7 +1060,7 @@ function weixin_login_btn(){
$result .= '<script>window.localStorage.setItem(\'ls-bind\',1);</script>';
}
}
$result .= '<p>您已登陆</p><p>您的ID是:'.$user_id.'</p><p>您的昵称是:'.$user->nickname.'</p>';
//$result .= '<p>您已登陆</p><p>您的ID是:'.$user_id.'</p><p>您的昵称是:'.$user->nickname.'</p>';
}
return $result;
}
@ -1129,13 +1130,6 @@ function editorial_hover_color( $hex, $steps ) {
/**
* Get minified css and removed space
*
* @since 1.2.5
*/
/**
* Minify CSS
*
* @since 1.0.0
*/
function pwd_minify_css( $css ) {
@ -1220,7 +1214,8 @@ function gdk_tag_dropdown(){
return $gdk_option_tag;
}
function base64EncodeImage ($image_file) {
//转化图片为base64格式
function base64img ($image_file) {
$base64_image = '';
$image_info = getimagesize($image_file);
$image_data = file_get_contents($image_file);

View file

@ -202,7 +202,9 @@ add_shortcode('vip', 'gdk_login_to_read');
function gdk_secret_view($atts, $content = null) {
$pid = get_the_ID();
add_post_meta($pid, '_pass_content', $content, true) or update_post_meta($pid, '_pass_content', $content);
if ( current_user_can( 'administrator' ) || gdk_is_weixin()) { return $content; }//admin show
if ( current_user_can( 'administrator' ) ) {
return '<fieldset class="fieldset"><legend class="legend">隐藏内容</legend><p>' . $content . '</p></fieldset>';
}//admin show
return '<div class="cm-grid cm-card pass_viewbox">
<div class="cm-row">
<div class="cm-col-md-4">