Commit 416642cb authored by 陈家荣's avatar 陈家荣

改接口2

parent 6dbe6a4c
...@@ -581,45 +581,23 @@ router.post('/getThreadSexStatistic', function(req, res, next) { ...@@ -581,45 +581,23 @@ router.post('/getThreadSexStatistic', function(req, res, next) {
//社区情况(首页_第二版) //社区情况(首页_第二版)
router.get('/statistic_v2', function(req, res, next) { router.get('/statistic_v2', function(req, res, next) {
var yesterday = moment(new Date(req.query.day)).format('YYYY-MM-DD'),
before_yesterday = moment(new Date(req.query.day).getTime() - 1 * 24 * 3600 * 1000).format('YYYY-MM-DD');
var ent_code = req.query.ent_code, var ent_code = req.query.ent_code,
y_begin = new Date(yesterday), //昨天开始时间 y_begin = new Date(req.query.day + ' 00:00:00'), //开始时间
y_end = new Date(yesterday + ' 23:59:59'), //昨天结束时间 y_end = new Date(req.query.day + ' 23:59:59'); //结束时间
by_begin = new Date(before_yesterday), //前天开始时间
by_end = new Date(before_yesterday + ' 23:59:59'); //前天结束时间
then.parallel([ then.parallel([
function(cont) { function(cont) {
//昨天访问用户 //昨天访问用户
var match = { var match = {
ent_code: ent_code, ent_code: Number(ent_code),
created: { created: {
$gte: y_begin, $gte: y_begin,
$lte: y_end $lte: y_end
} }
}; };
aggregate(ForumUvLog, match, { aggregate(ForumUvLog, match, {
mid: '$mid' open_id: '$open_id'
}, {
'count': -1
}, function(err, docs) {
cont(err, docs.length);
});
},
function(cont) {
//前天访问用户
var match = {
ent_code: ent_code,
created: {
$gte: by_begin,
$lte: by_end
}
};
aggregate(ForumUvLog, match, {
mid: '$mid'
}, { }, {
'count': -1 'created': -1
}, function(err, docs) { }, function(err, docs) {
cont(err, docs.length); cont(err, docs.length);
}); });
...@@ -627,7 +605,7 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -627,7 +605,7 @@ router.get('/statistic_v2', function(req, res, next) {
function(cont) { function(cont) {
//昨天发帖数 //昨天发帖数
var match = { var match = {
ent_code: ent_code, ent_code: Number(ent_code),
created: { created: {
$gte: y_begin, $gte: y_begin,
$lte: y_end $lte: y_end
...@@ -638,38 +616,21 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -638,38 +616,21 @@ router.get('/statistic_v2', function(req, res, next) {
}); });
}, },
function(cont) { function(cont) {
//前天发帖数 //总访问量
var match = { var match = {
ent_code: ent_code, ent_code: Number(ent_code),
created: {
$gte: by_begin,
$lte: by_end
}
};
ForumThread.count(match, function(err, count) {
cont(err, count);
});
},
function(cont) {
//总访问用户
var match = {
ent_code: ent_code,
created:{ created:{
$lte: y_end $lte: y_end
} }
}; };
aggregate(ForumUvLog, match, { ForumPvLog.count(match, function(err, count) {
mid: '$mid' cont(err, count);
}, {
'count': -1
}, function(err, docs) {
cont(err, docs.length);
}); });
}, },
function(cont) { function(cont) {
//总发帖数 //总发帖数
var match = { var match = {
ent_code: ent_code, ent_code: Number(ent_code),
created: { created: {
$lte: y_end $lte: y_end
} }
...@@ -678,28 +639,15 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -678,28 +639,15 @@ router.get('/statistic_v2', function(req, res, next) {
cont(err, count); cont(err, count);
}); });
} }
]).then(function(cont, datas) { ]).then(function(cont, results) {
var y_user = datas[0],
by_user = datas[1],
y_thread = datas[2],
by_thread = datas[3],
all_user = datas[4],
all_thread = datas[5];
//计算昨天比前天多 多少 的百分比
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, all_user, all_thread);
}).then(function(cont, y_user, user_rate, y_thread, thread_rate, all_user, all_thread) {
//返回数据 //返回数据
res.json({ res.json({
result: true, result: true,
data: { data: {
user: y_user, user: results[0],
user_rate: Math.round(user_rate > 1 ? 100 : user_rate < 0 ? 0 : user_rate * 100), thread: results[1],
thread: y_thread, all_user: results[2],
thread_rate: Math.round(thread_rate > 1 ? 100 : thread_rate < 0 ? 0 : thread_rate * 100), all_thread: results[3]
all_user: all_user,
all_thread: all_thread
} }
}) })
}).fail(function(cont, err) { }).fail(function(cont, err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment