APP ID是pfBKo2YGLcilMUd6yzjQID27-gzGzoHsz
没有查询操作
function go() {
console.log('we go!'+new Date());
async.waterfall([
//获取所有户的appid,放到list集合里
function (callback) {
var userId='c03d80f07c144cdab5e881866b92ad9f';//shuge
//var url='http://101.200.130.178/api/get/customer/'+userId;
var url=urls_api.getUsersByUserId(userId);
var list=[];
request(url,function (error,response,body) {
var str=JSON.parse(body);
//console.log(str);
str.customers.forEach(function (item) {
list.push({
appid:item.appid,
username:item.username
});
});
callback(null,list);
});
},function (list,callback) {
//遍历appid的list
//获取今天的日期
var count=0;
async.eachLimit(list,5,function (item,cb) {
var appid = item.appid;
var day = moment(new Date()).format('DD');
var i = day - 1;
var new_date = moment(new Date()).format('YYYY-MM-') + i;
//获取昨日的消费等数据,存放在leancloud里
var url = urls_api.getRealtimeUrl(appid, new_date);
request(url, function (error, response, bodystr) {
if (!error && response.statusCode == 200) {
try{
var body = JSON.parse(bodystr);
}catch (e){
console.log(bodystr);
console.log(url);
}
item.cost = body.cost;
var data = new dataAV();
data.set('username', item.username);
data.set('appid', item.appid);
data.set('cost', body.cost);
data.set('total_pv', body.total_pv_count);
data.set('total_count', body.total_download_count);
data.set('total_active', body.active_total_count);
data.set('ios_total_count', body.ios_total_count);
data.set('android_total_pv', body.android_total_pv);
data.set('android_total_count', body.android_total_count);
data.set('ios_total_pv', body.ios_total_pv);
data.set('month', moment(new Date() - 1000 * 60 * 60 * 24).format('MM'));
data.set('date', moment(new Date() - 1000 * 60 * 60 * 24).format('YYYY-MM-DD'));
data.save().then(function (ob) {
cb();
}, function (error) {
if (error) {
console.log(error.message);
}else{
}
});
}
})
},function (err) {
if (err){
console.log(err.message);
}else{
}
});
},function (list,callback) {
console.log('success!');
//console.log(list);
callback(null);
}
],function (err) {
if(err){
console.log(err.message);
}
});
}