Commit 64ac73cb authored by 黄广星's avatar 黄广星

等级

parent 41212c6d
......@@ -2,9 +2,11 @@
var express = require('express'),
router = express.Router(),
user = require('../../utils/user'),
util = require('../../utils/util'),
returnCode = require('../../utils/returnCode'),
_ = require('lodash');
var forumAboutMEService=require('../../service/forumAboutMEService');
var forumAboutMEService = require('../../service/forumAboutMEService');
module.exports = function(app) {
app.use('/v1/forum', router);
......@@ -13,15 +15,17 @@ module.exports = function(app) {
router.get('/aboutme/me2other', function(req, res, next) {
var userId = user.getMobileUser(req);
var entcode = req.session.user.ent_code;
var pageNo=req.query.pageNo || 1;
var pageSize=req.query.pageSize || 10;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
console.log(userId);
console.log(entcode);
forumAboutMEService.me2other(entcode,userId,pageNo,pageSize,function(err,result){
if(err){
forumAboutMEService.me2other(entcode, userId, pageNo, pageSize, function(err, result) {
if (err) {
res.json(returnCode.UNCHECK_ERROR(err));
}else{
} else {
util.loadLevel(req.session.user.ent_code,result.items,function(){
res.json(_.assign(result, returnCode.SUCCESS));
});
}
});
});
......@@ -29,15 +33,17 @@ router.get('/aboutme/me2other', function(req, res, next) {
router.get('/aboutme/other2me', function(req, res, next) {
var userId = user.getMobileUser(req);
var entcode = req.session.user.ent_code;
var pageNo=req.query.pageNo || 1;
var pageSize=req.query.pageSize || 10;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
console.log(userId);
console.log(entcode);
forumAboutMEService.other2me(entcode,userId,pageNo,pageSize,function(err,result){
if(err){
forumAboutMEService.other2me(entcode, userId, pageNo, pageSize, function(err, results) {
if (err) {
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.json(_.assign(result, returnCode.SUCCESS));
} else {
util.loadLevel(req.session.user.ent_code,results.items,function(){
res.json(_.assign(results, returnCode.SUCCESS));
});
}
});
});
......@@ -45,12 +51,12 @@ router.get('/aboutme/other2me', function(req, res, next) {
router.get('/aboutme/he2other/:id/:entcode', function(req, res, next) {
var userId = req.params.id;
var entcode = req.params.entcode;
var pageNo=req.query.pageNo || 1;
var pageSize=req.query.pageSize || 10;
forumAboutMEService.me2other(entcode,userId,pageNo,pageSize,function(err,result){
if(err){
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
forumAboutMEService.me2other(entcode, userId, pageNo, pageSize, function(err, result) {
if (err) {
res.json(returnCode.UNCHECK_ERROR(err));
}else{
} else {
res.json(_.assign(result, returnCode.SUCCESS));
}
});
......@@ -59,12 +65,12 @@ router.get('/aboutme/he2other/:id/:entcode', function(req, res, next) {
router.get('/aboutme/other2he/:id/:entcode', function(req, res, next) {
var userId = req.params.id;
var entcode = req.params.entcode;
var pageNo=req.query.pageNo || 1;
var pageSize=req.query.pageSize || 10;
forumAboutMEService.other2me(entcode,userId,pageNo,pageSize,function(err,result){
if(err){
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
forumAboutMEService.other2me(entcode, userId, pageNo, pageSize, function(err, result) {
if (err) {
res.json(returnCode.UNCHECK_ERROR(err));
}else{
} else {
res.json(_.assign(result, returnCode.SUCCESS));
}
});
......
......@@ -3,6 +3,7 @@ var express = require('express'),
router = express.Router(),
returnCode = require('../../utils/returnCode'),
then = require('thenjs'),
util = require('../../utils/util'),
_ = require('lodash');
var mongoose = require('mongoose');
......@@ -10,8 +11,8 @@ var ForumInfo = mongoose.model('ForumInfo');
var forumInfoService = require('../../service/forumInfoService');
var forumThreadService = require('../../service/forumThreadService');
var forumUserThreadControlService = require('../../service/forumUserThreadControlService');
var forumTagService=require('../../service/forumTagService');
var forumCommentService=require('../../service/forumCommentService');
var forumTagService = require('../../service/forumTagService');
var forumCommentService = require('../../service/forumCommentService');
var forumThreadAttendService = require('../../service/forumThreadAttendService');
var httpService = require('../../service/httpService');
var redisPraiseLog = require('../../utils/redisPraiseLog');
......@@ -28,7 +29,9 @@ module.exports = function(app) {
router.get('/info/list/all', function(req, res, next) {
var rs = {};
var ent_code = req.session.user.ent_code;
forumInfoService.getAllByGid({ent_code:ent_code},1,100, function(err, datas) {
forumInfoService.getAllByGid({
ent_code: ent_code
}, 1, 100, function(err, datas) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
......@@ -62,7 +65,7 @@ router.get('/info/:fid/get', function(req, res, next) {
var fid = req.params.fid || null;
if (fid) {
var source = req.session.mobileForumUser.source;
httpService.createLog(req,source,fid,2);
httpService.createLog(req, source, fid, 2);
async.waterfall([
function(callback) {
//更新浏览数
......@@ -159,7 +162,7 @@ router.get('/info/:fid/threads', function(req, res, next) {
var conditions = {
ent_code: ent_code,
level: 1,
status:1
status: 1
};
if (fid) {
conditions.info = fid;
......@@ -194,22 +197,24 @@ router.get('/info/:fid/threads', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
redisPraiseLog.get(ent_code,user.getMobileUser(req),'thread', function(error, docs){
_.forEach(results.items, function(d,i) {
if(results.items[i].toObject){
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if(results.items[i]._id == docs[k]){
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
};
});
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
}
......@@ -230,7 +235,9 @@ router.get('/info/:fid/hotThreads', function(req, res, next) {
ent_code: req.session.user.ent_code,
level: 1,
info: fid,
status:{$ne:3}
status: {
$ne: 3
}
};
if (fid) {
......@@ -285,7 +292,9 @@ router.get('/info/:fid/photoThreads', function(req, res, next) {
level: 1,
info: fid,
type: 3,
status:{$ne:3}
status: {
$ne: 3
}
};
if (fid) {
......@@ -374,6 +383,7 @@ router.get('/info/:fid/myThreads', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
});
......@@ -392,7 +402,7 @@ router.get('/info/myThreads', function(req, res, next) {
var conditions = {
ent_code: req.session.user.ent_code,
from: user.getMobileUser(req),
status:1
status: 1
};
async.waterfall([
......@@ -426,7 +436,10 @@ router.get('/info/myThreads', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
util.loadLevel(req.session.user.ent_code, results.items, function() {
res.json(_.assign(results, returnCode.SUCCESS));
});
}
});
}
......@@ -474,7 +487,9 @@ router.get('/info/hisThreads/:id', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
util.loadLevel(req.session.user.ent_code, results.items, function() {
res.json(_.assign(results, returnCode.SUCCESS));
});
}
});
}
......@@ -486,10 +501,10 @@ router.get('/info/myComments', function(req, res, next) {
var fid = req.params.fid || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var id=user.getMobileUser(req);
var id = user.getMobileUser(req);
var conditions = {
ent_code: req.session.user.ent_code,
status:1,
status: 1,
//$or:[{from: id},{to: id}]
to: id
};
......@@ -506,16 +521,16 @@ router.get('/info/myComments', function(req, res, next) {
//获取跟我相关的评论列表
router.get('/info/:tid/comment/list', function(req, res, next) {
var tid=req.params.tid || null;
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var id=user.getMobileUser(req);
var id = user.getMobileUser(req);
var conditions = {
ent_code: req.session.user.ent_code,
thread: tid,//5539fa026cf87854c87be3c9
thread: tid, //5539fa026cf87854c87be3c9
level: '1'
};
if(!tid){
if (!tid) {
return res.json(returnCode.WRONG_PARAM);
}
forumCommentService.getAllCommentByThread(conditions, function(err, results) {
......@@ -523,34 +538,34 @@ router.get('/info/:tid/comment/list', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
var docs =[];
if(results && results.length> 0){
results.forEach(function(doc,i){
var docs = [];
if (results && results.length > 0) {
results.forEach(function(doc, i) {
//过滤与自己无关的评论
if(doc.from._id != id && doc.thread.from != id){//文章和一级评论的作者不是自己
if(doc.comments && doc.comments.length>0){//有子评论
if (doc.from._id != id && doc.thread.from != id) { //文章和一级评论的作者不是自己
if (doc.comments && doc.comments.length > 0) { //有子评论
var comments = [];
doc.comments.forEach(function(comment,j){
if((comment.from && comment.from._id == id) || (comment.to && comment.to._id == id)){
doc.comments.forEach(function(comment, j) {
if ((comment.from && comment.from._id == id) || (comment.to && comment.to._id == id)) {
//二级评论的作者 或 被评论者是自己
comments.push(comment);
}
});
if(comments.length >0){
doc.comments=comments;
if (comments.length > 0) {
doc.comments = comments;
docs.push(doc);
}
}
}else{//文章或一级评论的作者是自己那么所有的子评论都不用过滤
} else { //文章或一级评论的作者是自己那么所有的子评论都不用过滤
docs.push(doc);
}
});
}
var obj={};
obj.total=docs.length;
obj.pageNo=pageNo;
obj.pageSize=pageSize;
obj.items=docs.slice((pageNo-1>=0?pageNo-1:0)*pageSize,pageSize);
var obj = {};
obj.total = docs.length;
obj.pageNo = pageNo;
obj.pageSize = pageSize;
obj.items = docs.slice((pageNo - 1 >= 0 ? pageNo - 1 : 0) * pageSize, pageSize);
res.json(_.assign(obj, returnCode.SUCCESS));
}
});
......@@ -565,7 +580,7 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
var ent_code = req.session.user.ent_code;
var conditions = {
ent_code: ent_code,
status:1,
status: 1,
info: fid
};
......@@ -609,14 +624,15 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
redisPraiseLog.get(ent_code,user.getMobileUser(req),'thread', function(error, docs){
_.forEach(results.items, function(d,i) {
if(results.items[i].toObject){
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if(results.items[i]._id == docs[k]){
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
......@@ -624,6 +640,8 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
});
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
}
......@@ -644,11 +662,11 @@ router.get('/info/:fid/tags', function(req, res, next) {
info: fid
};
if (fid) {
forumTagService.getAllTag(conditions,pageNo,pageSize,function(err,results){
if(err){
forumTagService.getAllTag(conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
}else{
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
});
......@@ -662,16 +680,16 @@ router.get('/info/:fid/mobileList', function(req, res, next) {
var fid = req.params.fid || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var conditions={
ent_code:req.session.user.ent_code,
type:1
var conditions = {
ent_code: req.session.user.ent_code,
type: 1
};
if (fid) {
forumTagService.getAllTag(conditions,pageNo,pageSize,function(err,results){
if(err){
forumTagService.getAllTag(conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
}else{
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
});
......@@ -686,51 +704,54 @@ router.get('/info/myAttend', function(req, res, next) {
var pageNo = req.query.pageNo,
pageSize = req.query.pageSize;
var total = 0;
then(function(cont){
then(function(cont) {
var conditions = {
attend:user_id
attend: user_id
}
forumThreadAttendService.findMyAttentByPage(conditions,pageNo, pageSize,'-updated',function(err,attends){
if(err){
forumThreadAttendService.findMyAttentByPage(conditions, pageNo, pageSize, '-updated', function(err, attends) {
if (err) {
cont(err);
}else{
if(attends && attends.datas.length>0){
} else {
if (attends && attends.datas.length > 0) {
total = attends.total;
var threadIds = [];
_.forEach(attends.datas,function(a){
_.forEach(attends.datas, function(a) {
threadIds.push(a.thread);
});
cont(null,threadIds);
}else{
res.json(_.assign({data:[],total:0}, returnCode.SUCCESS));
cont(null, threadIds);
} else {
res.json(_.assign({
data: [],
total: 0
}, returnCode.SUCCESS));
}
}
});
}).then(function(cont,threadIds){
}).then(function(cont, threadIds) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
cont(err,doc,threadIds);
cont(err, doc, threadIds);
});
}).then(function(cont,results,threadIds){
}).then(function(cont, results, threadIds) {
var conditions = {};
if(results){
conditions._id ={
$in:threadIds
if (results) {
conditions._id = {
$in: threadIds
// $nin:results
}
}else{
conditions._id ={
$in:threadIds
} else {
conditions._id = {
$in: threadIds
}
}
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize,'', function(err, threads) {
cont(err,threads);
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, '', function(err, threads) {
cont(err, threads);
});
}).then(function(cont,threads){
}).then(function(cont, threads) {
threads.total = total;
res.json(_.assign(threads, returnCode.SUCCESS));
}).then(function(cont){
}).then(function(cont) {
}).fail(function(cont,err){
}).fail(function(cont, err) {
console.error(err);
res.json(returnCode.BUSY);
})
......
......@@ -2,6 +2,7 @@
var express = require('express'),
router = express.Router(),
returnCode = require('../../utils/returnCode'),
util = require('../../utils/util'),
_ = require('lodash');
var mongoose = require('mongoose');
var ForumThread = mongoose.model('ForumThread');
......@@ -26,7 +27,6 @@ module.exports = function(app) {
app.use('/v1/forum', router);
};
function create(req, callback) {
var entity = req.body;
......@@ -58,19 +58,24 @@ function create(req, callback) {
entity.images = array;
}
//-----------处理前端上传图片结束
if(entity.pid && entity.type == 3 ){
forumThreadService.getByConditions({type:3,level:'2',pid:entity.pid,from:entity.from},function(err,doc){
if(doc){
if (entity.pid && entity.type == 3) {
forumThreadService.getByConditions({
type: 3,
level: '2',
pid: entity.pid,
from: entity.from
}, function(err, doc) {
if (doc) {
var update = {
$set:{
images:entity.images,
content:entity.content
$set: {
images: entity.images,
content: entity.content
}
};
forumThreadService.updateThreadById(doc._id,update,function(err,updatedDoc){
callback(err,entity);
forumThreadService.updateThreadById(doc._id, update, function(err, updatedDoc) {
callback(err, entity);
});
}else{
} else {
forumThreadService.createThread(entity, function(err, entity) {
if (err) {
console.error(err);
......@@ -81,7 +86,7 @@ function create(req, callback) {
});
}
});
}else{
} else {
forumThreadService.createThread(entity, function(err, entity) {
if (err) {
console.error(err);
......@@ -140,7 +145,7 @@ router.get('/thread/searchComment', function(req, res, next) {
var q = {
ent_code: ent_code,
// status: status,
from:req.session.mobileForumUser.from
from: req.session.mobileForumUser.from
};
forumThreadService.findCommentByPage(pageNo, pageSize, q, function(err, result) {
......@@ -161,14 +166,14 @@ router.get('/thread/searchComment', function(req, res, next) {
//新增论坛文章
router.post('/thread/create', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
if(isProhibition){
} else {
if (isProhibition) {
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
} else {
var integral = req.session.openUser.integral || 0;
var exp = req.session.openUser.exp || 0;
forumRolePermissionService.checkRolePermiss(req.session.user.ent_code, 'create', integral, exp, function(err, result) {
......@@ -183,11 +188,11 @@ router.post('/thread/create', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
forumAboutMEService.saveThread(thread);
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag) {
if (err) {
console.error(err);
}else{
if(!flag){
} else {
if (!flag) {
httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'post');
}
}
......@@ -234,19 +239,20 @@ router.get('/thread/:tid/get', function(req, res, next) {
pid = thread.pid,
source = req.session.mobileForumUser.source;
if (thread.type == 1 && thread.level == 1) {
httpService.createLog(req,source,info_id, 3, 1, tid);
httpService.createLog(req, source, info_id, 3, 1, tid);
} else if (thread.type == 1 && thread.level == 2) {
httpService.createLog(req,source,info_id, 3, 4, tid, pid);
httpService.createLog(req, source, info_id, 3, 4, tid, pid);
} else if (thread.type == 2 && thread.level == 1) {
httpService.createLog(req,source,info_id, 3, 2, tid);
httpService.createLog(req, source, info_id, 3, 2, tid);
} else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req,source,info_id, 3, 3, tid);
httpService.createLog(req, source, info_id, 3, 3, tid);
}
if (err) {
callback(err, null);
} else {
callback(null, thread);
}
});
......@@ -256,25 +262,54 @@ router.get('/thread/:tid/get', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
redisPraiseLog.get(ent_code,user.getMobileUser(req),'thread', function(error, docs){
if(thread.toObject){
var threads = [];
threads.push(thread);
util.loadLevel(req.session.user.ent_code, threads, function() {
if (threads && threads.length > 0) {
thread = threads[0];
}
//console.log(thread);
//console.log(thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0);
if (thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0) {
//console.log(thread.subThreads);
util.loadLevel(req.session.user.ent_code, thread.subThreads.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
if (thread.toObject) {
thread = thread.toObject();
}
thread.isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if(thread._id == docs[k]){
if (thread._id == docs[k]) {
thread.isPraise = true;
break;
}
};
var rs = {};
rs.data = thread;
res.json(_.assign(rs, returnCode.SUCCESS));
});
});
} else {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'thread', function(error, docs) {
if (thread.toObject) {
thread = thread.toObject();
}
thread.isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if (thread._id == docs[k]) {
thread.isPraise = true;
break;
}
};
var rs = {};
rs.data = thread;
res.json(_.assign(rs, returnCode.SUCCESS));
});
}
});
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
......@@ -285,7 +320,12 @@ router.get('/thread/photo/:pid/get', function(req, res, next) {
var pid = req.params.pid || null,
userId = req.session.mobileForumUser.userId;;
if (pid) {
forumThreadService.getByConditions({type:3,level:'2',pid:pid,from:userId},function(err,thread){
forumThreadService.getByConditions({
type: 3,
level: '2',
pid: pid,
from: userId
}, function(err, thread) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
......@@ -308,8 +348,8 @@ router.post('/thread/:tid/update', function(req, res, next) {
if (err) {
res.json(returnCode.BUSY);
} else {
if(!isNaN(req.body.status)){
forumAboutMEService.updateThreadStatus(thread._id,thread.status)
if (!isNaN(req.body.status)) {
forumAboutMEService.updateThreadStatus(thread._id, thread.status)
}
res.json(returnCode.SUCCESS);
}
......@@ -377,7 +417,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
}
},
function(callback) {
if(doc){ //如果已存在,更新为点赞日志
if (doc) { //如果已存在,更新为点赞日志
forumPraiseLogService.updatePraiseLog(doc._id, 0, function(err, result) {
if (err) {
callback(err, null);
......@@ -385,7 +425,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
callback(null, null);
}
});
}else{ //不存在,创建点赞日志
} else { //不存在,创建点赞日志
var entity = {
ent_code: ent_code,
user: user.getMobileUser(req),
......@@ -393,7 +433,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
ip: req.ip,
comment: null,
type: 1,
status :0
status: 0
};
//4.创建点赞日志
forumPraiseLogService.createPraiseLog(entity, function(err, result) {
......@@ -421,10 +461,10 @@ router.post('/thread/:tid/raise', function(req, res, next) {
// });
//更新点赞redis
redisPraiseLog.get(ent_code,userId,'thread', function(error, docs){
redisPraiseLog.get(ent_code, userId, 'thread', function(error, docs) {
var list = docs;
list.push(tid);
redisPraiseLog.set(ent_code,userId,'thread',list, function(){});
redisPraiseLog.set(ent_code, userId, 'thread', list, function() {});
});
forumThreadService.getThreadById(tid, function(err, doc) {
......@@ -513,15 +553,15 @@ router.post('/thread/:tid/cancelRaise', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
//更新点赞redis
redisPraiseLog.get(ent_code,userId,'thread', function(error, docs){
redisPraiseLog.get(ent_code, userId, 'thread', function(error, docs) {
var list = docs;
for (var i = 0; i < list.length; i++) {
if (list[i].toString() == tid){
list.splice(i,1);
if (list[i].toString() == tid) {
list.splice(i, 1);
break;
}
}
redisPraiseLog.set(ent_code,userId,'thread',list, function(){});
redisPraiseLog.set(ent_code, userId, 'thread', list, function() {});
});
forumThreadService.getThreadById(tid, function(err, doc) {
......@@ -626,14 +666,14 @@ router.post('/thread/:tid/share', function(req, res, next) {
//新增文章评论
router.post('/thread/:tid/comment/add', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
if(isProhibition){
} else {
if (isProhibition) {
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
} else {
var tid = req.params.tid || null;
if (tid) {
var integral = req.session.openUser.integral || 0;
......@@ -675,7 +715,7 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
callback(err, null);
} else {
// callback(null, count);
if(count){
if (count) {
entity.floor = count + 1;
}
//4.创建文章评论
......@@ -683,15 +723,15 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
if (err) {
callback(err, null);
} else {
try{
if(user.getMobileUser(req).toString() != thread.from._id.toString()){//文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code,thread.from._id);
forumThreadAttendService.threadAttend(thread._id,user.getMobileUser(req),function(err){});
try {
if (user.getMobileUser(req).toString() != thread.from._id.toString()) { //文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code, thread.from._id);
forumThreadAttendService.threadAttend(thread._id, user.getMobileUser(req), function(err) {});
}
}catch(e){
} catch (e) {
console.log(e);
}
forumAboutMEService.saveCommentLevel1(thread,newComment);
forumAboutMEService.saveCommentLevel1(thread, newComment);
var comments = thread.comments;
var array = [];
if (comments && comments.items && comments.items.length > 0) {
......@@ -731,11 +771,11 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag) {
if (err) {
console.error(err);
}else{
if(!flag){
} else {
if (!flag) {
httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'comment');
}
}
......@@ -772,14 +812,14 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
//新增文章评论
router.post('/thread/:tid/comment/create', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
if(isProhibition){
} else {
if (isProhibition) {
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
} else {
var tid = req.params.tid || null;
if (tid) {
var integral = req.session.openUser.integral || 0;
......@@ -822,7 +862,7 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
callback(err, null);
} else {
// callback(null, count);
if(count){
if (count) {
entity.floor = count + 1;
}
//4.创建文章评论
......@@ -830,16 +870,16 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
if (err) {
callback(err, null);
} else {
try{
if(user.getMobileUser(req).toString() != thread.from._id.toString()){//文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code,thread.from._id);
forumThreadAttendService.threadAttend(thread._id,user.getMobileUser(req),function(err){});
try {
if (user.getMobileUser(req).toString() != thread.from._id.toString()) { //文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code, thread.from._id);
forumThreadAttendService.threadAttend(thread._id, user.getMobileUser(req), function(err) {});
}
}catch(e){
} catch (e) {
console.log(e);
}
forumAboutMEService.saveCommentLevel1(thread,newComment);
forumAboutMEService.saveCommentLevel1(thread, newComment);
var comments = thread.comments;
var array = [];
if (comments && comments.items && comments.items.length > 0) {
......@@ -880,11 +920,11 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag) {
if (err) {
console.error(err);
}else{
if(!flag){
} else {
if (!flag) {
httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'comment');
}
}
......@@ -949,14 +989,14 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
//新建文章评论的子评论
router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionOfSpeech(userId, function(err, isProhibition) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
if(isProhibition){
} else {
if (isProhibition) {
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
} else {
var tid = req.params.tid || null;
var cid = req.params.cid || null;
if (tid && cid) {
......@@ -995,15 +1035,15 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
if (err) {
callback(err, null);
} else {
try{
if(user.getMobileUser(req).toString() != req.body.to.toString()){//被评论人 和评论人不是同一个
commentTips.incrTips(req.session.user.ent_code,req.body.to);
forumThreadAttendService.threadAttend(tid,user.getMobileUser(req),function(err){});
try {
if (user.getMobileUser(req).toString() != req.body.to.toString()) { //被评论人 和评论人不是同一个
commentTips.incrTips(req.session.user.ent_code, req.body.to);
forumThreadAttendService.threadAttend(tid, user.getMobileUser(req), function(err) {});
}
}catch(e){
} catch (e) {
console.log(e);
}
forumAboutMEService.saveCommentLevel2(tid,comment,newComment);
forumAboutMEService.saveCommentLevel2(tid, comment, newComment);
var comments = comment.comments;
var array = [];
if (comments && comments.length > 0) {
......@@ -1037,11 +1077,11 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag){
if(err){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userId, function(err, flag) {
if (err) {
console.error(err);
}else{
if(!flag){
} else {
if (!flag) {
httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'reply');
}
}
......@@ -1081,26 +1121,26 @@ router.post('/thread/:tid/comment/:cid/disable', function(req, res, next) {
tid = req.params.tid,
cid = req.params.cid;
if (tid && cid) {
forumCommentService.getCommentById(cid,function(err,comment){
if(comment && user_id){
if(comment.from.toString() == user_id.toString()){
forumCommentService.changeStatus(cid,2,function(err,update){
forumCommentService.getCommentById(cid, function(err, comment) {
if (comment && user_id) {
if (comment.from.toString() == user_id.toString()) {
forumCommentService.changeStatus(cid, 2, function(err, update) {
if (err) {
res.json(returnCode.BUSY);
} else {
if(comment && comment.level==1){
forumAboutMEService.updateCommentLevel1Status(comment._id,2);
if (comment && comment.level == 1) {
forumAboutMEService.updateCommentLevel1Status(comment._id, 2);
}
if(comment && comment.level==2){
forumAboutMEService.updateCommentLevel2Status(comment._id,2);
if (comment && comment.level == 2) {
forumAboutMEService.updateCommentLevel2Status(comment._id, 2);
}
res.json(returnCode.SUCCESS);
}
});
}else{
} else {
res.json(returnCode.ACTION_NOT_PERMISSION);
}
}else{
} else {
res.json(returnCode.WRONG_PARAM);
}
});
......@@ -1155,7 +1195,7 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) {
//评论列表
router.get('/thread/:tid/comment/list', function(req, res, next) {
var tid=req.params.tid || null;
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
......@@ -1175,14 +1215,15 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
redisPraiseLog.get(ent_code,user.getMobileUser(req),'comment', function(error, docs){
_.forEach(results.items, function(d,i) {
if(results.items[i].toObject){
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'comment', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if(results.items[i]._id == docs[k]){
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
......@@ -1190,6 +1231,7 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
});
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
} else {
......@@ -1232,14 +1274,15 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
redisPraiseLog.get(ent_code,user.getMobileUser(req),'comment', function(error, docs){
_.forEach(results.items, function(d,i) {
if(results.items[i].toObject){
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'comment', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if(results.items[i]._id == docs[k]){
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
......@@ -1248,6 +1291,7 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
results.total = count;
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
}
......@@ -1298,7 +1342,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
});
},
function(callback) {
if(doc){
if (doc) {
//4.更新点赞日志
forumPraiseLogService.updatePraiseLog(doc._id, 0, function(err, result) {
if (err) {
......@@ -1307,7 +1351,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
callback(null, null);
}
});
}else{
} else {
var entity = {
ent_code: req.session.user.ent_code,
user: user.getMobileUser(req),
......@@ -1315,7 +1359,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
ip: req.ip,
comment: cid,
type: 2,
status :0
status: 0
};
//4.创建点赞日志
forumPraiseLogService.createPraiseLog(entity, function(err, result) {
......@@ -1343,10 +1387,10 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
// });
//更新点赞redis
redisPraiseLog.get(ent_code,userId,'comment', function(error, docs){
redisPraiseLog.get(ent_code, userId, 'comment', function(error, docs) {
var list = docs;
list.push(cid);
redisPraiseLog.set(ent_code,userId,'comment',list, function(){});
redisPraiseLog.set(ent_code, userId, 'comment', list, function() {});
});
......@@ -1434,15 +1478,15 @@ router.post('/thread/:tid/comment/:cid/cancelRaise', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
//更新点赞redis
redisPraiseLog.get(ent_code,userId,'comment', function(error, docs){
redisPraiseLog.get(ent_code, userId, 'comment', function(error, docs) {
var list = docs;
for (var i = 0; i < list.length; i++) {
if (list[i].toString() == cid){
list.splice(i,1);
if (list[i].toString() == cid) {
list.splice(i, 1);
break;
}
}
redisPraiseLog.set(ent_code,userId,'comment',list, function(){});
redisPraiseLog.set(ent_code, userId, 'comment', list, function() {});
});
//返回点赞总数
forumCommentService.getCommentById(cid, function(err, doc) {
......@@ -1525,7 +1569,9 @@ router.get('/thread/:tid/topics', function(req, res, next) {
ent_code: req.session.user.ent_code,
pid: tid,
type: 2,
status:{$ne:3}
status: {
$ne: 3
}
};
if (tid) {
......@@ -1580,8 +1626,15 @@ router.get('/thread/:tid/latestPhotos', function(req, res, next) {
ent_code: req.session.user.ent_code,
pid: tid,
type: 3,
status:{$ne:3},
images: {$exists: true, $not: {$size: 0}}
status: {
$ne: 3
},
images: {
$exists: true,
$not: {
$size: 0
}
}
};
if (tid) {
......@@ -1635,8 +1688,15 @@ router.get('/thread/:tid/hotPhotos', function(req, res, next) {
ent_code: req.session.user.ent_code,
pid: tid,
type: 3,
status:{$ne:3},
images: {$exists: true, $not: {$size: 0}}
status: {
$ne: 3
},
images: {
$exists: true,
$not: {
$size: 0
}
}
};
if (tid) {
......@@ -1686,21 +1746,21 @@ router.post('/thread/:tid/disable', function(req, res, next) {
var user_id = user.getMobileUser(req);
var tid = req.params.tid;
if (tid) {
forumThreadService.getThreadById(tid,function(err,thread){
if(thread.from && user_id){
if(thread.from._id.toString() == user_id.toString()){
forumThreadService.getThreadById(tid, function(err, thread) {
if (thread.from && user_id) {
if (thread.from._id.toString() == user_id.toString()) {
forumThreadService.logicDeleteThreadById(tid, function(err, flag) {
if (err) {
res.json(returnCode.BUSY);
} else {
forumAboutMEService.updateThreadStatus(tid,3);
forumAboutMEService.updateThreadStatus(tid, 3);
res.json(returnCode.SUCCESS);
}
});
}else{
} else {
res.json(returnCode.ACTION_NOT_PERMISSION);
}
}else{
} else {
res.json(returnCode.WRONG_PARAM);
}
})
......
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