Commit e16a1991 by liimin

完善接口

1 parent e1885f9c
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:20:01 * @Date: 2019-11-21 11:20:01
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-12 15:57:29 * @Last Modified time: 2019-12-17 16:48:14
*/ */
"use strict"; "use strict";
...@@ -196,20 +196,22 @@ class UserController extends Controller { ...@@ -196,20 +196,22 @@ class UserController extends Controller {
* @Request query integer pid 省份id * @Request query integer pid 省份id
*/ */
async statistics({ query: { pid,cid } }) { async statistics({ query: { pid,cid } }) {
var { r, u } = await this._fetch_total_last_day_({ pid,cid,field:['r','u']}); var { r, u, rt, a7, a30 } = await this._fetch_total_last_day_({ pid,cid,field:['r','u', 'rt', 'a7', 'a30']});
console.log(a7,a30);
// 昨天的付费转化率 (昨天的付费总人数 / 昨天用户总数) // 昨天的付费转化率 (昨天的付费总人数 / 昨天用户总数)
const renew = this.helper.percent(r,u); const renew = this.helper.percent(r,u);
const beginDate7 = this.helper.date(-7); const beginDate7 = this.helper.date(-7);
const { yesterday } = await this._fetch_date_in_cache_(); const { yesterday } = await this._fetch_date_in_cache_();
//近7天所有 //近7天所有
const { i:increased7,a:nLive7 } = await this._fetch_total_by_range_({ pid, cid, field:['i','a'],beginDate:beginDate7,endDate:yesterday}); const { i:increased7 } = await this._fetch_total_by_range_({ pid, cid, field:['i'],beginDate:beginDate7,endDate:yesterday});
// 近七天 用户活跃度 (近7天 活跃用户数 / 昨天用户数) // 近七天 用户活跃度 (昨天的数据: 近7天 活跃用户数 / 昨天用户数)
const live7 = this.helper.percent(nLive7,u); const live7 = this.helper.percent(a7,rt);
//近30天所有 //近30天所有
const { i:increased30,a:nLive30 } = await this._fetch_total_by_range_({ pid, cid, field:['i','a']}); const { i:increased30 } = await this._fetch_total_by_range_({ pid, cid, field:['i']});
// 近30天 用户活跃度 (近30天 活跃用户数 / 昨天用户数) // 近30天 用户活跃度 (昨天的数据: 近30天 活跃用户数 / 昨天用户数)
const live30 = this.helper.percent(nLive30,u); const live30 = this.helper.percent(a30,rt);
const data = { increased7, live7,increased30,live30,renew }; const data = { increased7, live7,increased30,live30,renew };
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:19:43 * @Date: 2019-11-21 11:19:43
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-12 15:10:54 * @Last Modified time: 2019-12-17 16:46:08
*/ */
const moment = require("moment"); const moment = require("moment");
...@@ -57,7 +57,7 @@ exports.json_stringify = obj => { ...@@ -57,7 +57,7 @@ exports.json_stringify = obj => {
* *
*/ */
exports.percent = (num, total, fixed = 2) => exports.percent = (num, total, fixed = 2) =>
((~~num / ~~total) * 100).toFixed(fixed) + "%"; (~~((~~num / ~~total) * 100).toFixed(fixed)) + "%";
/** /**
* 简单封装 sequelize 查询参数 * 简单封装 sequelize 查询参数
......
...@@ -64,6 +64,21 @@ module.exports = app => { ...@@ -64,6 +64,21 @@ module.exports = app => {
update_time: { update_time: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: true allowNull: true
},
recent_total: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
recent_7_day_active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
recent_30_day_active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
} }
}, { }, {
tableName: 't_user_city_daily' tableName: 't_user_city_daily'
......
...@@ -36,7 +36,7 @@ class UpdateCache extends Subscription { ...@@ -36,7 +36,7 @@ class UpdateCache extends Subscription {
function __init_or_plus__(target, obj) { function __init_or_plus__(target, obj) {
target = target || {}; target = target || {};
if (obj) { if (obj) {
const { r, u, a, i, j, m, o } = obj; const { r, u, a, i, j, m, o, rt, a7, a30 } = obj;
target["r"] += +r; //续费 renew target["r"] += +r; //续费 renew
target["u"] += +u; //用户总数 user target["u"] += +u; //用户总数 user
target["a"] += +a; // 活跃用户数 active target["a"] += +a; // 活跃用户数 active
...@@ -44,6 +44,9 @@ class UpdateCache extends Subscription { ...@@ -44,6 +44,9 @@ class UpdateCache extends Subscription {
target["j"] += +j; // 出行 journey target["j"] += +j; // 出行 journey
target["m"] += +m; // 里程 miles target["m"] += +m; // 里程 miles
target["o"] += +o; // online 在线时间 target["o"] += +o; // online 在线时间
target["rt"] += +rt; // 最近总数
target["a7"] += +a7; // 近7天 活跃数
target["a30"] += +a30; // 近30天 活跃数
} else { } else {
target["r"] = 0; //续费 renew target["r"] = 0; //续费 renew
target["u"] = 0; //用户总数 user target["u"] = 0; //用户总数 user
...@@ -52,19 +55,22 @@ class UpdateCache extends Subscription { ...@@ -52,19 +55,22 @@ class UpdateCache extends Subscription {
target["j"] = 0; // 出行 journey target["j"] = 0; // 出行 journey
target["m"] = 0.0; // 里程 miles target["m"] = 0.0; // 里程 miles
target["o"] = 0; // online 在线时间 target["o"] = 0; // online 在线时间
target["rt"] = 0; // 最近总数
target["a7"] = 0; // 近7天 活跃数
target["a30"] = 0; // 近30天 活跃数
} }
return target; return target;
} }
cities.forEach( cities.forEach(
function(city) { function(city) {
const prov_code = f(city); const prov_code = f(city);
let { city_code, total_user: u, renew: r, active: a, increase: i, journey: j, miles: m, online_time: o, day } = city; let { city_code, total_user: u, renew: r, active: a, increase: i, journey: j, miles: m, online_time: o, day,recent_total:rt, recent_7_day_active:a7, recent_30_day_active:a30} = city;
date = this.helper.moment(day).isAfter(date) ? day : date; date = this.helper.moment(day).isAfter(date) ? day : date;
data[day] = data[day] || Object.assign(__init_or_plus__(null),{'p':{}}) //如果day 节点不存在 则 初始化一个 data[day] = data[day] || Object.assign(__init_or_plus__(null),{'p':{}}) //如果day 节点不存在 则 初始化一个
data[day] = __init_or_plus__(data[day], { r, u, a, i, j, m, o }); // 累加全国总数值 data[day] = __init_or_plus__(data[day], { r, u, a, i, j, m, o, rt, a7, a30 }); // 累加全国总数值
data[day]["p"][prov_code] = data[day]["p"][prov_code] || Object.assign(__init_or_plus__(null),{'c':{}}); //如果day 下的 省份 不存在 则 初始化一个 data[day]["p"][prov_code] = data[day]["p"][prov_code] || Object.assign(__init_or_plus__(null),{'c':{}}); //如果day 下的 省份 不存在 则 初始化一个
data[day]["p"][prov_code] = __init_or_plus__(data[day]["p"][prov_code], { r, u, a, i, j, m, o }); //累加 prov_code 省份总数据 data[day]["p"][prov_code] = __init_or_plus__(data[day]["p"][prov_code], { r, u, a, i, j, m, o, rt, a7, a30 }); //累加 prov_code 省份总数据
data[day]["p"][prov_code]["c"][city_code] = { u, r, a, i, j, m, o }; data[day]["p"][prov_code]["c"][city_code] = { u, r, a, i, j, m, o, rt, a7, a30 };
}.bind(this) }.bind(this)
); );
return { data, date }; return { data, date };
...@@ -103,7 +109,7 @@ class UpdateCache extends Subscription { ...@@ -103,7 +109,7 @@ class UpdateCache extends Subscription {
value value
); );
cache_data_last_date = date; //更新缓存数据最新时间 cache_data_last_date = date; //更新缓存数据最新时间
this.logger.info("user_summary_%s([%s]):%s",data.date,Object.keys(data).join(","),value); this.logger.info("user_summary_%s([%s])",date,Object.keys(data).join(","));
}else{ }else{
this.logger.info("cache_date:%s date:%s 不写缓存",cache_data_last_date,date); this.logger.info("cache_date:%s date:%s 不写缓存",cache_data_last_date,date);
} }
......
...@@ -181,6 +181,9 @@ class UserService extends Service { ...@@ -181,6 +181,9 @@ class UserService extends Service {
'increase', 'increase',
'journey', 'journey',
'miles', 'miles',
'recent_total',
'recent_7_day_active',
'recent_30_day_active',
"online_time", "online_time",
'day', 'day',
col("t_city.city_name"), col("t_city.city_name"),
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:26:53 * @Date: 2019-11-16 09:26:53
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-07 12:19:13 * @Last Modified time: 2019-12-19 16:38:17
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -137,6 +137,6 @@ module.exports = app => { ...@@ -137,6 +137,6 @@ module.exports = app => {
user_cache_update_time_diff : 1 * 60 * 1000, user_cache_update_time_diff : 1 * 60 * 1000,
// 激活用户队列大小 // 激活用户队列大小
user_activation_queue_size : 10 user_activation_queue_size : 10
} };
return config; return config;
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:26:47 * @Date: 2019-11-16 09:26:47
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-11-21 17:25:19 * @Last Modified time: 2019-12-19 18:07:10
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -27,11 +27,11 @@ module.exports = appInfo => { ...@@ -27,11 +27,11 @@ module.exports = appInfo => {
// myAppName: 'egg', // myAppName: 'egg',
config.sequelize = { config.sequelize = {
dialect: "mysql", dialect: "mysql",
host: "192.168.0.39", host: "14.17.100.222",
port: 3306, port: "3307",
database: "glsx_data_screen", database: "glsx_data_screen",
username: "root", username: "dev_limin",
password: "123456" password: "fdseooui"
}; };
return config; return config;
}; };
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-16 09:26:40 * @Date: 2019-11-16 09:26:40
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-11-21 17:56:42 * @Last Modified time: 2019-12-19 15:49:03
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -25,13 +25,5 @@ module.exports = appInfo => { ...@@ -25,13 +25,5 @@ module.exports = appInfo => {
}; };
// add your user config here // add your user config here
// myAppName: 'egg', // myAppName: 'egg',
config.sequelize = {
dialect: "mysql",
host: "192.168.0.39",
port: 3306,
database: "glsx_data_screen",
username: "root",
password: "123456"
};
return config; return config;
}; };
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!