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
9739fec4
Commit
9739fec4
authored
Sep 08, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
版主加精 取消加精 删帖子
parent
a2ab33a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
250 additions
and
0 deletions
+250
-0
forumModerator.js
app/controllers/mobile/forumModerator.js
+218
-0
forumModerator.js
app/models/forumModerator.js
+32
-0
No files found.
app/controllers/mobile/forumModerator.js
0 → 100644
View file @
9739fec4
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
thenjs
=
require
(
'thenjs'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumModeratorApply
=
mongoose
.
model
(
'ForumModeratorApply'
);
var
user
=
require
(
'../../utils/user'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumModerator
=
mongoose
.
model
(
'ForumModerator'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
request
=
require
(
'request'
);
var
env
=
process
.
env
.
NODE_ENV
;
var
API_ADDRESS
=
'http://localhost:8080'
;
if
(
env
==
'sandbox'
){
API_ADDRESS
=
'http://rest.wxpai.cn'
;
}
else
if
(
env
==
'production'
){
API_ADDRESS
=
'https://rest.wxpai.cn'
;
}
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
function
moderatorOperateLog
(
forumUser
,
thread
,
type
){
var
forumModerator
=
new
ForumModerator
({
info
:
thread
.
info
,
userName
:
forumUser
.
uid
,
content
:
thread
.
_id
,
behavior
:
type
,
moderatorName
:
forumUser
.
nickName
||
forumUser
.
displayName
});
forumModerator
.
save
(
function
(
err
,
res
)
{});
}
function
addIntegral
(
thread
){
var
openID
=
thread
.
from
.
uid
;
var
tid
=
thread
.
_id
;
var
ent_code
=
thread
.
ent_code
;
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
tid
,
function
(
err
,
flag
){
if
(
!
err
&&
!
flag
){
//获取mid
console
.
log
(
API_ADDRESS
);
request
.
get
({
url
:
API_ADDRESS
+
'/v1.0/internal/member/getMidbyOpenID?entCode='
+
ent_code
+
'&openID='
+
openID
,
json
:
true
},
function
(
e
,
r
,
res
){
console
.
log
(
res
);
if
(
res
&&
res
.
data
){
httpService
.
sendRequest
(
ent_code
,
res
.
data
,
'thread_recomment'
);
}
});
}
});
}
//获取版主为当前用户的板块id数组
router
.
get
(
'/moderators/plates'
,
function
(
req
,
res
,
next
)
{
var
entCode
=
req
.
session
.
user
.
ent_code
;
var
id
=
user
.
getMobileUser
(
req
);
var
q
=
{};
q
.
status
=
1
;
q
.
ent_code
=
entCode
;
q
.
forumUser
=
id
;
ForumModeratorApply
.
find
(
q
).
exec
(
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
items
=
[];
if
(
result
&&
result
.
infoIds
){
items
=
result
.
infoIds
;
}
res
.
json
(
_
.
assign
({
items
:
items
},
returnCode
.
SUCCESS
));
});
});
//版主加精
//1.判断这篇文章是不是后台发的,后台发的不允许操作
//2.判断当前用户是不是这个文章对应板块的版主
router
.
get
(
'/moderators/recommend/:tid'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
,
entCode
=
req
.
session
.
user
.
ent_code
,
id
=
user
.
getMobileUser
(
req
);
//user._id
var
q1
=
{};
//拼装查询条件
q1
.
ent_code
=
entCode
;
q1
.
_id
=
tid
;
q1
.
status
=
1
;
q1
.
$or
=
[{
recommend
:
0
},
{
recommend
:
null
}];
ForumThread
.
findOne
(
q1
).
populate
(
'from'
).
exec
(
function
(
err
,
t
)
{
if
(
err
||
!
t
)
{
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
t
.
from
&&
!
isNaN
(
t
.
from
.
uid
)){
//是后台发的,没有权限操作
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
if
(
!
t
.
info
){
//没有板块id直接返回
return
res
.
json
(
returnCode
.
BUSY
);
}
var
q2
=
{};
//查询当前用户是不是这篇文章的版主
q2
.
status
=
1
;
q2
.
ent_code
=
entCode
;
q2
.
forumUser
=
id
;
q2
.
infoIds
=
t
.
info
;
ForumModeratorApply
.
findOne
(
q2
).
populate
(
'forumUser'
).
exec
(
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
!
result
){
//不是该版主
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
//加精
forumThreadService
.
updateRecommendByThreadId
(
tid
,
function
(
err
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
moderatorOperateLog
(
result
.
forumUser
,
t
,
1
);
addIntegral
(
t
);
//根据openid 送积分
}
});
});
});
});
//版主取消加精
router
.
get
(
'/moderators/unrecommend/:tid'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
,
entCode
=
req
.
session
.
user
.
ent_code
,
id
=
user
.
getMobileUser
(
req
);
//user._id
var
q1
=
{};
//拼装查询条件
q1
.
ent_code
=
entCode
;
q1
.
_id
=
tid
;
q1
.
status
=
1
;
q1
.
recommend
=
1
;
ForumThread
.
findOne
(
q1
).
populate
(
'from'
).
exec
(
function
(
err
,
t
)
{
if
(
err
||
!
t
)
{
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
t
.
from
&&
!
isNaN
(
t
.
from
.
uid
)){
//是后台发的,没有权限操作
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
if
(
!
t
.
info
){
//没有板块id直接返回
return
res
.
json
(
returnCode
.
BUSY
);
}
var
q2
=
{};
//查询当前用户是不是这篇文章的版主
q2
.
status
=
1
;
q2
.
ent_code
=
entCode
;
q2
.
forumUser
=
id
;
q2
.
infoIds
=
t
.
info
;
ForumModeratorApply
.
findOne
(
q2
).
populate
(
'forumUser'
).
exec
(
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
!
result
){
//不是该版主
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
//取消加精
forumThreadService
.
updateUnRecommendByThreadId
(
tid
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
moderatorOperateLog
(
result
.
forumUser
,
t
,
2
);
}
});
});
});
});
//版主删除帖子
router
.
get
(
'/moderators/delthread/:tid'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
,
entCode
=
req
.
session
.
user
.
ent_code
,
id
=
user
.
getMobileUser
(
req
);
//user._id
var
q1
=
{};
//拼装查询条件
q1
.
ent_code
=
entCode
;
q1
.
_id
=
tid
;
q1
.
status
=
1
;
ForumThread
.
findOne
(
q1
).
populate
(
'from'
).
exec
(
function
(
err
,
t
)
{
if
(
err
||
!
t
)
{
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
t
.
from
&&
!
isNaN
(
t
.
from
.
uid
)){
//是后台发的,没有权限操作
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
if
(
!
t
.
info
){
//没有板块id直接返回
return
res
.
json
(
returnCode
.
BUSY
);
}
var
q2
=
{};
//查询当前用户是不是这篇文章的版主
q2
.
status
=
1
;
q2
.
ent_code
=
entCode
;
q2
.
forumUser
=
id
;
q2
.
infoIds
=
t
.
info
;
ForumModeratorApply
.
findOne
(
q2
).
populate
(
'forumUser'
).
exec
(
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
!
result
){
//不是该版主
return
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
//删除帖子
forumThreadService
.
logicDeleteThreadById
(
tid
,
function
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
moderatorOperateLog
(
result
.
forumUser
,
t
,
3
);
}
});
});
});
});
app/models/forumModerator.js
0 → 100644
View file @
9739fec4
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
var
ForumModeratorSchema
=
new
Schema
({
info
:
{
type
:
Schema
.
Types
.
ObjectId
,
require
:
true
,
index
:
true
,
ref
:
'ForumInfo'
},
userName
:{
type
:
String
,
require
:
true
},
content
:{
type
:
Schema
.
Types
.
ObjectId
,
require
:
false
},
behavior
:{
//行为:1.加精 2.取消精华 3.删帖
type
:
Number
,
require
:
true
},
moderatorName
:{
type
:
String
,
require
:
true
}
},
{
'collection'
:
'pisns_forum_moderator_operation'
});
module
.
exports
=
mongoose
.
model
(
'ForumModerator'
,
ForumModeratorSchema
);
\ No newline at end of file
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