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
16beef1e
Commit
16beef1e
authored
Apr 27, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
管理平台 - 首页 - 社区情况接口修改
parent
80968d60
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
14 deletions
+41
-14
forumLog.js
app/controllers/admin/forumLog.js
+41
-14
No files found.
app/controllers/admin/forumLog.js
View file @
16beef1e
...
...
@@ -14,45 +14,72 @@ var ForumPvLog = mongoose.model('ForumPVLog'),
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
var
aggregate
=
function
(
model
,
match
,
group_id
,
sort
,
callback
){
model
.
aggregate
(
{
$match
:
match
},
{
$group
:
{
_id
:
group_id
,
count
:
{
$sum
:
1
}
}
},
{
$sort
:
sort
},
function
(
err
,
docs
){
callback
(
err
,
docs
);
});
}
//社区情况(首页)
router
.
get
(
'/statistic'
,
function
(
req
,
res
,
next
)
{
var
yesterday
=
moment
(
new
Date
().
getTime
()
-
24
*
3600
*
1000
).
format
(
'YYYY-MM-DD'
),
before_yesterday
=
moment
(
new
Date
().
getTime
()
-
2
*
24
*
3600
*
1000
).
format
(
'YYYY-MM-DD'
);
var
y_begin
=
yesterday
,
y_
end
=
yesterday
+
' 23:59:59'
,
by_begin
=
before_yesterday
,
by_
end
=
before_yesterday
+
' 23:59:59'
;
var
q
=
{
ent_code
:
req
.
session
.
user
.
ent_code
};
var
ent_code
=
req
.
session
.
user
.
ent_code
,
y_
begin
=
new
Date
(
yesterday
),
//昨天开始时间
y_end
=
new
Date
(
yesterday
+
' 23:59:59'
),
//昨天结束时间
by_
begin
=
new
Date
(
before_yesterday
),
//前天开始时间
by_end
=
new
Date
(
before_yesterday
+
' 23:59:59'
);
//前天结束时间
then
.
parallel
([
function
(
cont
){
//昨天访问用户
q
.
created
=
{
$gte
:
y_begin
,
$lte
:
y_end
};
ForumUvLog
.
count
(
q
,
cont
);
var
match
=
{
ent_code
:
ent_code
,
created
:{
$gte
:
y_begin
,
$lte
:
y_end
}};
aggregate
(
ForumUvLog
,
match
,{
mid
:
'$mid'
},{
'count'
:
-
1
},
function
(
err
,
docs
){
cont
(
err
,
docs
.
length
);
});
},
function
(
cont
){
//前天访问用户
q
.
created
=
{
$gte
:
by_begin
,
$lte
:
by_end
};
ForumUvLog
.
count
(
q
,
cont
);
var
match
=
{
ent_code
:
ent_code
,
created
:{
$gte
:
by_begin
,
$lte
:
by_end
}};
aggregate
(
ForumUvLog
,
match
,{
mid
:
'$mid'
},{
'count'
:
-
1
},
function
(
err
,
docs
){
cont
(
err
,
docs
.
length
);
});
},
function
(
cont
){
//昨天发帖数
q
.
created
=
{
$gte
:
y_begin
,
$lte
:
y_end
};
ForumThread
.
count
(
q
,
cont
);
var
match
=
{
ent_code
:
ent_code
,
created
:{
$gte
:
y_begin
,
$lte
:
y_end
}};
aggregate
(
ForumThread
,
match
,{
mid
:
'$mid'
},{
'count'
:
-
1
},
function
(
err
,
docs
){
cont
(
err
,
docs
.
length
);
});
},
function
(
cont
){
//前天发帖数
q
.
created
=
{
$gte
:
by_begin
,
$lte
:
by_end
};
ForumThread
.
count
(
q
,
cont
);
var
match
=
{
ent_code
:
ent_code
,
created
:{
$gte
:
by_begin
,
$lte
:
by_end
}};
aggregate
(
ForumThread
,
match
,{
mid
:
'$mid'
},{
'count'
:
-
1
},
function
(
err
,
docs
){
cont
(
err
,
docs
.
length
);
});
}
]).
then
(
function
(
cont
,
datas
){
var
y_user
=
datas
[
0
],
by_user
=
datas
[
1
],
y_thread
=
datas
[
2
],
by_thread
=
datas
[
3
];
//计算昨天比前天多 多少 的百分比
var
user_rate
=
(
by_user
===
0
)?
y_user
:(
y_user
/
by_user
).
toFixed
(
4
)
-
1
,
thread_rate
=
(
by_thread
===
0
)?
y_thread
:(
y_thread
/
by_thread
).
toFixed
(
4
)
-
1
;
cont
(
null
,
y_user
,
user_rate
,
y_thread
,
thread_rate
);
}).
then
(
function
(
cont
,
y_user
,
user_rate
,
y_thread
,
thread_rate
){
//返回数据
res
.
json
({
result
:
true
,
data
:{
user
:
y_user
,
user_rate
:
Math
.
round
(
user_rate
>
1
?
100
:
user_rate
<
0
?
0
:
user_rate
*
100
),
...
...
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