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
0ed28b1f
Commit
0ed28b1f
authored
Apr 20, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development
parents
3d210033
235aa871
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1673 additions
and
1195 deletions
+1673
-1195
forumIdentifyUser.js
app/controllers/admin/forumIdentifyUser.js
+9
-0
forumThread.js
app/controllers/admin/forumThread.js
+2
-2
forumInfo.js
app/controllers/mobile/forumInfo.js
+335
-316
forumShare.js
app/controllers/mobile/forumShare.js
+64
-12
forumShareConfig.js
app/controllers/mobile/forumShareConfig.js
+60
-0
forumThread.js
app/controllers/mobile/forumThread.js
+862
-829
forumPVLog.js
app/models/forumPVLog.js
+70
-0
forumThread.js
app/models/forumThread.js
+5
-0
forumUVLog.js
app/models/forumUVLog.js
+70
-0
forumThreadService.js
app/service/forumThreadService.js
+103
-30
httpService.js
app/service/httpService.js
+93
-6
No files found.
app/controllers/admin/forumIdentifyUser.js
View file @
0ed28b1f
...
...
@@ -7,6 +7,7 @@ var express = require('express'),
var
mongoose
=
require
(
'mongoose'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
async
=
require
(
'async'
);
...
...
@@ -51,4 +52,12 @@ router.post('/user/identifyUser',function(req,res,next){
}
else
{
res
.
json
(
'success'
);
}
});
//微信分享带来用户
router
.
get
(
'/user/from/share'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
query
.
mid
,
action
=
req
.
query
.
action
,
ent_code
=
req
.
query
.
ent_code
;
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
});
\ No newline at end of file
app/controllers/admin/forumThread.js
View file @
0ed28b1f
...
...
@@ -29,10 +29,9 @@ 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';
async
.
waterfall
([
function
(
callback
){
forumUserService
.
getUserByUid
(
uid
,
callback
);
...
...
@@ -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/controllers/mobile/forumInfo.js
View file @
0ed28b1f
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumInfo
=
mongoose
.
model
(
'ForumInfo'
);
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
user
=
require
(
'../../utils/user'
);
var
user
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
var
async
=
require
(
'async'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
app
.
use
(
'/v1/forum'
,
router
);
};
//新增论坛板块
router
.
post
(
'/info/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumInfoService
.
createInfo
(
req
.
body
,
function
(
err
,
info
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
info
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumInfoService
.
createInfo
(
req
.
body
,
function
(
err
,
info
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
info
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//获取目标论坛板块
router
.
get
(
'/info/:fid/get'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
fid
=
req
.
params
.
fid
||
null
;
if
(
fid
)
{
httpService
.
createLog
(
req
,
fid
,
2
);
async
.
waterfall
([
function
(
callback
)
{
//更新浏览数
forumInfoService
.
updateInfoPvCount
(
fid
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
data
,
callback
)
{
forumInfoService
.
getInfoById
(
fid
,
function
(
err
,
info
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
info
);
}
});
},
function
(
info
,
callback
)
{
forumThreadService
.
getAllCountByFid
({
info
:
fid
},
function
(
err
,
threadCount
)
{
if
(
err
)
{
callback
(
err
,
null
,
null
);
}
else
{
callback
(
null
,
info
,
threadCount
);
}
});
}
],
function
(
err
,
info
,
threadCount
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
info
;
rs
.
data
.
threadCount
=
threadCount
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
if
(
fid
)
{
async
.
waterfall
([
function
(
callback
){
//更新浏览数
forumInfoService
.
updateInfoPvCount
(
fid
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
data
,
callback
){
forumInfoService
.
getInfoById
(
fid
,
function
(
err
,
info
){
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
info
);
}
});
},
function
(
info
,
callback
){
forumThreadService
.
getAllCountByFid
({
info
:
fid
},
function
(
err
,
threadCount
){
if
(
err
){
callback
(
err
,
null
,
null
);
}
else
{
callback
(
null
,
info
,
threadCount
);
}
});
}
],
function
(
err
,
info
,
threadCount
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
info
;
rs
.
data
.
threadCount
=
threadCount
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新目标论坛板块
router
.
post
(
'/info/:fid/update'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
;
if
(
fid
)
{
forumInfoService
.
updateInfoById
(
fid
,
req
.
body
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
fid
=
req
.
params
.
fid
;
if
(
fid
)
{
forumInfoService
.
updateInfoById
(
fid
,
req
.
body
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除目标论坛板块
router
.
post
(
'/info/:fid/delete'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
;
if
(
fid
)
{
forumInfoService
.
deleteInfoById
(
fid
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
fid
=
req
.
params
.
fid
;
if
(
fid
)
{
forumInfoService
.
deleteInfoById
(
fid
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
/**
...
...
@@ -124,262 +130,275 @@ router.post('/info/:fid/delete', function(req, res, next) {
* @return {[type]}
*/
router
.
get
(
'/info/:fid/threads'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
fid
=
req
.
params
.
fid
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
var
fid
=
req
.
params
.
fid
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
};
if
(
fid
){
conditions
.
info
=
fid
;
if
(
fid
)
{
conditions
.
info
=
fid
;
}
if
(
fid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
if
(
fid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取论坛最热文章列表
router
.
get
(
'/info/:fid/hotThreads'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
info
:
fid
};
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
info
:
fid
};
if
(
fid
)
{
if
(
fid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-comment_count -praise_count'
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-comment_count -praise_count'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取论坛晒图文章列表
router
.
get
(
'/info/:fid/photoThreads'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
info
:
fid
,
type
:
3
};
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
info
:
fid
,
type
:
3
};
if
(
fid
)
{
if
(
fid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取我的文章列表
router
.
get
(
'/info/:fid/myThreads'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
info
:
fid
};
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
info
:
fid
};
if
(
fid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
if
(
fid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//搜索文章列表
router
.
get
(
'/info/:fid/serachThreads'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
content
=
req
.
query
.
content
;
var
content
=
req
.
query
.
content
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
info
:
fid
};
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
info
:
fid
};
if
(
content
)
{
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
}
if
(
content
)
{
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
}
if
(
fid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
if
(
fid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/controllers/mobile/forumShare.js
View file @
0ed28b1f
...
...
@@ -9,14 +9,16 @@ var forumThreadService = require('../../service/forumThreadService');
var
forumShareConfigService
=
require
(
'../../service/forumShareConfigService'
);
var
forumShareService
=
require
(
'../../service/forumShareService'
);
var
config
=
require
(
'../../../config/config'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
then
=
require
(
'thenjs'
);
//
var forumInfoService = require('../../service/forumInfoService');
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
function
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
)
{
function
write
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
)
{
link
=
config
.
service
+
link
+
"&mid="
+
mid
;
res
.
writeHead
(
200
,
{
'Content-Type'
:
'text/javascript'
,
...
...
@@ -31,7 +33,11 @@ function getWX(res, title, desc, link, imgUrl, mid) {
// imgUrl = 'http://dev.fs.wxpai.cn/upload/100001_2015410_1428671539587_40.jpg',
// desc = '测试描述';
// var string = '';
var
string
=
'wx.onMenuShareTimeline({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
",'
+
'
\
"link
\
":
\
"'
+
link
+
'
\
",'
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'success: function(){},'
+
'cancel: function () {}'
+
' });'
+
' wx.onMenuShareAppMessage({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
", '
+
'
\
"desc
\
":
\
"'
+
desc
+
'
\
", '
+
'
\
"link
\
":
\
"'
+
link
+
'
\
", '
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'
\
"type
\
":
\'\'
,'
+
'
\
"dataUrl
\
":
\'\'
, '
+
'success: function(){},'
+
'cancel: function () { '
+
'}'
+
' });'
var
success
=
'$.ajax({'
+
'type:
\'
GET
\'
,'
+
'url:
\'
/v1/forum/'
+
ent_code
+
'/timeline
\'
'
+
'});'
;
var
string
=
'wx.onMenuShareTimeline({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
",'
+
'
\
"link
\
":
\
"'
+
link
+
'
\
",'
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'success: function(){'
+
success
+
'},'
+
'cancel: function () {}'
+
' });'
+
' wx.onMenuShareAppMessage({'
+
'
\
"title
\
":
\
"'
+
title
+
'
\
", '
+
'
\
"desc
\
":
\
"'
+
desc
+
'
\
", '
+
'
\
"link
\
":
\
"'
+
link
+
'
\
", '
+
'
\
"imgUrl
\
":
\
"'
+
imgUrl
+
'
\
", '
+
'
\
"type
\
":
\'\'
,'
+
'
\
"dataUrl
\
":
\'\'
, '
+
'success: function(){},'
+
'cancel: function () { '
+
'}'
+
' });'
res
.
write
(
'wx.ready(function(){'
+
string
+
'});'
);
res
.
write
(
'wx.error(function(res){console.log(res);});'
);
...
...
@@ -39,6 +45,36 @@ function getWX(res, title, desc, link, imgUrl, mid) {
res
.
end
();
}
function
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
forumThread
)
{
//['{板块名称}','{文章标题}','{话题名称}','{照片墙标题}'];
//share_type:是否使用默认设置:1使用默认分享设置 2.使用自己的分享设置
link
=
config
.
service
+
link
+
"&mid="
+
mid
;
if
(
type
===
"Info"
)
{
forumInfoService
.
getInfoById
(
id
,
function
(
err
,
forumInfo
)
{
if
(
err
||
forumInfo
<
1
)
{
console
.
error
(
"板块不存在或者发生未知错误"
);
res
.
json
({
message
:
'板块不存在或者发生未知错误'
,
result
:
false
,
code
:
'10002'
,
error
:
err
});
}
else
{
title
=
title
.
replace
(
/{板块名称}/g
,
forumInfo
.
name
);
desc
=
desc
.
replace
(
/{板块名称}/g
,
forumInfo
.
name
);
write
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
);
}
});
}
else
if
(
type
===
"Thread"
){
title
=
title
.
replace
(
/{文章标题}|{话题名称}|{照片墙标题}/g
,
forumThread
.
title
);
desc
=
desc
.
replace
(
/{文章标题}|{话题名称}|{照片墙标题}/g
,
forumThread
.
title
);
write
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
);
}
}
//微信分享接口
router
.
get
(
'/:ent_code/share.js'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
...
...
@@ -53,9 +89,11 @@ router.get('/:ent_code/share.js', function(req, res, next) {
if
(
type
)
{
//板块微信接口
if
(
type
===
'Info'
)
{
then
(
function
(
cont
)
{
forumShareConfigService
.
getByKey
(
ent_code
,
'share'
,
function
(
err
,
result
)
{
console
.
log
(
err
);
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
...
...
@@ -73,7 +111,9 @@ router.get('/:ent_code/share.js', function(req, res, next) {
}
else
{
link
=
link
+
'index'
;
}
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
);
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
null
);
}
else
{
cont
(
err
);
}
...
...
@@ -105,7 +145,7 @@ router.get('/:ent_code/share.js', function(req, res, next) {
}).
then
(
function
(
cont
,
result
)
{
//如果没有share值则用默认值
if
(
!
result
.
share
)
{
if
(
!
result
.
share
||
result
.
share_type
==
1
)
{
forumShareConfigService
.
getByKey
(
ent_code
,
'share'
,
function
(
err
,
sc
)
{
var
title
=
''
,
...
...
@@ -130,9 +170,9 @@ router.get('/:ent_code/share.js', function(req, res, next) {
for
(
var
i
=
0
;
i
<
sc
.
length
;
i
++
)
{
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
if
(
sc
[
i
].
type
===
'article'
)
{
title
=
sc
[
i
].
title
;
desc
=
sc
[
i
].
desc
;
imgUrl
=
sc
[
i
].
imgUrl
;
...
...
@@ -147,7 +187,7 @@ router.get('/:ent_code/share.js', function(req, res, next) {
}
}
else
if
(
result
.
type
===
3
)
{
if
(
sc
[
i
].
type
===
'photo'
)
{
title
=
sc
[
i
].
title
;
desc
=
sc
[
i
].
desc
;
...
...
@@ -158,8 +198,9 @@ router.get('/:ent_code/share.js', function(req, res, next) {
}
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
);
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
result
.
_id
,
type
,
result
);
}
else
{
cont
(
err
);
}
...
...
@@ -181,7 +222,8 @@ router.get('/:ent_code/share.js', function(req, res, next) {
//key = 'photo';
}
getWX
(
res
,
forumShare
.
title
,
forumShare
.
description
,
link
,
forumShare
.
icon
,
mid
);
getWX
(
res
,
forumShare
.
title
,
forumShare
.
description
,
link
,
forumShare
.
icon
,
mid
,
ent_code
,
result
.
_id
,
type
,
result
);
});
}
}).
fail
(
function
(
cont
,
err
)
{
...
...
@@ -199,3 +241,13 @@ router.get('/:ent_code/share.js', function(req, res, next) {
});
}
});
//微信分享接口
router
.
get
(
'/:ent_code/timeline'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
session
.
openUser
.
mid
,
action
=
'share_timeline'
,
ent_code
=
req
.
session
.
user
.
ent_code
;
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
});
app/controllers/mobile/forumShareConfig.js
0 → 100644
View file @
0ed28b1f
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
//var forumThreadService = require('../../service/forumThreadService');
var
forumShareConfigService
=
require
(
'../../service/forumShareConfigService'
);
//var forumShareService = require('../../service/forumShareService');
//var config = require('../../../config/config');
var
then
=
require
(
'thenjs'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//type:类型(板块,照片墙等); key:类型里面的标题(title,desc等);value:值
function
getForumConfig
(
key
,
value
,
ent_code
)
{
var
forumConfig
=
{};
forumConfig
.
meta_key
=
key
;
forumConfig
.
meta_value
=
value
;
forumConfig
.
ent_code
=
ent_code
;
return
forumConfig
;
}
//批量创建默认分享设置
router
.
post
(
'/forumConfig/put'
,
function
(
req
,
res
,
next
)
{
var
model
=
req
.
body
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
model
.
ent_code
=
ent_code
;
if
(
model
.
ent_code
)
{
forumShareConfigService
.
create
(
model
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
BUSY
);
}
});
//初始化默认分享数据
router
.
get
(
'/forumConfig/getConfig'
,
function
(
req
,
res
,
next
)
{
var
ent_code
=
req
.
session
.
user
.
ent_code
;
forumShareConfigService
.
getByKey
(
ent_code
,
req
.
query
.
meta_key
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
({
message
:
'success'
,
data
:
result
});
}
});
});
app/controllers/mobile/forumThread.js
View file @
0ed28b1f
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumComment
=
mongoose
.
model
(
'ForumComment'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
user
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
var
user
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
app
.
use
(
'/v1/forum'
,
router
);
};
function
create
(
req
,
callback
)
{
var
entity
=
req
.
body
;
if
(
entity
.
pid
==
''
)
{
entity
.
pid
=
null
;
}
var
address
=
entity
.
address
||
null
;
if
(
address
)
{
entity
.
address
=
JSON
.
parse
(
address
);
}
entity
.
ent_code
=
req
.
session
.
user
.
ent_code
;
entity
.
from
=
user
.
getMobileUser
(
req
);
//-----------处理前端上传图片开始
//格式为['http://imageurl','http://imageurl'],
//转换为[{urlFileName:'http://imageUrL'},{urlFileName:'http://imageUrL'}]
var
images
=
entity
.
images
;
if
(
images
)
{
var
array
=
[];
for
(
var
i
=
0
;
i
<
images
.
length
;
i
=
i
+
1
)
{
array
.
push
({
urlFileName
:
images
[
i
]
});
}
entity
.
images
=
array
;
}
//-----------处理前端上传图片结束
forumThreadService
.
createThread
(
entity
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
entity
);
}
});
function
create
(
req
,
callback
)
{
var
entity
=
req
.
body
;
if
(
entity
.
pid
==
''
)
{
entity
.
pid
=
null
;
}
var
address
=
entity
.
address
||
null
;
if
(
address
)
{
entity
.
address
=
JSON
.
parse
(
address
);
}
entity
.
ent_code
=
req
.
session
.
user
.
ent_code
;
entity
.
from
=
user
.
getMobileUser
(
req
);
//-----------处理前端上传图片开始
//格式为['http://imageurl','http://imageurl'],
//转换为[{urlFileName:'http://imageUrL'},{urlFileName:'http://imageUrL'}]
var
images
=
entity
.
images
;
if
(
images
)
{
var
array
=
[];
for
(
var
i
=
0
;
i
<
images
.
length
;
i
=
i
+
1
)
{
array
.
push
({
urlFileName
:
images
[
i
]
});
}
entity
.
images
=
array
;
}
//-----------处理前端上传图片结束
forumThreadService
.
createThread
(
entity
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
entity
);
}
});
}
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'create'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
create
(
req
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'create'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
create
(
req
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'post'
);
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
});
//获取目标论坛文章
router
.
get
(
'/thread/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
async
.
waterfall
([
function
(
callback
){
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
data
,
callback
){
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
},
],
function
(
err
,
thread
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
data
,
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
//文章类型 1、文章 2、话题 3、照片墙
var
info_id
=
thread
.
info
.
_id
,
pid
=
thread
.
pid
;
if
(
thread
.
type
==
1
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
info_id
,
3
,
1
,
tid
);
}
else
if
(
thread
.
type
==
1
&&
thread
.
level
==
2
){
httpService
.
createLog
(
req
,
info_id
,
3
,
4
,
tid
,
pid
);
}
else
if
(
thread
.
type
==
2
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
info_id
,
3
,
2
,
tid
);
}
else
if
(
thread
.
type
==
3
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
info_id
,
3
,
3
,
tid
);
}
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
},
],
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新文章状态、如:屏蔽
router
.
post
(
'/thread/:tid/update'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除文章
router
.
post
(
'/thread/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章点赞
router
.
post
(
'/thread/:tid/raise'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
//判断是否已经点赞
forumPraiseLogService
.
queryPraiseLog
(
tid
,
null
,
user
.
getMobileUser
(
req
),
1
,
function
(
err
,
logs
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
logs
&&
logs
.
length
>
0
){
res
.
json
(
returnCode
.
CAN_NOT_RAISE_REPEAT
);
}
else
{
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'raise'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
//3.更新文章统计数据(点赞数)
if
(
thread
){
forumThreadService
.
updateThreadRaiseCount
(
tid
,
function
(
err
,
cb
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
ip
:
req
.
ip
,
comment
:
null
,
type
:
1
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
user
.
getOpenId
(
req
),
tid
,
'raise'
);
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
doc
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
praise_count
=
doc
.
praise_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
//判断是否已经点赞
forumPraiseLogService
.
queryPraiseLog
(
tid
,
null
,
user
.
getMobileUser
(
req
),
1
,
function
(
err
,
logs
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
logs
&&
logs
.
length
>
0
)
{
res
.
json
(
returnCode
.
CAN_NOT_RAISE_REPEAT
);
}
else
{
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'raise'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
//3.更新文章统计数据(点赞数)
if
(
thread
)
{
forumThreadService
.
updateThreadRaiseCount
(
tid
,
function
(
err
,
cb
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
ip
:
req
.
ip
,
comment
:
null
,
type
:
1
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'thread_praise'
);
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
praise_count
=
doc
.
praise_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章分享
router
.
post
(
'/thread/:tid/share'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'share'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
//3.更新文章统计数据(分享数)
if
(
thread
)
{
forumThreadService
.
updateThreadShareCount
(
tid
,
function
(
err
,
cb
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
destination
:
destination
,
ip
:
req
.
ip
};
//4.创建分享日志
forumShareLogService
.
createShareLog
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
user
.
getOpenId
(
req
),
t
id
,
'share'
);
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'share'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
//3.更新文章统计数据(分享数)
if
(
thread
)
{
forumThreadService
.
updateThreadShareCount
(
tid
,
function
(
err
,
cb
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
},
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
destination
:
destination
,
ip
:
req
.
ip
};
//4.创建分享日志
forumShareLogService
.
createShareLog
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
// httpService.sendRequest(req.session.user.ent_code,req.session.openUser.m
id,'share');
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//新增文章评论
router
.
post
(
'/thread/:tid/comment/create'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'comment'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
){
//评论不能为空
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
content
:
content
,
ip
:
req
.
ip
,
thread
:
thread
,
level
:
'1'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
var
comments
=
thread
.
comments
;
// console.log('=========');
// console.log(comments);
// console.log('=========');
var
array
=
[];
if
(
comments
&&
comments
.
items
&&
comments
.
items
.
length
>
0
){
array
=
comments
.
items
;
}
array
.
push
(
newComment
.
_id
);
forumThreadService
.
updateThreadById
(
tid
,{
comments
:
array
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
});
},
function
(
callback
){
//3.更新文章统计数据(评论数)
if
(
thread
){
forumThreadService
.
updateThreadCommentCount
(
tid
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
user
.
getOpenId
(
req
),
tid
,
'comment'
);
async
.
parallel
([
function
(
callback
){
//获取最新5条评论
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
forumCommentService
.
getAllComment
(
conditions
,
1
,
5
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
},
function
(
callback
){
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
}
],
function
(
err
,
results
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
comments
=
results
[
0
].
items
;
rs
.
commentCount
=
results
[
1
].
comment_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'comment'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
)
{
//评论不能为空
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
content
:
content
,
ip
:
req
.
ip
,
thread
:
thread
,
level
:
'1'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
comments
=
thread
.
comments
;
// console.log('=========');
// console.log(comments);
// console.log('=========');
var
array
=
[];
if
(
comments
&&
comments
.
items
&&
comments
.
items
.
length
>
0
)
{
array
=
comments
.
items
;
}
array
.
push
(
newComment
.
_id
);
forumThreadService
.
updateThreadById
(
tid
,
{
comments
:
array
},
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
});
},
function
(
callback
)
{
//3.更新文章统计数据(评论数)
if
(
thread
)
{
forumThreadService
.
updateThreadCommentCount
(
tid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
async
.
parallel
([
function
(
callback
)
{
//获取最新5条评论
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
forumCommentService
.
getAllComment
(
conditions
,
1
,
5
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
},
function
(
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
comments
=
results
[
0
].
items
;
rs
.
commentCount
=
results
[
1
].
comment_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//新建文章评论的子评论
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'reply'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
){
//评论不能为空
//2.获取论坛评论
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
to
:
req
.
body
.
to
,
content
:
content
,
ip
:
req
.
ip
,
thread
:
tid
,
level
:
'2'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
){
array
=
comments
;
}
array
.
push
(
newComment
.
_id
);
forumCommentService
.
updateCommentById
(
cid
,{
comments
:
array
},
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
newComment
);
}
});
}
});
},
function
(
callback
){
forumCommentService
.
updateCommentCount
(
cid
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
user
.
getOpenId
(
req
),
tid
,
'reply'
);
ForumComment
.
populate
(
results
[
0
],
{
path
:
'from to'
,
select
:
'uid nickName icon comments'
}
,
function
(
err
,
c
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
results
[
0
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
// res.json(returnCode.SUCCESS);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'reply'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
)
{
//评论不能为空
//2.获取论坛评论
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
to
:
req
.
body
.
to
,
content
:
content
,
ip
:
req
.
ip
,
thread
:
tid
,
level
:
'2'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
)
{
array
=
comments
;
}
array
.
push
(
newComment
.
_id
);
forumCommentService
.
updateCommentById
(
cid
,
{
comments
:
array
},
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
newComment
);
}
});
}
});
},
function
(
callback
)
{
forumCommentService
.
updateCommentCount
(
cid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'reply'
);
ForumComment
.
populate
(
results
[
0
],
{
path
:
'from to'
,
select
:
'uid nickName icon comments'
},
function
(
err
,
c
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
results
[
0
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
// res.json(returnCode.SUCCESS);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除文章评论
router
.
post
(
'/thread/:tid/comment/:cid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
if
(
result
.
from
===
user
.
getMobileUser
(
req
))
{
async
.
parallel
([
function
(
callback
)
{
forumCommentService
.
deleteCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
if
(
result
.
from
===
user
.
getMobileUser
(
req
))
{
async
.
parallel
([
function
(
callback
)
{
forumCommentService
.
deleteCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论列表
router
.
get
(
'/thread/:tid/comment/list'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
'1'
};
if
(
tid
)
{
//获取最新5条评论
forumCommentService
.
getAllComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
'1'
};
if
(
tid
)
{
//获取最新5条评论
forumCommentService
.
getAllComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论点赞
router
.
post
(
'/thread/:tid/comment/:cid/raise'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
){
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
//判断是否已经点赞
forumPraiseLogService
.
queryPraiseLog
(
tid
,
cid
,
user
.
getMobileUser
(
req
),
2
,
function
(
err
,
logs
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
logs
&&
logs
.
length
>
0
){
res
.
json
(
returnCode
.
CAN_NOT_RAISE_REPEAT
);
}
else
{
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'raise'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
){
forumCommentService
.
updatePraiseCount
(
cid
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
callback
){
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
ip
:
req
.
ip
,
comment
:
cid
,
type
:
2
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}],
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
user
.
getOpenId
(
req
),
tid
,
'raise'
);
//返回点赞总数
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
doc
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
praise_count
=
doc
.
praise_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
//判断是否已经点赞
forumPraiseLogService
.
queryPraiseLog
(
tid
,
cid
,
user
.
getMobileUser
(
req
),
2
,
function
(
err
,
logs
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
logs
&&
logs
.
length
>
0
)
{
res
.
json
(
returnCode
.
CAN_NOT_RAISE_REPEAT
);
}
else
{
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'raise'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
forumCommentService
.
updatePraiseCount
(
cid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
},
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
tid
,
ip
:
req
.
ip
,
comment
:
cid
,
type
:
2
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment_praise'
);
//返回点赞总数
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
praise_count
=
doc
.
praise_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//用户屏蔽文章
router
.
post
(
'/thread/:tid/userShield'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
doc
){
var
thread
=
doc
.
thread
;
thread
.
push
(
tid
);
forumUserThreadControlService
.
updateUserThreadControlById
(
doc
.
_id
,{
thread
:
thread
},
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
var
array
=
[
tid
];
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
array
};
forumUserThreadControlService
.
createUserThreadControl
(
entity
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
doc
)
{
var
thread
=
doc
.
thread
;
thread
.
push
(
tid
);
forumUserThreadControlService
.
updateUserThreadControlById
(
doc
.
_id
,
{
thread
:
thread
},
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
var
array
=
[
tid
];
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
thread
:
array
};
forumUserThreadControlService
.
createUserThreadControl
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取论坛话题列表
router
.
get
(
'/thread/:tid/topics'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
2
};
if
(
tid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
2
};
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取论坛最新照片墙列表
router
.
get
(
'/thread/:tid/latestPhotos'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
};
if
(
tid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-created'
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
};
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-created'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取论坛最热照片墙列表
router
.
get
(
'/thread/:tid/hotPhotos'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
};
if
(
tid
){
async
.
waterfall
([
function
(
callback
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
if
(
doc
){
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
};
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
doc
);
}
else
{
callback
(
null
,
null
);
}
}
});
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-praise_count'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/models/forumPVLog.js
0 → 100644
View file @
0ed28b1f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//话题广场,板块
var
ForumPVLogSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
user
:
{
//访问者
type
:
String
,
require
:
true
,
index
:
true
,
ref
:
'ForumUser'
},
mid
:
{
//会员ID
type
:
Number
,
require
:
true
,
index
:
true
},
open_id
:
{
//微信公众号唯一识别
type
:
String
,
require
:
true
,
index
:
true
},
info
:
{
//板块ID
type
:
String
,
index
:
true
,
ref
:
'ForumInfo'
},
thread
:
{
//话题、文章、照片墙的ID
type
:
String
,
index
:
true
,
ref
:
'forumThread'
},
type
:
{
//页面:1.主页 2.板块 3.文章
type
:
Number
,
index
:
true
,
require
:
true
},
thread_type
:
{
//文章类型:1.普通文章 2.话题 3.照片墙 4.子文章
type
:
Number
,
index
:
true
},
p_thread
:
{
//父文章ID
type
:
Number
,
index
:
true
},
source
:
{
//分享者
type
:
String
},
ip
:
{
//IP地址
type
:
String
},
userAgent
:
{
type
:
String
},
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_pv_log'
});
module
.
exports
=
mongoose
.
model
(
'ForumPVLog'
,
ForumPVLogSchema
);
app/models/forumThread.js
View file @
0ed28b1f
...
...
@@ -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/models/forumUVLog.js
0 → 100644
View file @
0ed28b1f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//话题广场,板块
var
ForumUVLogSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
user
:
{
//访问者
type
:
String
,
require
:
true
,
index
:
true
,
ref
:
'ForumUser'
},
mid
:
{
//会员ID
type
:
Number
,
require
:
true
,
index
:
true
},
open_id
:
{
//微信公众号唯一识别
type
:
String
,
require
:
true
,
index
:
true
},
info
:
{
//板块ID
type
:
String
,
index
:
true
,
ref
:
'ForumInfo'
},
thread
:
{
//话题、文章、照片墙的ID
type
:
String
,
index
:
true
,
ref
:
'forumThread'
},
type
:
{
//页面:1.主页 2.板块 3.文章
type
:
Number
,
index
:
true
,
require
:
true
},
thread_type
:
{
//文章类型:1.话题 2.文章 3.照片墙 4.子文章
type
:
Number
,
index
:
true
},
p_thread
:
{
//父文章ID
type
:
Number
,
index
:
true
},
source
:
{
//分享者
type
:
String
},
ip
:
{
//IP地址
type
:
String
},
userAgent
:
{
type
:
String
},
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_uv_log'
});
module
.
exports
=
mongoose
.
model
(
'ForumUVLog'
,
ForumUVLogSchema
);
app/service/forumThreadService.js
View file @
0ed28b1f
...
...
@@ -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,15 +10,39 @@ var async = require('async');
//创建文章
exports
.
createThread
=
function
(
entity
,
callback
)
{
var
forum
=
new
ForumThread
(
entity
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
forum
);
}
});
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
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
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
);
...
...
@@ -61,7 +86,7 @@ exports.getThreadById = function(tid, callback) {
thread
:
tid
,
level
:
'1'
};
//获取最新10条评论
//获取最新10条评论
forumCommentService
.
getAllComment
(
conditions
,
1
,
10
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
...
...
@@ -165,16 +190,64 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章
exports
.
updateThreadById
=
function
(
tid
,
entity
,
callback
)
{
ForumThread
.
update
({
_id
:
tid
},
entity
,
null
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
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
);
}
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
{
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更新文章
...
...
@@ -402,17 +475,17 @@ exports.getAllThreadByFid = function(conditions, pageNo, pageSize, sort, callbac
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
exports
.
updateTopByThreadId
=
function
(
infoId
,
threadId
,
callback
)
{
// ForumThread.update({info:infoId}, {top:0},{multi:true}, function(err, doc) {
//
if(err){
//
callback(err,null);
//
}else{
//
ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) {
//
if(err){
//
callback(err,null);
//
}else{
//
callback(null,null);
//
}
//
});
//
}
//
if(err){
//
callback(err,null);
//
}else{
//
ForumThread.findOneAndUpdate({_id:threadId}, {top:1}, function(err, doc) {
//
if(err){
//
callback(err,null);
//
}else{
//
callback(null,null);
//
}
//
});
//
}
// });
ForumThread
.
findOneAndUpdate
({
_id
:
threadId
...
...
app/service/httpService.js
View file @
0ed28b1f
...
...
@@ -2,10 +2,97 @@
// var request=require('request');
// var REMOTE_URL='http://127.0.0.1:3011/admin/forum/http/receive';
var
ACTION_KEY
=
{
'post'
:
'FORUM_THREAD_POST'
,
'share'
:
'FORUM_THREAD_SHARE'
,
'share_timeline'
:
'FORUM_THREAD_SHARE_TIMELINE'
,
'comment'
:
'FORUM_THREAD_COMMENT'
,
'thread_praise'
:
'FORUM_THREAD_PRAISE'
,
'comment_praise'
:
'FORUM_COMMENT_PRAISE'
,
'reply'
:
'FORUM_COMMENT_REPLY'
,
'user_from_share'
:
'FORUM_USER_FROM_SHARE'
};
var
mongoose
=
require
(
'mongoose'
),
moment
=
require
(
'moment'
),
then
=
require
(
'thenjs'
);
exports
.
sendRequest
=
function
(
ent_code
,
uid
,
tid
,
action
){
// var url=REMOTE_URL+'?ent_code='+ent_code+'&uid='+uid+'&tid='+tid+'&action='+action;
// request.get({url:url}, function (e, r, body) {
// });
};
\ No newline at end of file
var
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
var
ForumUVLog
=
mongoose
.
model
(
'ForumUVLog'
);
exports
.
sendRequest
=
function
(
ent_code
,
mid
,
action
,
messageid
,
integral
,
exp
)
{
var
obj
=
{
tag
:
'member'
,
key
:
'forum'
,
action
:
ACTION_KEY
[
action
],
mid
:
mid
,
entcode
:
ent_code
,
messageid
:
messageid
||
''
,
integral
:
integral
||
0
,
exp
:
exp
||
0
};
redis
.
lpush
(
'adapter-redis-to-ons'
,
JSON
.
stringify
(
obj
),
function
(
err
,
reply
)
{
if
(
err
)
{
console
.
error
(
err
);
}
});
};
var
getClientIP
=
function
(
req
)
{
var
ipAddress
;
var
headers
=
req
.
headers
;
var
forwardedIpsStr
=
headers
[
'x-real-ip'
]
||
headers
[
'x-forwarded-for'
];
if
(
forwardedIpsStr
)
{
ipAddress
=
forwardedIpsStr
;
}
else
{
ipAddress
=
null
;
}
if
(
!
ipAddress
)
{
ipAddress
=
req
.
connection
.
remoteAddress
;
}
return
ipAddress
;
};
exports
.
createLog
=
function
(
req
,
info
,
type
,
thread_type
,
thread
,
p_thread
)
{
var
logObj
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
mid
:
req
.
session
.
openUser
.
mid
,
open_id
:
req
.
session
.
mobileForumUser
.
openId
,
user
:
req
.
session
.
mobileForumUser
.
userId
,
info
:
info
,
type
:
type
,
thread_type
:
thread_type
,
thread
:
thread
,
p_thread
:
p_thread
,
ip
:
getClientIP
(
req
),
userAgent
:
req
.
headers
[
'user-agent'
]
};
if
(
logObj
)
{
then
(
function
(
cont
){
var
pv_model
=
new
ForumPVLog
(
logObj
);
pv_model
.
save
(
cont
);
}).
then
(
function
(
cont
){
var
q
=
{
created
:{
$gte
:
moment
(
new
Date
()).
format
(
'YYYY-MM-DD'
)},
mid
:
logObj
.
mid
,
openId
:
logObj
.
openId
,
user
:
logObj
.
user
,
info
:
logObj
.
info
};
if
(
logObj
.
thread
){
q
.
thread
=
logObj
.
thread
;
q
.
thread_type
=
logObj
.
thread_type
;
}
ForumUVLog
.
findOne
(
q
,
function
(
err
,
doc
){
cont
(
err
,
doc
?
false
:
true
);
})
}).
then
(
function
(
cont
,
isLog
){
if
(
isLog
){
var
uv_model
=
new
ForumUVLog
(
logObj
);
uv_model
.
save
();
}
}).
fail
(
function
(
cont
,
err
){
console
.
error
(
err
);
});
}
else
{
console
.
error
(
'没有日志信息'
);
}
};
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