Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
824a0fba
Commit
824a0fba
authored
Apr 16, 2015
by
邓军
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
个性化分享
parent
068e2633
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
32 deletions
+110
-32
forumThread.js
app/controllers/admin/forumThread.js
+2
-2
forumThread.js
app/models/forumThread.js
+5
-0
forumThreadService.js
app/service/forumThreadService.js
+103
-30
No files found.
app/controllers/admin/forumThread.js
View file @
824a0fba
...
...
@@ -29,7 +29,6 @@ router.post('/thread/create', function(req, res, next) {
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
uid
=
req
.
session
.
user
.
id
;
// var uid='12345';
...
...
@@ -121,6 +120,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
//更新文章状态、如:屏蔽
router
.
post
(
'/thread/:tid/update'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
){
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
){
if
(
err
){
...
...
app/models/forumThread.js
View file @
824a0fba
...
...
@@ -70,6 +70,11 @@ var ForumThreadSchema = new Schema({
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'ForumShare'
},
share_type
:{
//是否使用默认设置:1使用默认分享设置 2.使用自己的分享设置
type
:
Number
,
require
:
true
,
default
:
1
},
pv_count
:
{
//话题的访问量
type
:
Number
,
require
:
true
,
...
...
app/service/forumThreadService.js
View file @
824a0fba
...
...
@@ -2,6 +2,7 @@
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumComment
=
mongoose
.
model
(
'ForumComment'
);
var
ForumShare
=
mongoose
.
model
(
'ForumShare'
);
var
forumCommentService
=
require
(
'./forumCommentService'
);
...
...
@@ -9,6 +10,26 @@ var async = require('async');
//创建文章
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
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
...
...
@@ -18,6 +39,10 @@ exports.createThread = function(entity, callback) {
callback
(
null
,
forum
);
}
});
}
});
}
};
//根据ID获取文章记录,不查评论,子话题
...
...
@@ -41,7 +66,7 @@ exports.getThreadById = function(tid, callback) {
var
conditions
=
{
_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
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -165,9 +190,19 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章
exports
.
updateThreadById
=
function
(
tid
,
entity
,
callback
)
{
var
shareEntity
=
entity
.
share
;
entity
.
share
=
entity
.
share
.
_id
;
if
(
entity
.
share
)
{
ForumThread
.
update
({
_id
:
tid
},
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
);
...
...
@@ -175,6 +210,44 @@ exports.updateThreadById = function(tid, entity, callback) {
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更新文章
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment