Commit 824a0fba authored by 邓军's avatar 邓军

个性化分享

parent 068e2633
...@@ -29,10 +29,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -29,10 +29,9 @@ router.post('/thread/create', function(req, res, next) {
var rs = {}; var rs = {};
req.body.ent_code=req.session.user.ent_code; req.body.ent_code=req.session.user.ent_code;
var uid=req.session.user.id; var uid=req.session.user.id;
// var uid='12345'; // var uid='12345';
async.waterfall([ async.waterfall([
function(callback){ function(callback){
forumUserService.getUserByUid(uid,callback); forumUserService.getUserByUid(uid,callback);
...@@ -121,6 +120,7 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -121,6 +120,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
//更新文章状态、如:屏蔽 //更新文章状态、如:屏蔽
router.post('/thread/:tid/update', function(req, res, next) { router.post('/thread/:tid/update', function(req, res, next) {
var tid=req.params.tid; var tid=req.params.tid;
req.body.ent_code=req.session.user.ent_code;
if(tid){ if(tid){
forumThreadService.updateThreadById(tid,req.body,function(err,thread){ forumThreadService.updateThreadById(tid,req.body,function(err,thread){
if(err){ if(err){
......
...@@ -70,6 +70,11 @@ var ForumThreadSchema = new Schema({ ...@@ -70,6 +70,11 @@ var ForumThreadSchema = new Schema({
type: Schema.Types.ObjectId, type: Schema.Types.ObjectId,
ref: 'ForumShare' ref: 'ForumShare'
}, },
share_type:{//是否使用默认设置:1使用默认分享设置 2.使用自己的分享设置
type:Number,
require:true,
default:1
},
pv_count: { //话题的访问量 pv_count: { //话题的访问量
type: Number, type: Number,
require: true, require: true,
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
var mongoose = require('mongoose'); var mongoose = require('mongoose');
var ForumThread = mongoose.model('ForumThread'); var ForumThread = mongoose.model('ForumThread');
var ForumComment = mongoose.model('ForumComment'); var ForumComment = mongoose.model('ForumComment');
var ForumShare = mongoose.model('ForumShare');
var forumCommentService = require('./forumCommentService'); var forumCommentService = require('./forumCommentService');
...@@ -9,15 +10,39 @@ var async = require('async'); ...@@ -9,15 +10,39 @@ var async = require('async');
//创建文章 //创建文章
exports.createThread = function(entity, callback) { exports.createThread = function(entity, callback) {
var forum = new ForumThread(entity); if (!entity.share) {
forum.save(function(err, forum) { var forum = new ForumThread(entity);
if (err) {
console.error(err); forum.save(function(err, forum) {
callback(err, null); if (err) {
} else { console.error(err);
callback(null, forum); callback(err, null);
} } else {
}); callback(null, forum);
}
});
} else {
var forumShare = new ForumShare(entity.share);
forumShare.ent_code = entity.ent_code;
forumShare.save(function(err, forumShare) {
if (err) {
console.error(err);
callback(err, null);
} else {
entity.share = forumShare._id;
var forum = new ForumThread(entity);
forum.save(function(err, forum) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, forum);
}
});
}
});
}
}; };
//根据ID获取文章记录,不查评论,子话题 //根据ID获取文章记录,不查评论,子话题
...@@ -41,7 +66,7 @@ exports.getThreadById = function(tid, callback) { ...@@ -41,7 +66,7 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
_id: tid _id: tid
}; };
ForumThread.find(conditions).populate('from').populate('info').exec(function(err, docs) { ForumThread.find(conditions).populate('from').populate('info').populate('share').exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -61,7 +86,7 @@ exports.getThreadById = function(tid, callback) { ...@@ -61,7 +86,7 @@ exports.getThreadById = function(tid, callback) {
thread: tid, thread: tid,
level: '1' level: '1'
}; };
//获取最新10条评论 //获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) { forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
if (err) { if (err) {
console.log(err); console.log(err);
...@@ -165,16 +190,64 @@ exports.getThreadById = function(tid, callback) { ...@@ -165,16 +190,64 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章 //根据ID更新文章
exports.updateThreadById = function(tid, entity, callback) { exports.updateThreadById = function(tid, entity, callback) {
ForumThread.update({ var shareEntity = entity.share;
_id: tid entity.share = entity.share._id;
}, entity, null, function(err, result) { if (entity.share) {
if (err) { ForumThread.update({
console.error(err); _id: tid
callback(err, null); }, entity, null, function(err, result) {
if (err) {
console.error(err);
callback(err, null);
} else {
ForumShare.update({
_id: shareEntity._id
}, shareEntity, null, function(err, result) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
}
});
}
});
} else {
if (shareEntity.title || shareEntity.description || shareEntity.icon) {
shareEntity.ent_code = entity.ent_code;
var forumShare = new ForumShare(shareEntity);
forumShare.save(function(err, forumShare) {
entity.share = forumShare._id;
ForumThread.update({
_id: tid
}, entity, null, function(err, result) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
}
});
});
} else { } else {
callback(null, null); delete entity.share;
ForumThread.update({
_id: tid
}, entity, null, function(err, result) {
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, null);
}
});
} }
}); }
}; };
//根据ID更新文章 //根据ID更新文章
...@@ -402,17 +475,17 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac ...@@ -402,17 +475,17 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶) //根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports.updateTopByThreadId = function(infoId, threadId, callback) { exports.updateTopByThreadId = function(infoId, threadId, callback) {
// ForumThread.update({info:infoId}, {top:0},{multi:true}, function(err, doc) { // ForumThread.update({info:infoId}, {top:0},{multi:true}, function(err, doc) {
// if(err){ // if(err){
// callback(err,null); // callback(err,null);
// }else{ // }else{
// ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) { // ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) {
// if(err){ // if(err){
// callback(err,null); // callback(err,null);
// }else{ // }else{
// callback(null,null); // callback(null,null);
// } // }
// }); // });
// } // }
// }); // });
ForumThread.findOneAndUpdate({ ForumThread.findOneAndUpdate({
_id: threadId _id: threadId
......
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