Commit ba647f58 authored by 蒋林's avatar 蒋林

点赞

parent ffae9a80
<?php <?php
require("../class/connect.php"); require(__DIR__ . "/../../class/connect.php");
require("../class/db_sql.php"); require(__DIR__ . "/../../class/db_sql.php");
require("../member/class/user.php"); require(__DIR__ . "/../../member/class/user.php");
require("../class/q_functions.php"); require(__DIR__ . "/../../class/q_functions.php");
$link=db_connect(); $link=db_connect();
$empire=new mysqlquery(); $empire=new mysqlquery();
...@@ -215,14 +215,4 @@ function likeComment($plid, $user) { ...@@ -215,14 +215,4 @@ function likeComment($plid, $user) {
function handelcomment($comment) { function handelcomment($comment) {
$comment['created_at'] = date('Y-m-d H:i', $comment['created_at']); $comment['created_at'] = date('Y-m-d H:i', $comment['created_at']);
return $comment; return $comment;
}
function returnmsg($status=false, $msg='', $data='') {
$return['status'] = $status ? true : false;
$return['msg'] = $msg;
$return['data'] = $data;
echo json_encode($return, JSON_UNESCAPED_UNICODE);
exit();
} }
\ No newline at end of file
<?php
require(__DIR__ . "/../../class/connect.php");
require(__DIR__ . "/../../class/db_sql.php");
require(__DIR__ . "/../../member/class/user.php");
require(__DIR__ . "/../../class/q_functions.php");
$link=db_connect();
$empire=new mysqlquery();
$user = islogin();
if (empty($user)) {
returnmsg(false, '请登录');
}
$mod = isset($_GET['mod']) ? $_GET['mod']: '';
$newsid = isset($_POST['newsid']) ? intval($_POST['newsid']) : 0;
if (!$newsid) {
returnmsg(false, '内容ID参数错误');
}
if ($mod == 'diggtop') {
diggtop($newsid, $user);
} elseif ($mod == 'checkdiggtop') {
checkdiggtop($newsid, $user);
}
function checkdiggtop($newsid, $user) {
global $empire,$dbtbpre;
$tablenewsdiggtop = $dbtbpre.'ecms_news_diggtop';
$sql = "select * from {$tablenewsdiggtop} where user_id={$user['userid']} and news_id={$newsid}";
$newsdiggtop = $empire->fetch1($sql);
if ($newsdiggtop) {
returnmsg(true, '已赞');
} else {
returnmsg(false);
}
}
function diggtop($newsid, $user) {
global $empire,$dbtbpre;
$tablenews = $dbtbpre.'ecms_news';
$tablenewsdiggtop = $dbtbpre.'ecms_news_diggtop';
$sql = "select id,classid,userid from {$tablenews} where id={$newsid}";
$news = $empire->fetch1($sql);
if (empty($news)) {
returnmsg(false, '该内容不存在');
}
$sql = "select * from {$tablenewsdiggtop} where user_id={$user['userid']} and news_id={$newsid}";
$newsdiggtop = $empire->fetch1($sql);
if ($newsdiggtop) {
returnmsg( false, '已赞过该内容', 'diggtoped');
}
$now = time();
$sql = "insert into {$tablenewsdiggtop} (user_id,news_uid,news_id,created_at) VALUES ({$user['userid']}, {$news['userid']}, {$newsid}, {$now})";
$empire->query($sql);
$id = $empire->lastid();
if ($id) {
$sql = "update {$tablenews} set diggtop=diggtop+1 where id={$newsid}";
$empire->query($sql);
returnmsg(true, '点赞成功');
} else {
returnmsg(false, '点赞失败');
}
}
\ No newline at end of file
...@@ -297,4 +297,13 @@ function ReplaceTempvar($temp){ ...@@ -297,4 +297,13 @@ function ReplaceTempvar($temp){
return $temp; return $temp;
} }
function returnmsg($status=false, $msg='', $data='') {
$return['status'] = $status ? true : false;
$return['msg'] = $msg;
$return['data'] = $data;
echo json_encode($return, JSON_UNESCAPED_UNICODE);
exit();
}
?> ?>
\ No newline at end of file
...@@ -20,7 +20,7 @@ $(".send-pl").click(function () { ...@@ -20,7 +20,7 @@ $(".send-pl").click(function () {
$(self).attr("disabled", true); $(self).attr("disabled", true);
$.post("/e/pl/comments.php?mod=create", data, function (e) { $.post("/e/action/news/comment.php?mod=create", data, function (e) {
$(self).attr("disabled", false); $(self).attr("disabled", false);
if (e.status) { if (e.status) {
$("textarea[name='content']").val(''); $("textarea[name='content']").val('');
...@@ -35,7 +35,7 @@ $(".send-pl").click(function () { ...@@ -35,7 +35,7 @@ $(".send-pl").click(function () {
}); });
function comments(newsid) { function comments(newsid) {
$.post("/e/pl/comments.php", {newsid: newsid}, function (e) { $.post("/e/action/news/comment.php", {newsid: newsid}, function (e) {
if (!$.isEmptyObject(e.data)) { if (!$.isEmptyObject(e.data)) {
var comments = e.data; var comments = e.data;
var html = ''; var html = '';
...@@ -98,7 +98,7 @@ $(".reply-pl").click(function () { ...@@ -98,7 +98,7 @@ $(".reply-pl").click(function () {
$(self).attr("disabled", true); $(self).attr("disabled", true);
$.post("/e/pl/comments.php?mod=reply", data, function (e) { $.post("/e/action/news/comment.php?mod=reply", data, function (e) {
$(self).attr("disabled", false); $(self).attr("disabled", false);
if (e.status) { if (e.status) {
handelReplyComment(data.plid, e.data); handelReplyComment(data.plid, e.data);
...@@ -134,7 +134,7 @@ function likeComment(plid, islike) { ...@@ -134,7 +134,7 @@ function likeComment(plid, islike) {
return false; return false;
} }
$.post("/e/pl/comments.php?mod=like", {plid: plid}, function (e) { $.post("/e/action/news/comment.php?mod=like", {plid: plid}, function (e) {
if (e.status) { if (e.status) {
$.each( $('.comment-list li'), function(){ $.each( $('.comment-list li'), function(){
if ($(this).attr('data-id') == plid) { if ($(this).attr('data-id') == plid) {
...@@ -167,7 +167,7 @@ function scrollLoading() { ...@@ -167,7 +167,7 @@ function scrollLoading() {
var nextPage = currentPage + 1; var nextPage = currentPage + 1;
scrollLoad.html("<img src='" + spinner + "'>"); scrollLoad.html("<img src='" + spinner + "'>");
$.post("/e/pl/comments.php", {newsid: newsid, p:currentPage}, function (e) { $.post("/e/action/news/comment.php", {newsid: newsid, p:currentPage}, function (e) {
if (!$.isEmptyObject(e.data)) { if (!$.isEmptyObject(e.data)) {
var comments = e.data; var comments = e.data;
var html = ''; var html = '';
...@@ -196,5 +196,30 @@ if (scrollLoad.length > 0) { ...@@ -196,5 +196,30 @@ if (scrollLoad.length > 0) {
} }
//点赞 //检查内容点赞状态
$.post("/e/action/news/index.php?mod=checkdiggtop", {newsid: newsid}, function (e) {
if (e.status) {
$("#zan").find('i').removeClass('icon-zan').addClass('icon-zan-fill');
} else {
$('#zan').one('click',function () {
diggtop();
});
}
}, 'json');
function diggtop() {
$.post("/e/action/news/index.php?mod=diggtop", {newsid: newsid}, function (e) {
if (e.status) {
$("#zan").find('i').removeClass('icon-zan').addClass('icon-zan-fill');
$('.zan-tip').animate({opacity: "1", top: "-=30"},500).animate({opacity: "0", top: "-30"}, "slow");
} else {
pop(e.msg);
}
}, 'json');
}
//收藏
$('#favor').click(function () {
$(this).find('i').removeClass('icon-favor').addClass('icon-favor-fill');
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment