Commit b720115f authored by strong's avatar strong

Merge commit '088f47d6'

parents d33c609a 088f47d6
...@@ -3,6 +3,7 @@ var express = require('express'), ...@@ -3,6 +3,7 @@ var express = require('express'),
router = express.Router(), router = express.Router(),
returnCode = require('../../utils/returnCode'), returnCode = require('../../utils/returnCode'),
moment = require('moment'), moment = require('moment'),
mongoose = require('mongoose'),
_ = require('lodash'), _ = require('lodash'),
then = require('thenjs'); then = require('thenjs');
...@@ -86,7 +87,7 @@ router.get('/message/:mid/get', function(req, res, next) { ...@@ -86,7 +87,7 @@ router.get('/message/:mid/get', function(req, res, next) {
var userID = user.getMobileUser(req); var userID = user.getMobileUser(req);
if(mid){ if(mid){
var condition = { var condition = {
_id: mid _id: new mongoose.Types.ObjectId(mid)
} }
async.parallel([ async.parallel([
function(cb) { function(cb) {
...@@ -154,8 +155,8 @@ router.post('/message/:mid/unShowMsg', function(req, res, next) { ...@@ -154,8 +155,8 @@ router.post('/message/:mid/unShowMsg', function(req, res, next) {
var mid = req.params.mid || null; var mid = req.params.mid || null;
var userID = user.getMobileUser(req); var userID = user.getMobileUser(req);
if(mid && userID){ if(mid && userID){
//更新用户的消息状态为未读 //更新用户的消息状态为未读
forumMessageService.updateUserMessageStatus({_id:userID}, mid, 2, function(err, result) { forumMessageService.updateUserMessageStatus({_id:userID}, mid, 2, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
...@@ -164,6 +165,25 @@ router.post('/message/:mid/unShowMsg', function(req, res, next) { ...@@ -164,6 +165,25 @@ router.post('/message/:mid/unShowMsg', function(req, res, next) {
} }
}); });
}else{ }else{
res.json(returnCode.WRONG_PARAM); res.json(returnCode.WRONG_PARAM);
}
});
//用户清空消息(修改状态)
router.post('/message/cleanAll', function(req, res, next) {
//消息参数
var userID = user.getMobileUser(req);
if(userID){
//更新用户的消息状态为未读
forumMessageService.updateUserMessageStatus({_id:userID}, null, 2, function(err, result) {
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
...@@ -36,8 +36,6 @@ function create(req, callback) { ...@@ -36,8 +36,6 @@ function create(req, callback) {
entity.pid = null; entity.pid = null;
} }
var address = entity.address || null; var address = entity.address || null;
if (address) { if (address) {
entity.address = JSON.parse(address); entity.address = JSON.parse(address);
...@@ -72,13 +70,16 @@ function create(req, callback) { ...@@ -72,13 +70,16 @@ function create(req, callback) {
type: 3, type: 3,
level: '2', level: '2',
pid: entity.pid, pid: entity.pid,
from: entity.from from: entity.from,
status: {$ne:3}
}, function(err, doc) { }, function(err, doc) {
if (doc) { if (doc) {
var update = { var update = {
$set: { $set: {
images: entity.images, images: entity.images,
content: entity.content content: entity.content,
tag: entity.tag,
address: entity.address
} }
}; };
forumThreadService.updateThreadById(doc._id, update, function(err, updatedDoc) { forumThreadService.updateThreadById(doc._id, update, function(err, updatedDoc) {
...@@ -531,10 +532,9 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -531,10 +532,9 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (tid) { if (tid) {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
forumThreadService.getThreadById(tid, function(err, thread) { forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙 //文章类型 1、文章 2、话题 3、照片墙
if (err) { if (err || !thread) {
callback(err, null); callback(err, null);
} else { } else {
callback(null, thread); callback(null, thread);
...@@ -619,13 +619,14 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -619,13 +619,14 @@ router.get('/thread/:tid/get', function(req, res, next) {
//获取目标论坛文章 //获取目标论坛文章
router.get('/thread/photo/:pid/get', function(req, res, next) { router.get('/thread/photo/:pid/get', function(req, res, next) {
var pid = req.params.pid || null, var pid = req.params.pid || null,
userId = req.session.mobileForumUser.userId;; userId = user.getMobileUser(req);
if (pid) { if (pid) {
forumThreadService.getByConditions({ forumThreadService.getByConditions({
type: 3, type: 3,
level: '2', level: '2',
pid: pid, pid: pid,
from: userId from: userId,
status: {$ne:3}
}, function(err, thread) { }, function(err, thread) {
if (err) { if (err) {
console.error(err); console.error(err);
...@@ -1769,52 +1770,12 @@ router.post('/thread/:tid/disable', function(req, res, next) { ...@@ -1769,52 +1770,12 @@ router.post('/thread/:tid/disable', function(req, res, next) {
} }
}); });
//获取推荐文章 //旧的,无用 2016/1/29日后请删除
router.get('/thread/getThreadWithEssence_old', function(req, res, next) {
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var infoId = req.query.infoId || null;
var sort = '-new_recommend_time';
var ent_code = req.session.user.ent_code;
var today = new Date();
var conditions = {
ent_code: ent_code,
level: 1,
status: 1,
new_recommend: 1,
$or: [{
isEvent: 0
}, {
isEvent: null
}, {
isEvent: 1,
'event.eventStartTime' : {$lte : today}
}]
};
if(infoId){
conditions.info = infoId;
}
queryThread(conditions, pageNo, pageSize, sort, function(err, results){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
util.loadLevel(ent_code, results.items, function() {
handleThreadList(req, results, ent_code, function(result){
res.json(_.assign(result, returnCode.SUCCESS));
});
});
}
});
});
//查询帖子列表数据,不获取评论,话题获取参与用 //查询帖子列表数据,不获取评论,话题获取参与用
router.get('/thread/getThreadWithNotPopulateComment', function(req, res, next) { router.get('/thread/getThreadWithNotPopulateComment', function(req, res, next) {
var pageNo = req.query.pageNo || 1; var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10; var pageSize = req.query.pageSize || 10;
var infoId = req.query.infoId || null; var infoId = req.query.infoId || null;
var tagId = req.query.tagId || null;
var sort = '-_id'; var sort = '-_id';
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
var today = new Date(); var today = new Date();
...@@ -1834,6 +1795,9 @@ router.get('/thread/getThreadWithNotPopulateComment', function(req, res, next) { ...@@ -1834,6 +1795,9 @@ router.get('/thread/getThreadWithNotPopulateComment', function(req, res, next) {
if(infoId){ if(infoId){
conditions.info = infoId; conditions.info = infoId;
} }
if(tagId){
conditions.tag={$in:[tagId]};
}
queryThread(conditions, pageNo, pageSize, sort, function(err, results){ queryThread(conditions, pageNo, pageSize, sort, function(err, results){
if(err){ if(err){
console.error(err); console.error(err);
...@@ -1979,3 +1943,46 @@ function handleThreadList(req, results, ent_code, callback){ ...@@ -1979,3 +1943,46 @@ function handleThreadList(req, results, ent_code, callback){
}); });
} }
//新圈子首页帖子列表 最热
router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, next) {
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var infoId = req.query.infoId || null;
var tagId = req.query.tagId || null;
var sort = '-top -topTime -_id';
var ent_code = req.session.user.ent_code;
var today = new Date();
var conditions = {
ent_code: ent_code,
level: 1,
status: 1,
$or: [{
isEvent: 0
}, {
isEvent: null
}, {
isEvent: 1,
'event.eventStartTime' : {$lte : today}
}]
};
if(infoId){
conditions.info = infoId;
}
if(tagId){
sort = "-tag_top -tag_topTime -_id";
conditions.tag={$in:[tagId]};
}
queryThread(conditions, pageNo, pageSize, sort, function(err, results){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
util.loadLevel(ent_code, results.items, function() {
handleThreadList(req, results, ent_code, function(result){
res.json(_.assign(result, returnCode.SUCCESS));
});
});
}
});
});
\ No newline at end of file
...@@ -193,8 +193,10 @@ exports.getMessages= function(conditions, status, pageNo, pageSize, callback) { ...@@ -193,8 +193,10 @@ exports.getMessages= function(conditions, status, pageNo, pageSize, callback) {
} }
} }
var total = messages.length; var total = messages.length;
var skip = (pageNo - 1) * pageSize; var skip = pageNo * pageSize;
var limit = total - skip > pageSize ? pageSize : (total - skip); var limit = total - skip > pageSize ? pageSize : (total - skip);
limit = parseInt(limit) + parseInt(skip);
//获取分页后的数组 //获取分页后的数组
messages = messages.slice(skip,limit); messages = messages.slice(skip,limit);
callback(null,total,messages); callback(null,total,messages);
...@@ -210,14 +212,20 @@ exports.updateUserMessageStatus= function(condition,msgID, status,callback) { ...@@ -210,14 +212,20 @@ exports.updateUserMessageStatus= function(condition,msgID, status,callback) {
console.error(err); console.error(err);
callback(err,null); callback(err,null);
}else{ }else{
for(var i in docs){ if(!msgID){
if (docs[i].msg == msgID) { for(var i in docs){
if (docs[i].toObject) { docs[i].status = status;
docs[i] = docs[i].toObject(); }
} else {
for(var i in docs){
if (docs[i].msg == msgID) {
if (docs[i].toObject) {
docs[i] = docs[i].toObject();
}
docs[i].status = status;
break;
} }
docs[i].status = status; }
break;
}
} }
//更新用户 //更新用户
ForumUser.update(condition, {messages:docs},null,function(err,result){ ForumUser.update(condition, {messages:docs},null,function(err,result){
......
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