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
a6375040
Commit
a6375040
authored
Jan 25, 2016
by
陈家荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加获取最新帖子接口,/thread/getThreadWithNotPopulateComment
parent
ab6de49e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
151 additions
and
19 deletions
+151
-19
forumThread.js
app/controllers/mobile/forumThread.js
+90
-18
forumThreadService.js
app/service/forumThreadService.js
+61
-1
No files found.
app/controllers/mobile/forumThread.js
View file @
a6375040
...
...
@@ -1776,25 +1776,50 @@ router.post('/thread/:tid/disable', function(req, res, next) {
//获取推荐文章
router
.
get
(
'/thread/getThreadWithEssence'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
,
pageSize
=
req
.
query
.
pageSize
||
10
,
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
pageNo
&&
pageSize
)
{
var
q
=
{
ent_code
:
ent_code
,
new_recommend
:
1
};
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
sort
=
'-new_recommend_time'
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
new_recommend
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
pageNo
,
pageSize
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
function
(
error
,
docs
)
{
_
.
forEach
(
results
.
items
,
function
(
d
,
i
)
{
if
(
results
.
items
[
i
].
toObject
)
{
results
.
items
[
i
]
=
results
.
items
[
i
].
toObject
();
}
results
.
items
[
i
].
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
results
.
items
[
i
].
_id
==
docs
[
k
])
{
results
.
items
[
i
].
isPraise
=
true
;
break
;
}
};
forumThreadService
.
findThread
(
pageNo
,
pageSize
,
q
,
'-new_recommend_time'
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
});
}
});
});
...
...
@@ -1826,4 +1851,51 @@ router.get('/thread/searchThread', function(req, res, next) {
err
:
'params error'
});
}
});
//查询帖子列表数据,不获取评论,话题获取参与用
router
.
get
(
'/thread/getThreadWithNotPopulateComment'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
sort
=
'-top -topTime -quality -created'
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
pageNo
,
pageSize
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
function
(
error
,
docs
)
{
_
.
forEach
(
results
.
items
,
function
(
d
,
i
)
{
if
(
results
.
items
[
i
].
toObject
)
{
results
.
items
[
i
]
=
results
.
items
[
i
].
toObject
();
}
results
.
items
[
i
].
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
results
.
items
[
i
].
_id
==
docs
[
k
])
{
results
.
items
[
i
].
isPraise
=
true
;
break
;
}
};
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
});
}
});
});
\ No newline at end of file
app/service/forumThreadService.js
View file @
a6375040
...
...
@@ -720,7 +720,6 @@ function populateSubComment(subComments, callback) {
//获取数量
function
countAllByFid
(
conditions
,
callback
)
{
// callback(null, 21);
ForumThread
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -1255,4 +1254,65 @@ exports.updateByIdWithOptions = function(condition, entity, options, callback) {
callback
(
null
,
null
);
}
});
};
//查询列表数据,不获取评论,话题获取参与用户
exports
.
getThreadWithNotPopulateComment
=
function
(
conditions
,
pageNo
,
pageSize
,
sort
,
callback
)
{
countAllByFid
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
var
sortBy
=
'-topTime -quality -created'
;
if
(
sort
)
{
sortBy
=
sort
;
}
ForumThread
.
find
(
conditions
).
populate
({
path
:
'from'
,
select
:
'uid mid nickName icon honorTitles'
,
options
:
{
populate
:
"honorTitles"
//继续查荣誉
}
}).
limit
(
limit
).
skip
(
skip
).
sort
(
sortBy
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
obj
=
{};
obj
.
total
=
count
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
;
if
(
docs
&&
docs
.
length
>
0
)
{
var
asyncTasks
=
[];
docs
.
forEach
(
function
(
doc
)
{
if
(
!
(
doc
.
type
===
1
||
doc
.
level
!==
1
))
{
//照片墙或文章时获取参与用户
asyncTasks
.
push
(
function
(
callback
)
{
getSubThreads
(
doc
,
null
,
callback
);
});
}
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
obj
.
items
=
results
;
callback
(
null
,
obj
);
}
});
}
else
{
callback
(
null
,
obj
);
}
}
});
}
});
};
\ 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