Commit 0c25731d authored by 刘文胜's avatar 刘文胜

Merge remote-tracking branch 'remotes/origin/newfunc_0510_forum_management' into SANDBOX

parents 4c5514d2 e930587b
'use strict';
//插件
var router = require('express').Router(),
returnCode = require('../../utils/returnCode'),
_ = require('lodash'),
then = require('thenjs'),
moment = require('moment'),
mongoose = require('mongoose'),
async = require('async');
//模型
var ForumThread = mongoose.model('ForumThread'),
ForumComment = mongoose.model('ForumComment'),
ForumPVLog = mongoose.model('ForumPVLog'),
ForumFollowThread = mongoose.model('ForumFollowThread');
//服务
var forumThreadService = require('../../service/forumThreadService'),
forumUserService = require('../../service/forumUserService'),
forumCommentService = require('../../service/forumCommentService'),
forumAboutMEService = require('../../service/forumAboutMEService');
module.exports = function(app) {
app.use('/admin/forum', router);
};
//格式化日期 (格式:年-月-日)
function date_format(date) {
return moment(date).format('YYYY-MM-DD HH:mm:ss');
}
//文章列表
router.get('/threadManagement/threads/list', function(req, res, next) {
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var infoId = req.query.infoId;
var tagId = req.query.tagId;
var pid = req.query.pid;//父文章id
var content = req.query.content;//标题 或 内容
var type = req.query.type;//1普通文章,话题,照片墙
var nickName = req.query.nickName;
var mid = req.query.mid;
var begin_time=req.query.begin_time;
var end_time=req.query.end_time;
var tab = req.query.tab;//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
var asc = req.query.asc?1:-1;
var sortBy = {//默认排序
created:asc
};
if(req.query.sort){//指定排序字段
sortBy = ({}[req.query.sort] = asc);
}
var conditions = {
ent_code: req.session.user.ent_code,
level: 1,
status: {
$ne: 3
}
};
if (infoId) {
conditions.info = infoId;
}
if (tagId) {
conditions.tag = {
$in: [tagId]
};
}
if (pid) {
conditions.pid = pid;
conditions.level = 2;
}
if (content) {
conditions.$or = [
{
title:{
$regex: content,
$options: 'i'
}
},
{
content:{
$regex: content,
$options: 'i'
}
}
];
}
if (type) {
conditions.type = Number(type);
}
if(tab){
if(tab === 'admin'){//官方贴
conditions.isPublishByBg = 1;
}
else if(tab === 'new_recommend'){//推荐贴
conditions.new_recommend = 1;
}
else if(tab === 'top'){//置顶贴
conditions.top = 1;
}
else if(tab === 'recommend'){//加精贴
conditions.recommend = 1;
}
else if(tab === 'event'){//活动贴
conditions.isEvent = 1;
}
else if(tab === 'closed'){//屏蔽贴
conditions.status = 0;
}
}
if(begin_time && end_time){
conditions.created = {$gte : begin_time, $lte : end_time};
} else if(end_time){
conditions.created = {$lte : end_time};
} else if(begin_time){
conditions.created = {$gte : begin_time};
}
var callback = function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if (pid) {
forumThreadService.getById(pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
}
};
if (mid) {
forumThreadService.getAllThreadByFidAndMid(mid, conditions, pageNo, pageSize, sortBy, callback);
} else if (nickName) {
forumThreadService.getAllThreadByFidAndNickName(nickName, conditions, pageNo, pageSize, sortBy, callback);
} else {
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, sortBy, callback);
}
});
//获取帖子总数,帖子数,用户发帖数,帖子加精数
router.get('/threadManagement/threads/statistics', function(req, res, next) {
var infoId = req.query.infoId;
var tagId = req.query.tagId;
var pid = req.query.pid;//父文章id
var content = req.query.content;//标题 或 内容
var type = req.query.type;//1普通文章,话题,照片墙
var nickName = req.query.nickName;
var mid = req.query.mid;
var begin_time=req.query.begin_time;
var end_time=req.query.end_time;
var tab = req.query.tab;//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
var conditions = {
ent_code: req.session.user.ent_code,
level: 1,
status: {
$ne: 3
}
};
if (infoId) {
conditions.info = infoId;
}
if (tagId) {
conditions.tag = {
$in: [tagId]
};
}
if (pid) {
conditions.pid = pid;
conditions.level = 2;
}
if (content) {
conditions.$or = [
{
title:{
$regex: content,
$options: 'i'
}
},
{
content:{
$regex: content,
$options: 'i'
}
}
];
}
if (type) {
conditions.type = Number(type);
}
if(tab){
if(tab === 'admin'){//官方贴
conditions.isPublishByBg = 1;
}
else if(tab === 'new_recommend'){//推荐贴
conditions.new_recommend = 1;
}
else if(tab === 'top'){//置顶贴
conditions.top = 1;
}
else if(tab === 'recommend'){//加精贴
conditions.recommend = 1;
}
else if(tab === 'event'){//活动贴
conditions.isEvent = 1;
}
else if(tab === 'closed'){//屏蔽贴
conditions.status = 0;
}
}
if(begin_time && end_time){
conditions.created = {$gte : begin_time, $lte : end_time};
} else if(end_time){
conditions.created = {$lte : end_time};
} else if(begin_time){
conditions.created = {$gte : begin_time};
}
async.parallel([function(cb){//获取帖子总数
var _conditions = {
ent_code: req.session.user.ent_code,
status: {
$ne: 3
}
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_total',count || 0]);
});
},function(cb){//获取帖子数
var _conditions = _.assign({}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
},function(cb){//获取用户发帖数
var _conditions = _.assign({isPublishByBg:{$ne:1}}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
},function(cb){//获取加精帖子数
var _conditions = _.assign({recommend:1}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
}],function(err,results){
if(err){
console.log(err);
return res.json(returnCode.BUSY);
}
// 数组转对象_.zipObject([[‘fred‘, 30], [‘barney‘, 40]]);→ { ‘fred‘: 30, ‘barney‘: 40 }
res.json(_.assign({
data:_.zipObject(results)
}, returnCode.SUCCESS));
});
});
//批量屏蔽帖子
router.post('/threadManagement/threads/batchclose', function(req, res, next) {
var ent_code = req.session.user.ent_code;
var ids = req.body.ids;
if(!ent_code || !ids){
return res.json(returnCode.BUSY);
}
forumThreadService.batchClose(ent_code,ids,function(err,result){
if(err){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
//批量删除帖子
router.post('/threadManagement/threads/batchdel', function(req, res, next) {
var ent_code = req.session.user.ent_code;
var ids = req.body.ids;
if(!ent_code || !ids){
return res.json(returnCode.BUSY);
}
forumThreadService.batchLogicDelete(ent_code,ids,function(err,result){
if(err){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
function updateComemntStatus(ent_code,id,status,cb){
if(!ent_code || !id){
return cb && cb(null,true);
}
var cid = id;
async.waterfall([
function(callback) {
//获取评论实例
forumCommentService.getCommentById(cid, callback);
},
function(comment, callback) {
//更新评论状态
forumCommentService.updateCommentStatusById(cid, status, function(err, update) {
callback(err, comment);
});
},
function(comment, callback) {
if (comment && comment.level == 1) {
forumAboutMEService.updateCommentLevel1Status(comment._id, status);
}
if (comment && comment.level == 2) {
forumAboutMEService.updateCommentLevel2Status(comment._id, status);
}
//是否删除评论
if (status == 2) {
if (comment.level == 1) {//一级评论,需要移除文章的comments里的cid,并且评论数-1
forumThreadService.updateThreadById(comment.thread, {
$pull:{
comments:cid
},
$inc: {
comment_count: -1
}
}, function(err, result) {
if(err){
console.log(err);
}
callback();
});
} else {//二级评论,移除父级评论的comments里的cid
forumCommentService.getCommentParent(cid, function(err, p_comment) {
if(err || !p_comment){
console.log(err);
}else{
forumCommentService.updateCommentById(p_comment._id, {
$pull:{
comments:cid
},
$inc: {
comment_count: -1
}
}, function(err, update) {
if(err){
console.log(err);
}
});
}
callback();
});
}
} else {
callback();
}
}
], function(err, restult) {
if (err) {
console.error(err);
}
cb(err,!!!err);
});
}
function batchUpdateCommentStatus(ent_code,ids,status,callback){
if(!ent_code || !ids){
return callback && callback('参数错误');
}
var tasks = [];
_.forEach(ids,function(id){
task.push(function(cb){
updateComemntStatus(ent_code,id,status,function(err,result){
cb();
})
});
});
async.parallel(tasks,function(err,results){
return callback && callback(err,!!!err);
});
}
//批量屏蔽帖子的评论
router.post('/threadManagement/threads/:id/comment/batchclose', function(req, res, next) {
var ent_code = req.session.user.ent_code;
var id = req.params.id;//帖子id
var ids = req.body.ids;//评论id数组
var closed_status = 0;
if(!ent_code || !id || !ids){
return res.json(returnCode.BUSY);
}
//获取有效的评论id数组
ForumComment.find({ent_code:ent_code,thread:id,_id:{
$in:ids
}}).select('_id').exec(function(err, docs) {
if(err){
return res.json(returnCode.BUSY);
}
if(!docs || docs.length == 0){
return res.json(_.assign({data:true}, returnCode.SUCCESS));
}
var available_ids = [];
_.forEach(docs,function(doc){
available_ids.push(doc._id);
});
batchUpdateCommentStatus(ent_code,available_ids,closed_status,function(err,result){
if(err){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
});
//批量删除帖子的评论
router.post('/threadManagement/threads/:id/comment/batchdel', function(req, res, next) {
var ent_code = req.session.user.ent_code;
var id = req.params.id;//帖子id
var ids = req.body.ids;//评论id数组
var delete_status = 2;
if(!ent_code || !id || !ids){
return res.json(returnCode.BUSY);
}
//获取有效的评论id数组
ForumComment.find({ent_code:ent_code,thread:id,_id:{
$in:ids
}}).select('_id').exec(function(err, docs) {
if(err){
return res.json(returnCode.BUSY);
}
if(!docs || docs.length == 0){
return res.json(_.assign({data:true}, returnCode.SUCCESS));
}
var available_ids = [];
_.forEach(docs,function(doc){
available_ids.push(doc._id);
});
batchUpdateCommentStatus(ent_code,available_ids,delete_status,function(err,result){
if(err){
return res.json(returnCode.BUSY);
}
return res.json(_.assign({data:true}, returnCode.SUCCESS));
});
});
});
//查询评论列表
router.get('/threadManagement/threads/:tid/comment/search', function(req, res, next) {
var tid = req.params.tid || null,
pageNo = req.query.pageNo || 1,
pageSize = req.query.pageSize || 10,
mid = req.query.mid,
floor_start = req.query.floor_start,
floor_end = req.query.floor_end,
content = req.query.content || '';
var conditions = {
ent_code: req.session.user.ent_code,
thread: tid,
level:1,
};
if (content) {
conditions.content = {
$regex: content,
$options: 'i'
};
}
if(floor_start){
conditions.floor = {
$gte:floor_start
};
}
if(floor_end){
conditions.floor = {
$lte:floor_end
};
}
if (tid && mid) {
forumCommentService.getCommentListByMid(mid, conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
});
} else if(tid){
forumCommentService.getAllComment(conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.log(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//查询帖子的收藏数
router.get('/threadManagement/threads/:tid/collects', function(req, res, next) {
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
var conditions = {
ent_code: ent_code,
thread: tid
};
if (tid && ent_code) {
ForumFollowThread.count(conditions, function(err, count) {
if (err) {
res.json(returnCode.BUSY);
} else {
res.json(_.assign({data:(count||0)}, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//查询帖子的子文章数
router.get('/threadManagement/threads/:tid/subtotal', function(req, res, next) {
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
var conditions = {
ent_code: ent_code,
pid: tid,
status:1
};
if (tid && ent_code) {
ForumThread.count(conditions, function(err, count) {
if (err) {
res.json(returnCode.BUSY);
} else {
res.json(_.assign({data:(count||0)}, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//查询(话题/照片墙)的参与人数
router.get('/threadManagement/threads/:tid/joined/total', function(req, res, next) {
var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code;
if (tid && ent_code) {
ForumThread.aggregate({
$match: {
ent_code: ent_code,
pid: mongoose.Types.ObjectId(tid)
}
}, {
$group: {
_id: {
from: '$from'
},
count: {
$sum: 1
}
}
}, function(err, data) {
if (err) {
res.json(returnCode.BUSY);
} else {
res.json(_.assign({data:((data && data.length)||0)}, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
\ No newline at end of file
...@@ -490,8 +490,234 @@ router.get('/sharev2.js', function(req, res, next) { ...@@ -490,8 +490,234 @@ router.get('/sharev2.js', function(req, res, next) {
} }
desc = thread.content?thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):''; desc = thread.content?thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):'';
// 分享图标:帖子带图片则使用第一张图片,否则使用发帖者的头像 // 分享图标:帖子设置了share_pic就使用share_pic ,否则帖子带图片则使用第一张图片,否则使用发帖者的头像
if(thread.images && thread.images[0]){ if(thread.share_pic){
imgUrl = thread.share_pic;
}else if(thread.images && thread.images[0]){
imgUrl = thread.images[0].urlFileName;
}else{
imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon;
}
link += baseParamsUrl;
//获取分享设置
if (thread.share_type!==2) {
//文章默认分享
getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}else if(thread.share){
getWXV2(res, thread.share.title, thread.share.description, link, thread.share.icon, mid,ent_code,thread._id,type,thread);
} else {
getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}
}
}).fail(function(cont, err) {
console.error(err);
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
});
}else{
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
}
}
});
router.get('/sharev3.js', function(req, res, next) {
//记录分享日志
var _v = new Date().getTime();//用于sharelog 版本号
var share_log = {_v:_v};
req.session.shareLog = {_v:_v};//新的分享对象
console.log('forumshare 1',req.session.shareLog);
var rs = {},
type = req.query.type,
id = req.query.id,
uId= req.session.mobileForumUser.userId,
ent_code = req.session.user.ent_code,
mid = req.session.openUser.mid,
link = '/app/forum/' + ent_code + '/index_v3?pageUrl=';
var title = '',desc = '',imgUrl = '';
var key = ent_code + 'forum_share_index_info_v3';
if(type && type === 'index'){
var expire = 60 * 60;
redis.get(key, function(error, share){
if(share){//有缓存
try{
share = JSON.parse(share);
title=share.title;
desc=share.desc;
link=share.linkUrl;
imgUrl=share.imgUrl;
if(link.indexOf('?') === -1){
link = link + '?uId='+ uId;
}else{
link = link + '&uId='+ uId;
}
}catch(err){
console.log(err);
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null,true);
}else{
then.parallel([
function(cont){
link = link + 'newindex';
cont();
},function(cont){
request.get({url:config.rest_api+'/v1.0/internal/forum/config/share/byentcode?entCode='+ent_code,body:{},json:true}, function (e, r, result) {
if(result && result.data){
try{
var obj = JSON.parse(result.data);
title = obj.shareTitle || '';
desc = obj.shareDescription || '';
imgUrl = obj.sharePictureUrl || '';
}catch(err){
console.log(err);
}
}
cont();
});
}
]).then(function(cont, datas) {
//放入redis缓存
redis.set(key,JSON.stringify({
title:title,
desc:desc,
linkUrl:link,
imgUrl:imgUrl
}),function(){
redis.expire(key, expire);
});
if(link.indexOf('?') === -1){
link = link + '?uId='+ uId;
}else{
link = link + '&uId='+ uId;
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null,true);
}).fail(function(cont, err) {
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
});
}
});
}else{
//板块微信接口
if(!type || !id){
console.error('请求参数错误')
res.json(_.assign({result:false},returnCode.WRONG_PARAM));
}else if(type === 'notice'){
Notice.findOne({_id:id},function(err,result){
if (err || !result) {
console.error(err);
res.json(_.assign({result:false},returnCode.BUSY));
}
link = link + 'noticeDetail&infoId=' + (result.plate || '') + '&ent_code=' + ent_code + '&tId=' + result._id +'&uId='+uId;
title = result.title;
desc = result.content?result.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):'';
redis.get(key, function(error, share){
if(share){//有缓存
try{
share = JSON.parse(share);
imgUrl=share.imgUrl;
}catch(err){
console.log(err);
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}else{
request.get({url:config.rest_api+'/v1.0/internal/forum/config/share/byentcode?entCode='+ent_code,body:{},json:true}, function (e, r, result) {
if(result.data){
try{
var obj = JSON.parse(result.data);
imgUrl = obj.sharePictureUrl || '';
}catch(err){
console.log(err);
}
}
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
});
}
});
});
}else if (type === 'Info') {
forumInfoService.getInfoById(id, function(err, forumInfo) {
if (err) {
console.error(err);
res.json(_.assign({result:false},returnCode.BUSY));
}else{
//分享记录对象
share_log.type = 2;
share_log.info = id;
//替换分享log内容
if(!req.session.shareLog || !req.session.shareLog._v || _v >= req.session.shareLog._v){
console.log('forumshare 2',share_log);
req.session.shareLog = share_log;
}
if(forumInfo.share_type && forumInfo.share_type == 1){
var shareInfo = forumInfo.share || {};
title = shareInfo.title,desc = shareInfo.description,imgUrl = shareInfo.icon;
}else{
title = forumInfo.name,desc = forumInfo.description,imgUrl = forumInfo.icon;
}
link = link + 'index&infoId='+ id+'&uId='+uId;
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}
});
}else if (type === 'Thread') {
then(function(cont) {
//获得文章
forumThreadService.getThreadByIdSimple({_id:id},cont);
}).then(function(cont, thread) {
if(!thread){
//文章不存在
cont('分享文章不存在');
}else{
share_log.type = 3;
share_log.thread = id;
share_log.p_thread = thread.pid;
share_log.info = thread.info._id || thread.info;
share_log.thread_type = thread.pid?4:thread.type;
//替换分享log内容
if(!req.session.shareLog || !req.session.shareLog._v || _v >= req.session.shareLog._v){
console.log('forumshare 3',share_log);
req.session.shareLog = share_log;
}
//组装分享路径与判断分享类型
var baseParamsUrl = '&infoId=' + thread.info._id + '&ent_code=' + ent_code + '&tId=' + thread._id +'&uId='+uId;
var share_type = '';
switch(thread.type){
case 1://文章
link = link + 'detail';
share_type = 'article';
title = thread.title == '发话题'?"":thread.title;
break;
case 2://话题
if(thread.level === 2){
link += 'detail';
share_type = 'article';
title = thread.pid.title;
}else if(thread.level === 1){
link += 'topic';
share_type = 'topic';
title = thread.title;
}
break;
case 3://照片墙
if(thread.level === 2){
link += 'photoDetail';
share_type = 'photo';
title = thread.pid.title;
}else if(thread.level === 1){
link += 'photoWall';
share_type = 'photo';
title = thread.title;
}
break;
}
desc = thread.content?thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"").replace(/\t/g,"").replace(/\n/g,""):'';
// 分享图标:帖子设置了share_pic就使用share_pic ,否则帖子带图片则使用第一张图片,否则使用发帖者的头像
if(thread.share_pic){
imgUrl = thread.share_pic;
}else if(thread.images && thread.images[0]){
imgUrl = thread.images[0].urlFileName; imgUrl = thread.images[0].urlFileName;
}else{ }else{
imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon; imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon;
......
...@@ -78,8 +78,11 @@ var ForumThreadSchema = new Schema({ ...@@ -78,8 +78,11 @@ var ForumThreadSchema = new Schema({
comments: [{type: Schema.Types.ObjectId, ref: 'ForumComment'}], //评论内容列表 comments: [{type: Schema.Types.ObjectId, ref: 'ForumComment'}], //评论内容列表
images: {//文章图片列表 images: {//文章图片列表
type : Array type : Array
}, },
share: { //自定义分享 share_pic:{//帖子分享图标
type: String
},
share: { //自定义分享(已弃用,后台管理没有设置的页面了)
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
ref: 'ForumShare' ref: 'ForumShare'
}, },
......
...@@ -6,6 +6,7 @@ var ForumShare = mongoose.model('ForumShare'); ...@@ -6,6 +6,7 @@ var ForumShare = mongoose.model('ForumShare');
var forumUserService = require('./forumUserService'); var forumUserService = require('./forumUserService');
var forumCommentService = require('./forumCommentService'); var forumCommentService = require('./forumCommentService');
var forumAboutMEService = require('./forumAboutMEService');
var async = require('async'); var async = require('async');
var then = require('thenjs'); var then = require('thenjs');
...@@ -1140,6 +1141,32 @@ exports.updateThreadRaiseCount = function(threadId, callback) { ...@@ -1140,6 +1141,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) { exports.updateThreadRaiseCountDec = function(threadId, callback) {
// ForumThread.update({ // ForumThread.update({
......
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