Commit 627a03c4 authored by strong's avatar strong

Merge commit '11b32e95'

# Conflicts:
#	app/service/forumCommentService.js
#	app/service/forumThreadService.js
parents 937eb9a3 11b32e95
......@@ -24,7 +24,8 @@ var forumThreadService = require('../../service/forumThreadService'),
forumLimitOperationService = require('../../service/forumLimitOperationService'),
forumAboutMEService = require('../../service/forumAboutMEService'),
httpService = require('../../service/httpService'),
redisThreadList = require('../../utils/redisThreadList');
redisThreadList = require('../../utils/redisThreadList'),
forumFollowThreadService = require('../../service/forumFollowThreadService');
var userUtil = require('../../utils/user');
var MemoryCache = require('../../utils/simpleCache');
......@@ -115,7 +116,8 @@ router.post('/thread/create', function(req, res, next) {
} else {
forumAboutMEService.saveThread(entity);
rs.data = {
'id': entity._id
'id': entity._id,
'ent_code' : ent_code
};
res.json(_.assign(rs, returnCode.SUCCESS));
}
......@@ -141,7 +143,8 @@ router.post('/thread/create', function(req, res, next) {
} else {
forumAboutMEService.saveThread(entity);
rs.data = {
'id': entity._id
'id': entity._id,
'ent_code' : ent_code
};
res.json(_.assign(rs, returnCode.SUCCESS));
}
......@@ -157,6 +160,7 @@ router.post('/thread/create', function(req, res, next) {
router.get('/thread/:tid/get', function(req, res, next) {
var uid = req.session.user.id;
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
var rs = {};
if (tid) {
async.waterfall([
......@@ -172,7 +176,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
function(thread, callback) {
if (thread && thread.info && thread.info._id) {
forumTagService.getAllTag({
ent_code: req.session.user.ent_code,
ent_code: ent_code,
info: thread.info._id
}, 1, 100, function(err, results) {
if (err) {
......@@ -191,7 +195,32 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (err) {
callback(err, null);
} else {
datas.push(results)
datas.push(results);
callback(null, datas);
}
});
},
function(datas, callback) { //获取EXP
if(datas[0].from.mid){
userUtil.getMemberExp(ent_code, datas[0].from.mid, 3, function(err, results) {
if (err) {
callback(err, null);
} else {
datas.push(results)
callback(null, datas);
}
});
}else{
datas.push({})
callback(null, datas);
}
},
function(datas, callback) { //获取收藏数
forumFollowThreadService.count({thread: tid, ent_code: ent_code}, function(err, result){
if (err) {
callback(err, null);
} else {
datas.push(result);
callback(null, datas);
}
});
......@@ -210,6 +239,8 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (results[0].pid) {
forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0];
rs.data.from.exp = results[3] && results[3].allExp ? results[3].allExp : 0;
rs.data.followCount = results[4] ? results[4] : 0;
rs.tagList = results[1];
rs.parentThread = parentThread;
rs.isSameAuthor = isSameAuthor;
......@@ -217,6 +248,8 @@ router.get('/thread/:tid/get', function(req, res, next) {
});
} else {
rs.data = results[0];
rs.data.from.exp = results[3] && results[3].allExp ? results[3].allExp : 0;
rs.data.followCount = results[4] ? results[4] : 0;
rs.tagList = results[1];
rs.isSameAuthor = isSameAuthor;
res.json(_.assign(rs, returnCode.SUCCESS));
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -78,8 +78,11 @@ var ForumThreadSchema = new Schema({
comments: [{type: Schema.Types.ObjectId, ref: 'ForumComment'}], //评论内容列表
images: {//文章图片列表
type : Array
},
share: { //自定义分享
},
share_pic:{//帖子分享图标
type: String
},
share: { //自定义分享(已弃用,后台管理没有设置的页面了)
type: Schema.Types.ObjectId,
ref: 'ForumShare'
},
......
......@@ -230,6 +230,40 @@ exports.getAllCommentWithThreeeChildrenComment = function(conditions, pageNo, pa
});
};
exports.getAllCommentOrderBy = function(conditions,orderBy, pageNo, pageSize, callback) {
countAll(conditions, function(err, count) {
if (err) {
console.error(err);
callback(err, null);
} else {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
var sort = {
created:-1
};
if(orderBy){
sort = orderBy;
}
ForumComment.find(conditions,listCommentFields).populate({
path: 'from',
select: 'uid mid nickName icon exp honorTitles'
}).populate('to','uid mid nickName icon exp').limit(limit).skip(skip).sort(sort).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var obj = {};
obj.total = count;
obj.pageNo = pageNo;
obj.pageSize = pageSize;
obj.items = docs;
callback(null, obj);
}
});
}
});
};
//评论
function populateComment(doc, callback) {
if (doc && doc.comments.length > 0) {
......@@ -483,6 +517,54 @@ exports.getCommentListByMid = function(mid,conditions, pageNo, pageSize, callbac
};
exports.getCommentListByMidOrderBy = function(mid,conditions,orderBy, pageNo, pageSize, callback) {
//查询到用户
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户的文章
var user_ids = [];
for(var i in users){
user_ids.push(users[i]._id);
}
conditions.from = {
$in:user_ids
}
countAll(conditions, function(err, count) {
if (err) {
callback(err);
} else {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
var sort = {
created:-1
};
if(orderBy){
sort = orderBy;
}
ForumComment.find(conditions).populate('from').populate('to').limit(limit).skip(skip).sort(sort).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var obj = {};
obj.total = count;
obj.pageNo = pageNo;
obj.pageSize = pageSize;
obj.items = docs;
callback(null, obj);
}
});
}
});
}
});
};
exports.getCommentParent = function(cid, callback) {
ForumComment.findOne({
comments: {
......
......@@ -6,6 +6,7 @@ var ForumShare = mongoose.model('ForumShare');
var forumUserService = require('./forumUserService');
var forumCommentService = require('./forumCommentService');
var forumAboutMEService = require('./forumAboutMEService');
var async = require('async');
var then = require('thenjs');
......@@ -329,21 +330,29 @@ exports.getThreadById = function(tid, callback) {
},
function(cb) {
//获取话题子文章列表
if (doc.type !== 2) {
var conditions ={}
if(doc.type == 2){
conditions = {
pid: tid,
type: 2,
status:1
};
}else if(doc.type == 3){
conditions = {
pid: tid,
type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}}
};
}else{
cb(null, null);
return;
}
var conditions = {
pid: tid,
type: 2,
status:1
};
getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) {
getAllThreadByFidHelp(conditions, 1, 999999, null, function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
// console.log(threads);
cb(null, threads);
}
});
......@@ -1309,6 +1318,32 @@ exports.updateThreadRaiseCount = function(threadId, callback) {
});
};
//批量屏蔽帖子
exports.batchClose = function(ent_code,ids, callback) {
var status_closed = 0;
update({ent_code:ent_code,_id: {$in:ids}}, {status:status_closed}, { multi: true }, 'updateRedisRecommentThreads',function(err, result) {
callback(err, !!!err);
if(!err){
_.forEach(ids,function(id){
forumAboutMEService.updateThreadStatus(id, status_closed);
});
}
});
};
//批量删除
exports.batchLogicDelete = function(ent_code,ids, callback) {
var status_deleted = 3;
update({ent_code:ent_code,_id: {$in:ids}}, {status:status_deleted}, { multi: true }, 'updateRedisRecommentThreads',function(err, result) {
callback(err, !!!err);
if(!err){
_.forEach(ids,function(id){
forumAboutMEService.updateThreadStatus(id, status_deleted);
});
}
});
};
//减少文章点赞数
exports.updateThreadRaiseCountDec = function(threadId, callback) {
// ForumThread.update({
......
......@@ -3,6 +3,15 @@
var _ = require('lodash');
var loadUserLevel = require('./loadUserLevel');
var async=require('async');
var request = require('request');
var env = process.env.NODE_ENV;
var API_ADDRESS = 'http://rest.wxpai.cn';
if (env == 'sandbox') {
API_ADDRESS = 'http://rest.wxpai.cn';
} else if (env == 'production') {
API_ADDRESS = 'https://rest.wxpai.cn';
}
exports.loadLevel=function(ent_code,items,callback){
var openIds = [];
......@@ -27,7 +36,7 @@ exports.loadLevel=function(ent_code,items,callback){
var tasks = [];
_.forEach(openIds, function(open_id) {
tasks.push(function(cont){
loadUserLevel.loadLevelFromAPI(ent_code,open_id,cont);
loadLevelFromAPI(ent_code,open_id,cont);
});
});
async.parallel(tasks,function(err,results){
......@@ -111,4 +120,21 @@ exports.loadLevelByUser=function(ent_code,items,callback){
}
return callback && callback();
});
};
function loadLevelFromAPI(ent_code,open_id,callback){
if(!ent_code || !open_id){
return callback && callback(null,null);
}
var url = API_ADDRESS + '/v1.0/internal/member/exp/byopenid?openId='+open_id+'&entCode='+ent_code;
request.get({
url: url,
json: {}
}, function(e, r, body) {
if (e) {
console.log(e)
}
return callback && callback(null,(body && body.data) || null);
});
};
\ No newline at end of file
......@@ -43,7 +43,8 @@ var config = {
service:'http://sandbox.wxpai.cn',
port: 3011,
mongodb: {
uri: 'mongodb://114.215.206.32:27018/pisns-forum-sandbox',
//uri: 'mongodb://114.215.206.32:27018/pisns-forum-sandbox',
uri: 'mongodb://10.161.234.251:27018/pisns-forum-sandbox',
username: '',
password: '',
poolSize: 5
......
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