Commit 27630325 authored by 陈志良's avatar 陈志良

Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development

parents 72d9328c e9c1ede1
'use strict';
var express = require('express'),
router = express.Router(),
returnCode = require('../../utils/returnCode'),
_ = require('lodash');
var mongoose = require('mongoose');
var forumUserService=require('../../service/forumUserService');
var forumThreadService=require('../../service/forumThreadService');
var async=require('async');
var user=require('../../utils/user');
module.exports = function(app) {
app.use('/admin/forum', router);
};
//验证用户身份
router.post('/user/identifyUser',function(req,res,next){
var entity=req.body;
req.session.mobileForumUser=null;
if(!req.session.mobileForumUser){
forumUserService.getUserByUid(entity.uid,function(err,doc){
if(err){
console.log(err);
res.json('error');
}else{
if(doc){
req.session.mobileForumUser={
userId:doc._id,
openId:doc.uid
};
res.json('success');
}else{
forumUserService.createUser(entity,function(err,doc){
if(err){
console.log(err);
res.json('error');
}else{
req.session.mobileForumUser={
userId:doc._id,
openId:doc.uid
};
res.json('success');
}
});
}
}
});
}else{
res.json('success');
}
});
\ No newline at end of file
...@@ -42,8 +42,6 @@ router.post('/thread/create', function(req, res, next) { ...@@ -42,8 +42,6 @@ router.post('/thread/create', function(req, res, next) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}else{ }else{
if(user){ if(user){
//put forumUser to session
userUtil.setUserSession(req,user);
req.body.from=user._id; req.body.from=user._id;
forumThreadService.createThread(req.body,function(err,entity){ forumThreadService.createThread(req.body,function(err,entity){
if (err) { if (err) {
......
...@@ -30,6 +30,11 @@ function create(req,callback){ ...@@ -30,6 +30,11 @@ function create(req,callback){
entity.pid=null; entity.pid=null;
} }
var address=entity.address || null;
if(address){
entity.address=JSON.parse(address);
}
entity.ent_code=req.session.user.ent_code; entity.ent_code=req.session.user.ent_code;
entity.from=user.getMobileUser(req); entity.from=user.getMobileUser(req);
......
...@@ -43,6 +43,11 @@ var ForumThreadSchema = new Schema({ ...@@ -43,6 +43,11 @@ var ForumThreadSchema = new Schema({
icon: { //话题图标 icon: { //话题图标
type: String type: String
}, },
address: {//地址
country:{type: String,default:''},
province:{type: String,default:''},
city:{type: String,default:''},
},
order_idx: { //论坛排序 order_idx: { //论坛排序
type: Number, type: Number,
require: true, require: true,
......
...@@ -68,6 +68,7 @@ exports.getThreadById=function(tid,callback){ ...@@ -68,6 +68,7 @@ exports.getThreadById=function(tid,callback){
console.error(err); console.error(err);
cb(err,null); cb(err,null);
}else{ }else{
// console.log(threads);
cb(null,threads); cb(null,threads);
} }
}); });
...@@ -102,6 +103,29 @@ exports.getThreadById=function(tid,callback){ ...@@ -102,6 +103,29 @@ exports.getThreadById=function(tid,callback){
} }
}); });
}, },
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){ ],function(err,results){
if(err){ if(err){
callback(err,null); callback(err,null);
...@@ -111,12 +135,15 @@ exports.getThreadById=function(tid,callback){ ...@@ -111,12 +135,15 @@ exports.getThreadById=function(tid,callback){
var subThreads=results[2]||[];//话题子文章列表 var subThreads=results[2]||[];//话题子文章列表
var latestPhotos=results[3]||[];//最新照片墙列表 var latestPhotos=results[3]||[];//最新照片墙列表
var hotPhotos=results[4]||[];//最热照片墙列表 var hotPhotos=results[4]||[];//最热照片墙列表
var canyuPeopleCount=results[5]||0;//参与人数
var threadObj=thread.toObject(); var threadObj=thread.toObject();
threadObj.comments=comments; threadObj.comments=comments;
threadObj.subThreads=subThreads; threadObj.subThreads=subThreads;
threadObj.latestPhotos=latestPhotos; threadObj.latestPhotos=latestPhotos;
threadObj.hotPhotos=hotPhotos; threadObj.hotPhotos=hotPhotos;
threadObj.canyuPeopleCount=canyuPeopleCount;
callback(null,threadObj); callback(null,threadObj);
} }
}); });
...@@ -152,11 +179,12 @@ function populateComment(doc, callback){ ...@@ -152,11 +179,12 @@ function populateComment(doc, callback){
var asyncTasks = []; var asyncTasks = [];
doc.comments.forEach(function(comment){ doc.comments.forEach(function(comment){
asyncTasks.push(function(callback) { asyncTasks.push(function(callback) {
ForumComment.populate(comment, {path:'from to', select:'uid nickName icon comments'} , function(err, c){ ForumComment.populate(comment, {path:'from to', select:'uid nickName icon displayName displayIcon comments'} , function(err, c){
if (err) { if (err) {
console.error(err); console.error(err);
callback(null, null); callback(null, null);
} else{ } else{
// console.log(comment);
if(comment.comments){ if(comment.comments){
populateSubComment(comment,function(err, results){ populateSubComment(comment,function(err, results){
if(err){ if(err){
...@@ -300,7 +328,8 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,sort,callback){ ...@@ -300,7 +328,8 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,sort,callback){
var asyncTasks = []; var asyncTasks = [];
docs.forEach(function(doc){ docs.forEach(function(doc){
if(doc.type===1){ // console.log(doc);
if(doc.type===1 || doc.level!==1){//非照片墙或文章时获取评论
asyncTasks.push(function(callback) { asyncTasks.push(function(callback) {
populateComment(doc, callback); populateComment(doc, callback);
}); });
......
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