Commit 2741cdb0 authored by strong's avatar strong

Merge commit '240eb72e'

parents ff853633 240eb72e
'use strict';
var express = require('express'),
router = express.Router(),
returnCode = require('../../utils/returnCode'),
_ = require('lodash');
var mongoose = require('mongoose');
var ForumHonorTitle = mongoose.model('ForumHonorTitle');
var forumHonorTitleService=require('../../service/forumHonorTitleService');
module.exports = function(app) {
app.use('/admin/forum', router);
};
//新增
router.post('/honorTitle/create', function(req, res, next) {
var rs = {};
req.body.ent_code=req.session.user.ent_code;
forumHonorTitleService.create(req.body,function(err,entity){
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
rs.data = {'id':entity._id};
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
});
//删除
router.post('/honorTitle/:id/delete', function(req, res, next) {
var id=req.params.id;
if(id){
forumHonorTitleService.deleteById(id,function(err,entity){
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
}else{
res.json(returnCode.WRONG_PARAM);
}
});
//更新
router.post('/honorTitle/:id/update', function(req, res, next) {
var id=req.params.id;
var entity = req.body;
if(id && entity){
forumHonorTitleService.updateById(id,entity,function(err,entity){
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
}else{
res.json(returnCode.WRONG_PARAM);
}
});
//获取
router.get('/honorTitle/:id/get', function(req, res, next) {
var id = req.params.id || null;
var rs = {};
if (id) {
forumHonorTitleService.getById(id,function(err,entity){
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
rs.data = entity;
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//直接修改序号
router.put('/honorTitle/orderIDX/:id/:order', function(req, res, next) {
var id=req.params.id;
var idx=req.params.order;
forumHonorTitleService.updateIdx(id,idx,function(err,result){
if(err || !result){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
//上移
router.put('/honorTitle/moveUP/:id/:order', function(req, res, next) {
var id=req.params.id;
var idx=req.params.order;
var titleName=req.query.titleName || '';
var conditions={
ent_code:req.session.user.ent_code
};
if(tagName){
conditions.title={
$regex: titleName,
$options: 'i'
};
}
forumHonorTitleService.getAllOrderIDX(conditions,function(err,results){
if(err){
return res.json(returnCode.BUSY);
}
var index=-1;
_.forEach(results,function(r,i){
if(r._id.toString() === id.toString()){
index=i;
}
});
if(index === -1){
return res.json(returnCode.BUSY);
}
var preObj=results[index-1];
if(!preObj){
return res.json(returnCode.BUSY);
}
var preidx=preObj.order_idx;
if(preidx.toString() === idx.toString()){
preidx = Number(preidx)+1;
}
forumHonorTitleService.updateIdx(id,preidx,function(err,result){
if(err || !result){
return res.json(returnCode.BUSY);
}
forumHonorTitleService.updateIdx(preObj._id,idx,function(err,result){
if(err || !result){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
});
});
//查询列表
router.get('/honorTitle/searchList', function(req, res, next) {
var pageNo = req.query.pageNo || 1,
pageSize = req.query.pageSize || 10,
titleName=req.query.titleName || '';
var conditions={
ent_code:req.session.user.ent_code
};
if(titleName){
conditions.title={
$regex: titleName,
$options: 'i'
};
}
forumHonorTitleService.getAll(conditions,pageNo,pageSize,function(err,results){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
res.json(_.assign(results, returnCode.SUCCESS));
}
});
});
//获取状态为启用的
router.get('/honorTitle/list', function(req, res, next) {
var conditions={
ent_code:req.session.user.ent_code,
status:1
};
forumHonorTitleService.find(conditions, function(err,results){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
var rs = {
data:results
};
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
});
......@@ -65,6 +65,11 @@ router.post('/member/searchMembers', function(req, res, next) {
if (search.status) {
q.status = search.status;
}
if (search.honorTitleId) {
q.honorTitles = {
$in: [search.honorTitleId]
};
}
forumUserService.searchMembersAndLimitActions(pageNo, pageSize, q, function(err, results) {
if (err) {
console.error(err);
......@@ -136,3 +141,21 @@ router.get('/member/getMidByUid/:uid', function(req, res, next) {
});
}
});
//更新
router.post('/member/:mid/update', function(req, res, next) {
var mid=req.params.mid;
var entity = req.body;
if(mid && entity){
forumUserService.updateUserById(mid,entity,function(err,result){
if(err){
res.json(returnCode.BUSY);
}else{
res.json(returnCode.SUCCESS);
}
});
}else{
res.json(returnCode.WRONG_PARAM);
}
});
\ No newline at end of file
......@@ -326,7 +326,8 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
var tid = req.params.tid,
fid = req.params.fid,
ent_code = req.session.user.ent_code,
mid = req.body.mid; //板块ID
thread_from_id = req.body.thread_from_id;
mid = req.body.mid;
if (tid && fid) {
forumThreadService.updateRecommendByThreadId(tid, function(err, thread) {
if (err) {
......@@ -334,19 +335,24 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
if (mid) {
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(tid, function(err, flag) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
} else {
if (flag) {
if(thread_from_id){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(thread_from_id, function(err, flag) {
if (err) {
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
} else {
httpService.sendRequest(ent_code, mid, 'thread_recomment');
res.json(returnCode.SUCCESS);
if (flag) {
res.json(returnCode.PROHIBITION_OF_SPEECH);
} else {
httpService.sendRequest(ent_code, mid, 'thread_recomment');
res.json(returnCode.SUCCESS);
}
}
}
});
});
}else{
httpService.sendRequest(ent_code, mid, 'thread_recomment');
res.json(returnCode.SUCCESS);
}
} else {
res.json(returnCode.SUCCESS);
}
......@@ -387,6 +393,7 @@ router.get('/threads/list', function(req, res, next) {
var nickName = req.query.nickName;
var mid = req.query.mid;
var quality = req.query.quality;
var new_recommend = req.query.new_recommend;
var conditions = {
ent_code: req.session.user.ent_code,
......@@ -425,6 +432,11 @@ router.get('/threads/list', function(req, res, next) {
if (quality) {
conditions.quality = quality;
}
if (new_recommend) {
conditions.new_recommend = new_recommend;
}
if (mid) {
forumThreadService.getAllThreadByFidAndMid(mid, conditions, pageNo, pageSize, null, function(err, results) {
if (err) {
......@@ -1538,8 +1550,6 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
});
});
//更新文章质量
router.post('/thread/:tid/quality', function(req, res, next) {
var tid = req.params.tid; //文章ID
......@@ -1560,3 +1570,57 @@ router.post('/thread/:tid/quality', function(req, res, next) {
res.json(returnCode.WRONG_PARAM);
}
});
//文章推荐
router.post('/thread/:tid/essence', function(req, res, next) {
var tid = req.params.tid
var ent_code = req.session.user.ent_code;
if (tid) {
var condition = {
_id: tid,
ent_code: ent_code
};
var entity = {
new_recommend: 1,
new_recommend_time: new Date()
};
forumThreadService.updateThread(condition, entity, function(err, doc) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//文章取消推荐
router.post('/thread/:tid/unEssence', function(req, res, next) {
var tid = req.params.tid; //文章ID
var ent_code = req.session.user.ent_code;
if (tid) {
var condition = {
_id: tid,
ent_code: ent_code
};
var entity = {
new_recommend: 0,
new_recommend_time: null
};
forumThreadService.updateThread(condition, entity, function(err, doc) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(returnCode.SUCCESS);
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
\ No newline at end of file
......@@ -17,6 +17,8 @@ router.get('/commentTips', function(req, res, next) {
if(err){
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.setHeader('Cache-Control', 'private, max-age=600'); // 私有缓存一个10分钟
res.setHeader('Expires', new Date(Date.now() + 600000).toUTCString());
res.json(_.assign({data:result}, returnCode.SUCCESS));
}
});
......
......@@ -37,6 +37,8 @@ router.get('/info/list/all', function(req, res, next) {
res.json(returnCode.BUSY);
} else {
rs.data = datas.items;
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
......@@ -66,18 +68,13 @@ router.get('/info/:fid/get', function(req, res, next) {
if (fid) {
var source = req.session.mobileForumUser.source;
httpService.createLog(req, source, fid, 2);
async.waterfall([
forumInfoService.updateInfoPvCount(fid, function(err, result) {
if (err) {
console.error(err);
}
});
async.parallel([
function(callback) {
//更新浏览数
forumInfoService.updateInfoPvCount(fid, function(err, result) {
if (err) {
callback(err, null);
} else {
callback(null, null);
}
});
},
function(data, callback) {
forumInfoService.getInfoById(fid, function(err, info) {
if (err) {
callback(err, null);
......@@ -86,25 +83,25 @@ router.get('/info/:fid/get', function(req, res, next) {
}
});
},
function(info, callback) {
function(callback) {
forumThreadService.getAllCountByFid({
info: fid
}, function(err, threadCount) {
if (err) {
callback(err, null, null);
callback(err, null);
} else {
callback(null, info, threadCount);
callback(null, threadCount);
}
});
}
], function(err, info, threadCount) {
], function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
var rs = {};
rs.data = info;
rs.data.threadCount = threadCount;
rs.data = results[0].toObject();
rs.data.threadCount = results[1];
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
......@@ -667,6 +664,8 @@ router.get('/info/:fid/tags', function(req, res, next) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign(results, returnCode.SUCCESS));
}
});
......
......@@ -42,15 +42,13 @@ function moderatorOperateLog(forumUser,thread,type){
function addIntegral(thread){
var openID=thread.from.uid;
var tid= thread._id;
var userID=thread.from._id;
var ent_code= thread.ent_code;
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(tid, function(err, flag){
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(userID, function(err, flag){
if(!err && !flag){
//获取mid
console.log(API_ADDRESS);
request.get({url:API_ADDRESS+'/v1.0/internal/member/getMidbyOpenID?entCode='
+ent_code+'&openID='+openID,json:true},function(e,r,res){
console.log(res);
if(res && res.data){
httpService.sendRequest(ent_code,res.data,'thread_recomment');
}
......@@ -74,6 +72,8 @@ router.get('/moderators/plates', function(req, res, next) {
if(result && result.infoIds){
items = result.infoIds;
}
res.setHeader('Cache-Control', 'public, max-age=3600'); // 公共缓存一个小时
res.setHeader('Expires', new Date(Date.now() + 3600000).toUTCString());
res.json(_.assign({items:items}, returnCode.SUCCESS));
});
});
......
......@@ -518,20 +518,16 @@ router.get('/thread/:tid/get', function(req, res, next) {
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
if (tid) {
async.waterfall([
async.waterfall([
function(callback) {
forumThreadService.updateThreadPvCount(tid, function(err, doc) {
forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙
if (err) {
callback(err, null);
} else {
callback(null, null);
callback(null, thread);
}
});
},
function(data, callback) {
forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙
var info_id = thread.info._id,
pid = thread.pid,
source = req.session.mobileForumUser.source;
......@@ -543,15 +539,12 @@ router.get('/thread/:tid/get', function(req, res, next) {
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);
}
}
});
forumThreadService.updateThreadPvCount(tid, function(err, doc) {
if (err) {
callback(err, null);
} else {
callback(null, thread);
}
console.error(err);
}
});
},
], function(err, thread) {
......@@ -672,7 +665,6 @@ router.post('/thread/:tid/delete', function(req, res, next) {
}
});
//文章点赞
router.post('/thread/:tid/raise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
......@@ -1785,3 +1777,27 @@ router.post('/thread/:tid/disable', function(req, res, next) {
res.json(returnCode.WRONG_PARAM);
}
});
//获取推荐文章
router.get('/thread/getThreadWithEssence', function(req, res, next) {
var pageNo = req.query.pageNo || 1,
pageSize = req.query.pageSize || 10,
ent_code = req.session.user.ent_code;
if (pageNo && pageSize) {
var q = {
ent_code: ent_code,
new_recommend: 1
};
forumThreadService.findThread(pageNo, pageSize, q, '-new_recommend_time', function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
}
res.json(_.assign(result, returnCode.SUCCESS));
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
\ No newline at end of file
'use strict';
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
//荣誉头衔
var ForumHonorTitleSchema = new Schema({
ent_code: {
type: Number,
require: true,
index: true
},
title: { //荣誉头衔标题
type: String,
require: true,
},
icon: { //荣誉头衔图片
type: String
},
order_idx: { //荣誉头衔排序
type: Number,
require: true,
default: 0
},
status: { //荣誉头衔状态,1启用,0停用
type: Number,
require: true,
default: 1
},
is_show: { //显示荣誉头衔状态,1显示,0不显示
type: Number,
require: true,
default: 1
},
created: {
type: Date,
required: true,
default:Date.now
}
}, {
'collection': 'pisns_forum_honor_title'
});
module.exports = mongoose.model('ForumHonorTitle', ForumHonorTitleSchema);
\ No newline at end of file
......@@ -118,6 +118,14 @@ var ForumThreadSchema = new Schema({
require: true,
default: 100
},
new_recommend : { //推荐 0否,1是
type: Number,
require: true,
default: 0
},
new_recommend_time:{//推荐时间
type: Date
},
created: {
type: Date,
required: true,
......
......@@ -52,6 +52,10 @@ var ForumUserSchema = new Schema({
require: true,
default: 1
},
honorTitles: [{ //荣誉头衔数组
type: Schema.Types.ObjectId,
ref: 'ForumHonorTitle'
}],
created: {
type: Date,
required: true,
......
......@@ -4,6 +4,18 @@ var ForumComment = mongoose.model('ForumComment');
var forumUserService = require('./forumUserService');
var async = require('async');
var listCommentFields = {
from:1,
content:1,
level:1,
floor:1,
praise_count:1,
comment_count:1,
comments:1,
status:1
};
//创建评论
exports.createComment = function(entity, callback) {
var forum = new ForumComment(entity);
......@@ -125,7 +137,7 @@ exports.getAllComment = function(conditions, pageNo, pageSize, callback) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions).populate('from').populate('to').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
ForumComment.find(conditions,listCommentFields).populate('from','uid mid nickName icon exp').populate('to','uid mid nickName icon exp').limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
......
'use strict';
var mongoose = require('mongoose');
var ForumHonorTitle = mongoose.model('ForumHonorTitle');
//创建
exports.create=function(entity,callback){
var forum = new ForumHonorTitle(entity);
forum.save(function(err, doc) {
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,doc);
}
});
};
//根据ID获取
exports.getById=function(tid,callback){
ForumHonorTitle.findById(tid, function(err, doc) {
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,doc);
}
});
};
//根据ID更新
exports.updateById=function(tid,entity,callback){
ForumHonorTitle.update({ _id: tid}, entity,null,function(err,result){
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,null);
}
});
};
//根据ID删除
exports.deleteById=function(tid,callback){
ForumHonorTitle.remove({ _id: tid},function(err,result){
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,null);
}
});
};
//获取数量
function countAll(conditions,callback) {
ForumHonorTitle.count(conditions, function (err, count) {
if(err){
console.error(err);
callback(err,null);
}else{
callback(null,count);
}
});
}
//分页查询
exports.getAll= function(conditions,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);
ForumHonorTitle.find(conditions, null, {skip:skip,limit:limit,sort:{order_idx:-1}},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.find=function(conditions,callback){
ForumHonorTitle.find(conditions).sort({order_idx:-1}).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,docs);
}
});
};
exports.getAllOrderIDX=function(conditions,callback){
ForumHonorTitle.find(conditions).select('_id order_idx').sort({order_idx:-1}).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err,null);
} else {
callback(null,docs);
}
});
};
//修改序号
exports.updateIdx=function(id,idx,callback){
ForumHonorTitle.update(
{_id:id},
{ order_idx: idx },
null,
function(err,result){
if(err){
console.error(err);
callback(err,null);
}else{
callback(null,true);
}
});
};
......@@ -10,6 +10,128 @@ var forumCommentService = require('./forumCommentService');
var async = require('async');
var then = require('thenjs');
var listThreadFields = {
content:1,
type:1,
title:1,
pid:1,
from:1,
created:1,
recommend:1,
praise_count:1,
comment_count:1,
images:1,
comments:1,
level:1,
top:1,
tag:1,
tag_top:1,
pv_count:1,
address:1
};
var singleThreadFields = {
content:1,
type:1,
title:1,
pid:1,
info:1,
from:1,
created:1,
recommend:1,
praise_count:1,
comment_count:1,
images:1,
level:1,
top:1,
tag:1,
tag_top:1,
pv_count:1,
address:1
};
var subThreadFields = {
from:1
};
/**
* 过滤 html 标签正则
* @type {RegExp}
*/
var htmlElReg = /<[^>]*>/ig;
/**
* 过滤表情正则
* @type {RegExp}
*/
var emElReg = /\【em_([0-9]*)\】/ig;
/**
* 帖子内容处理函数
* @param {String} content 原始帖子内容
* @return {String} 处理完的帖子
*/
function handleContent(content) {
content = content || "";
content = content
.replace(htmlElReg, "")
.replace(emElReg, "");
if (content.length > 200) {
content = content.substr(0, 200) + "……";
}
return content.trim();
}
function findOneAndUpdate(id, entity, callback) {
ForumThread.findOneAndUpdate(id, entity, function(err, doc) {
callback(err, doc);
});
};
//根据发帖者分页查询话题列表
exports.findThread = function(pageNo, pageSize, q, sort, callback) {
then(function(cont) {
ForumThread.find(q).count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
var sortBy = '-created';
if (sort) {
sortBy = sort;
}
ForumThread.find(q).populate('from').populate('info').skip(skip).limit(limit).sort(sortBy).exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
var rsJson = {
pageNo:pageNo,
pageSize:pageSize,
total: count,
items: threads
};
callback(null, rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err, rsJson);
});
};
//根据发帖者分页查询话题列表
exports.findThreadByPage = function(pageNo, pageSize, q, callback) {
then(function(cont) {
......@@ -21,7 +143,7 @@ exports.findThreadByPage = function(pageNo, pageSize, q, callback) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
}).then(function(cont, count, threads) {
var rsJson = {
result: true,
total: count,
......@@ -135,129 +257,145 @@ exports.getByConditions = function(conditions, callback) {
}
//根据ID获取文章
exports.getThreadById = function(tid, callback) {
async.parallel([
function(cb) {
var conditions = {
_id: tid
};
ForumThread.findOne(conditions).populate('from').populate('info').populate('share').exec(function(err, doc) {
if (err) {
console.error(err);
callback(err, null);
} else {
cb(null, doc);
}
});
},
function(cb) {
var conditions = {
thread: tid,
level: '1'
// status:1
};
//获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
if (err) {
console.log(err);
cb(err, null);
} else {
cb(null, results);
}
});
},
function(cb) {
//获取话题子文章列表
var conditions = {
pid: tid,
type: 2,
status:1
};
getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
// console.log(threads);
cb(null, threads);
}
});
},
function(cb) {
//获取照片墙最新文章列表
var conditions = {
pid: tid,
type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}}
};
getAllThreadByFidHelp(conditions, 1, 10, '-created', function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
cb(null, threads);
}
});
},
function(cb) {
//获取照片墙最热文章列表
var conditions = {
pid: tid,
type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}}
};
getAllThreadByFidHelp(conditions, 1, 10, '-praise_count', function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
cb(null, threads);
}
});
},
function(cb) {
//获取发帖人数
ForumThread.aggregate({
$match: {
pid: mongoose.Types.ObjectId(tid)
}
}, {
$group: {
_id: {
from: '$from'
},
count: {
$sum: 1
}
}
}, function(err, data) {
if (err) {
cb(err, null);
} else {
cb(null, data.length);
}
});
}
], function(err, results) {
ForumThread.findOne({_id: tid}).populate('from','uid mid nickName icon exp').populate('info','name icon').populate('share').exec(function(err, doc) {
if (err) {
console.error(err);
callback(err, null);
} else {
var thread = results[0];
var comments = results[1];
var subThreads = results[2] || []; //话题子文章列表
var latestPhotos = results[3] || []; //最新照片墙列表
var hotPhotos = results[4] || []; //最热照片墙列表
var canyuPeopleCount = results[5] || 0; //参与人数
var threadObj = thread && thread.toObject() || {};
threadObj.comments = comments;
threadObj.subThreads = subThreads;
threadObj.latestPhotos = latestPhotos;
threadObj.hotPhotos = hotPhotos;
threadObj.canyuPeopleCount = canyuPeopleCount;
if (doc) {
async.parallel([
function(cb) {
if (doc.type !== 1) {
cb(null, null);
return;
}
var conditions = {
thread: tid,
level: '1'
// status:1
};
//获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
if (err) {
console.log(err);
cb(err, null);
} else {
cb(null, results);
}
});
},
function(cb) {
//获取话题子文章列表
if (doc.type !== 2) {
cb(null, null);
return;
}
var conditions = {
pid: tid,
type: 2,
status:1
};
getAllThreadByFidHelp(conditions, 1, 10, null, function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
// console.log(threads);
cb(null, threads);
}
});
},
function(cb) {
//获取照片墙最新文章列表
if (doc.type !== 3) {
cb(null, null);
return;
}
var conditions = {
pid: tid,
type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}}
};
getAllThreadByFidHelp(conditions, 1, 10, '-created', function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
cb(null, threads);
}
});
},
function(cb) {
//获取照片墙最热文章列表
if (doc.type !== 3) {
cb(null, null);
return;
}
var conditions = {
pid: tid,
type: 3,
status:1,
images: {$exists: true, $not: {$size: 0}}
};
getAllThreadByFidHelp(conditions, 1, 10, '-praise_count', function(err, threads) {
if (err) {
console.error(err);
cb(err, null);
} else {
cb(null, threads);
}
});
},
function(cb) {
//获取发帖人数
ForumThread.aggregate({
$match: {
pid: mongoose.Types.ObjectId(tid)
}
}, {
$group: {
_id: {
from: '$from'
},
count: {
$sum: 1
}
}
}, function(err, data) {
if (err) {
cb(err, null);
} else {
cb(null, data.length);
}
});
}
], function(err, results) {
if (err) {
callback(err, null);
} else {
var thread = doc;
var comments = results[0] || [];
var subThreads = results[1] || []; //话题子文章列表
var latestPhotos = results[2] || []; //最新照片墙列表
var hotPhotos = results[3] || []; //最热照片墙列表
var canyuPeopleCount = results[4] || 0; //参与人数
var threadObj = thread && thread.toObject() || {};
threadObj.comments = comments;
threadObj.subThreads = subThreads;
threadObj.latestPhotos = latestPhotos;
threadObj.hotPhotos = hotPhotos;
threadObj.canyuPeopleCount = canyuPeopleCount;
callback(null, threadObj);
}
});
callback(null, threadObj);
} else {
callback(null, {});
}
}
});
};
......@@ -582,6 +720,7 @@ function populateSubComment(subComments, callback) {
//获取数量
function countAllByFid(conditions, callback) {
// callback(null, 21);
ForumThread.count(conditions, function(err, count) {
if (err) {
console.error(err);
......@@ -611,7 +750,7 @@ function getSubThreads(doc, sort, callback) {
if (sort) {
sortBy = sort;
}
ForumThread.find(conditions).populate('from').sort(sortBy).exec(function(err, docs) {
ForumThread.find(conditions, subThreadFields).populate('from', 'icon').sort(sortBy).exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
......@@ -642,8 +781,8 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) {
if (sort) {
sortBy = sort;
}
ForumThread.find(conditions).populate('from').populate('info').populate({
path: 'tag'
ForumThread.find(conditions).populate('from', 'uid mid nickName icon').populate('info','name icon pv_count').populate({
path: 'tag',select: 'title pv_count'
}).populate({
path: 'comments',
options: {
......@@ -662,7 +801,6 @@ function getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback) {
obj.pageNo = pageNo;
obj.pageSize = pageSize;
obj.items = docs;
if (docs && docs.length > 0) {
var asyncTasks = [];
......@@ -710,8 +848,8 @@ function getAllThreadByFidHelpNoLimit(conditions, pageNo, pageSize, sort, callba
if (sort) {
sortBy = sort;
}
ForumThread.find(conditions).populate('from').populate('info').populate({
path: 'tag'
ForumThread.find(conditions).populate('from','uid mid nickName icon').populate('info','name icon pv_count').populate({
path: 'tag',select: 'title pv_count'
}).populate({
path: 'comments',
options: {
......@@ -774,6 +912,7 @@ exports.getAllThreadByFidNoLimit = function(conditions, pageNo, pageSize, sort,
//获取全部列表数据
exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callback) {
getAllThreadByFidHelp(conditions, pageNo, pageSize, sort, callback);
};
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
......@@ -1027,8 +1166,8 @@ function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, so
if (sort) {
sortBy = sort;
}
ForumThread.find(conditions).populate('from').populate('info').populate({
path: 'tag'
ForumThread.find(conditions, listThreadFields).populate('from','uid mid nickName icon').populate('info','name icon pv_count').populate({
path: 'tag', select: 'title pv_count'
}).populate({
path: 'comments',
options: {
......
......@@ -3,8 +3,6 @@ var mongoose = require('mongoose');
var ForumUser = mongoose.model('ForumUser');
var then = require('thenjs');
var async = require('async');
// var forumLimitActionRefService = require('../service/forumLimitActionRefService');
// var forumLimitActionConfigService = require('../service/forumLimitActionConfigService');
var forumLimitOperationService = require('../service/forumLimitOperationService');
......@@ -23,7 +21,11 @@ exports.createUser=function(entity,callback){
//根据Uid获取用户
exports.getUserByUid=function(uid,callback){
ForumUser.findOne({uid:uid}).exec(function(err,result){
ForumUser.findOne({uid:uid}).populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err,result){
if(err){
callback(err,null);
}else{
......@@ -38,7 +40,11 @@ exports.getUserByUid=function(uid,callback){
//根据id获取用户
exports.getUserById=function(id,callback){
ForumUser.findOne({_id:id}).exec(function(err,result){
ForumUser.findOne({_id:id}).populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err,result){
if(err){
callback(err,null);
}else{
......@@ -70,7 +76,11 @@ exports.searchMembers=function(pageNo, pageSize, q, callback){
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumUser.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
ForumUser.find(q).skip(skip).limit(limit).sort('-created').populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, members) {
......@@ -98,7 +108,11 @@ exports.searchMembersByNickName=function(nickName, callback){
{displayName : { $regex: nickName, $options: 'i' }}
]
};
ForumUser.find(name).exec(function(err,result){
ForumUser.find(name).populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err,result){
if(err){
callback(err,null);
}else{
......@@ -109,7 +123,11 @@ exports.searchMembersByNickName=function(nickName, callback){
//根据mid查询用户
exports.searchMembersByMid=function(mid, callback){
ForumUser.find({mid:mid}).exec(function(err,result){
ForumUser.find({mid:mid}).populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err,result){
if(err){
callback(err,null);
}else{
......@@ -125,7 +143,11 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumUser.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
ForumUser.find(q).skip(skip).limit(limit).sort('-created').populate({
path: 'honorTitles',
match: { status: { $ne: 0 }},
options: { sort:{order_idx:-1} }
}).exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, members) {
......
......@@ -21,7 +21,7 @@ module.exports = function(app, config) {
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(compress());
// app.use(compress());
app.use(cookieParser());
app.use(methodOverride());
app.use(multiparty());
......
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