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

社区统计接口

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