Commit a8118d00 authored by 刘文胜's avatar 刘文胜

社区统计接口

parent 89aa79ec
...@@ -568,8 +568,9 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -568,8 +568,9 @@ router.get('/statistic_v2', function(req, res, next) {
var ent_code = req.query.ent_code, var ent_code = req.query.ent_code,
y_begin = new Date(req.query.day + ' 00:00:00'), //开始时间 y_begin = new Date(req.query.day + ' 00:00:00'), //开始时间
y_end = new Date(req.query.day + ' 23:59:59'); //结束时间 y_end = new Date(req.query.day + ' 23:59:59'); //结束时间
then.parallel([ then.series([
function(cont) { function(cont) {
var s1 = new Date().getTime();
//昨天访问用户 //昨天访问用户
var match = { var match = {
ent_code: Number(ent_code), ent_code: Number(ent_code),
...@@ -578,15 +579,27 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -578,15 +579,27 @@ router.get('/statistic_v2', function(req, res, next) {
$lte: y_end $lte: y_end
} }
}; };
aggregate(ForumUvLog, match, { var o = {};
open_id: '$open_id' var emit;
}, { o.map = function () {
'created': -1 emit(this.open_id, 1);
}, function(err, docs) { };
o.reduce = function (k, vals) {
var sum = 0;
vals.forEach(function(val){
sum+=val;
});
return sum;
};
o.query = match;
ForumUvLog.mapReduce(o, function (err, docs) {
console.log('耗时1',(new Date().getTime()-s1)/1000);
cont(err, docs.length); cont(err, docs.length);
}); });
}, },
function(cont) { function(cont) {
var s1 = new Date().getTime();
//昨天发帖数 //昨天发帖数
var match = { var match = {
ent_code: Number(ent_code), ent_code: Number(ent_code),
...@@ -596,10 +609,12 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -596,10 +609,12 @@ router.get('/statistic_v2', function(req, res, next) {
} }
}; };
ForumThread.count(match, function(err, count) { ForumThread.count(match, function(err, count) {
console.log('耗时2',(new Date().getTime()-s1)/1000);
cont(err, count); cont(err, count);
}); });
}, },
function(cont) { function(cont) {
var s1 = new Date().getTime();
//总访问量 //总访问量
var match = { var match = {
ent_code: Number(ent_code), ent_code: Number(ent_code),
...@@ -608,10 +623,12 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -608,10 +623,12 @@ router.get('/statistic_v2', function(req, res, next) {
} }
}; };
ForumPvLog.count(match, function(err, count) { ForumPvLog.count(match, function(err, count) {
console.log('耗时3',(new Date().getTime()-s1)/1000);
cont(err, count); cont(err, count);
}); });
}, },
function(cont) { function(cont) {
var s1 = new Date().getTime();
//总发帖数 //总发帖数
var match = { var match = {
ent_code: Number(ent_code), ent_code: Number(ent_code),
...@@ -620,6 +637,7 @@ router.get('/statistic_v2', function(req, res, next) { ...@@ -620,6 +637,7 @@ router.get('/statistic_v2', function(req, res, next) {
} }
}; };
ForumThread.count(match, function(err, count) { ForumThread.count(match, function(err, count) {
console.log('耗时4',(new Date().getTime()-s1)/1000);
cont(err, count); cont(err, count);
}); });
} }
......
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