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

个性化分享

parent 068e2633
...@@ -29,7 +29,6 @@ router.post('/thread/create', function(req, res, next) { ...@@ -29,7 +29,6 @@ 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';
...@@ -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,6 +10,26 @@ var async = require('async'); ...@@ -9,6 +10,26 @@ var async = require('async');
//创建文章 //创建文章
exports.createThread = function(entity, callback) { exports.createThread = function(entity, callback) {
if (!entity.share) {
var forum = new ForumThread(entity);
forum.save(function(err, forum) {
if (err) {
console.error(err);
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); var forum = new ForumThread(entity);
forum.save(function(err, forum) { forum.save(function(err, forum) {
if (err) { if (err) {
...@@ -18,6 +39,10 @@ exports.createThread = function(entity, callback) { ...@@ -18,6 +39,10 @@ exports.createThread = function(entity, callback) {
callback(null, forum); 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);
...@@ -165,9 +190,19 @@ exports.getThreadById = function(tid, callback) { ...@@ -165,9 +190,19 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章 //根据ID更新文章
exports.updateThreadById = function(tid, entity, callback) { exports.updateThreadById = function(tid, entity, callback) {
var shareEntity = entity.share;
entity.share = entity.share._id;
if (entity.share) {
ForumThread.update({ ForumThread.update({
_id: tid _id: tid
}, entity, null, function(err, result) { }, 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) { if (err) {
console.error(err); console.error(err);
callback(err, null); callback(err, null);
...@@ -175,6 +210,44 @@ exports.updateThreadById = function(tid, entity, callback) { ...@@ -175,6 +210,44 @@ exports.updateThreadById = function(tid, entity, callback) {
callback(null, null); 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 {
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更新文章
......
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