Commit 988e60af by liimin

目录结构调整

1 parent a3ed1bd3
...@@ -38,6 +38,7 @@ const Queue = require("./app/common/queue"); ...@@ -38,6 +38,7 @@ const Queue = require("./app/common/queue");
console.log(' ◆ 3.初始化激活消息队列\r\n') console.log(' ◆ 3.初始化激活消息队列\r\n')
await this._init_user_activation_queue_(ctx) await this._init_user_activation_queue_(ctx)
await this._init_merchant_activation_queue_(ctx)
} }
async _init_user_validations_() { async _init_user_validations_() {
...@@ -63,16 +64,31 @@ const Queue = require("./app/common/queue"); ...@@ -63,16 +64,31 @@ const Queue = require("./app/common/queue");
} }
async _init_user_activation_queue_(ctx) { async _init_user_activation_queue_(ctx) {
let queue = new Queue({size:this.app.config.sys.user_activation_queue_size}); const { service, helper } = ctx;
const { USER_ACTIVE_DATA_LASI_ID } = helper.constant;
const size = this.app.config.sys.user_activation_queue_size
const _last_data = await service.screen.user.user_active({limit:size});
let queue = new Queue({size,data:_last_data.reverse(),cache:service.cache,fetch:service.screen.user.activation,const_id:USER_ACTIVE_DATA_LASI_ID});
this.app.queue = queue; this.app.queue = queue;
// service.cache.set(USER_ACTIVE_DATA_LASI_ID,(_last_data &&_last_data.length && _last_data[0].id) || 0 )
//调用一次真实数据 覆盖初始化数据 //调用一次真实数据 覆盖初始化数据
// const { service, helper } = ctx;
// const { USER_ACTIVE_DATA_LASI_ID } = helper.constant;
// const _last_id = await service.cache.get(USER_ACTIVE_DATA_LASI_ID) || 0;
// const data = this.app.queue.peek();
// this.app.queue.fill(async ()=>await service.screen.user.activation({ limit: queue.size(), last_id:_last_id }),data)
// .then(last_id=>last_id && service.cache.set(USER_ACTIVE_DATA_LASI_ID,last_id))
}
async _init_merchant_activation_queue_(ctx) {
const { service, helper } = ctx; const { service, helper } = ctx;
const { USER_ACTIVE_DATA_LASI_ID } = helper.constant; const { MERCHANT_ACTIVE_DATA_LASI_ID } = helper.constant;
const _last_id = await service.cache.get(USER_ACTIVE_DATA_LASI_ID) || 0; const size = this.app.config.sys.user_activation_queue_size
// const _last_data = await service.screen.user.user_active({id:_last_id}); const _last_data = await service.screen.merchant.merchant_active({limit:size});
const data = this.app.queue.peek(); let queue = new Queue({size,data:_last_data.reverse(),cache:service.cache,fetch:service.screen.merchant.activation,const_id:MERCHANT_ACTIVE_DATA_LASI_ID});
this.app.queue.fill(async ()=>await service.screen.user.activation({ limit: queue.size(), last_id:_last_id }),data) this.app.merchant_queue = queue;
.then(last_id=>last_id && service.cache.set(USER_ACTIVE_DATA_LASI_ID,last_id)) // service.cache.set(MERCHANT_ACTIVE_DATA_LASI_ID,(_last_data && _last_data.length && _last_data[0].id) || 0 )
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:20:15 * @Date: 2019-11-21 11:20:15
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2019-12-07 14:14:31 * @Last Modified time: 2020-01-04 10:47:17
*/ */
module.exports = { module.exports = {
...@@ -11,5 +11,6 @@ module.exports = { ...@@ -11,5 +11,6 @@ module.exports = {
MERCHANT_SUMMARY_30_DAY:'merchant_summary_30_day', MERCHANT_SUMMARY_30_DAY:'merchant_summary_30_day',
MERCHANT_SUMMARY_STATS:'merchant_summary_stats', MERCHANT_SUMMARY_STATS:'merchant_summary_stats',
DATES:'dates', DATES:'dates',
USER_ACTIVE_DATA_LASI_ID:'user_active_data_last_id' USER_ACTIVE_DATA_LASI_ID:'user_active_data_last_id',
MERCHANT_ACTIVE_DATA_LASI_ID:'merchant_active_data_last_id'
}; };
\ No newline at end of file \ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-12-06 14:58:35 * @Date: 2019-12-06 14:58:35
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2020-01-03 18:12:37 * @Last Modified time: 2020-01-04 12:17:19
*/ */
// const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。 // const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
...@@ -58,10 +58,14 @@ ...@@ -58,10 +58,14 @@
// } // }
module.exports = class Queue { module.exports = class Queue {
constructor({size,data,fn}) { constructor({size,data = [],cache,fetch,const_id}) {
this._elements = []; this._elements = data;
this._size = size; this._size = size;
this._last_dequeue = data; this._last_dequeue = data;
this._cache = cache;
this._fetch = fetch;
this._const_id = const_id;
cache.set(const_id,(data && data.length && data[data.length-1].id) || 0 )
} }
isArray(arr) { isArray(arr) {
return Object.prototype.toString.call(arr) === "[object Array]"; return Object.prototype.toString.call(arr) === "[object Array]";
...@@ -101,10 +105,12 @@ module.exports = class Queue { ...@@ -101,10 +105,12 @@ module.exports = class Queue {
peek() { peek() {
this._last_dequeue = this._elements; this._last_dequeue = this._elements;
this._elements = []; this._elements = [];
this.fill()
return this._last_dequeue; return this._last_dequeue;
} }
async fill(fn) { async fill() {
const result = await fn(); let _last_id = await this._cache.get(this._const_id); //获取缓存的最后一个ID
const result = await this._fetch.call(this._cache,{limit: this._size, last_id:_last_id}); //数据库获取数据
const _result_size = result.length; const _result_size = result.length;
if (!_result_size) { if (!_result_size) {
this.enqueue(this._last_dequeue); this.enqueue(this._last_dequeue);
...@@ -115,7 +121,9 @@ module.exports = class Queue { ...@@ -115,7 +121,9 @@ module.exports = class Queue {
} else { } else {
this.enqueue(result); this.enqueue(result);
} }
return _result_size? result.reduce((pre, next) => Math.max(pre, next.id), 0): 0; _last_id = _result_size? result.reduce((pre, next) => Math.max(pre, next.id), 0): _last_id;
this._cache.set(this._const_id,_last_id) // redis 缓存最后一个ID
return _last_id
} }
first() { first() {
if (this.isEmpty()) throw new Error("Queue is empty"); if (this.isEmpty()) throw new Error("Queue is empty");
......
...@@ -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: 2020-01-03 19:40:16 * @Last Modified time: 2020-01-04 12:24:23
*/ */
"use strict"; "use strict";
...@@ -23,6 +23,7 @@ class MerchantController extends Controller { ...@@ -23,6 +23,7 @@ class MerchantController extends Controller {
this.CacheService = ctx.service.cache; //redis 缓存服务 this.CacheService = ctx.service.cache; //redis 缓存服务
this.ServerResponseCode = ctx.response.ServerResponseCode; this.ServerResponseCode = ctx.response.ServerResponseCode;
this.ServerResponse = ctx.response.ServerResponse; this.ServerResponse = ctx.response.ServerResponse;
this.queue = ctx.app.merchant_queue;
} }
...@@ -184,14 +185,15 @@ class MerchantController extends Controller { ...@@ -184,14 +185,15 @@ class MerchantController extends Controller {
* @Request query string endDate 查询结束时间 (2019-12-12) * @Request query string endDate 查询结束时间 (2019-12-12)
*/ */
async device_order_stat() { async device_order_stat() {
const { type_4s , type_weixiu , type_yingai , type_jingpin ,type_meibao ,maintain_order ,repair_order ,insurance_order ,device_order } const { type_4s , type_weixiu , type_yingai , type_jingpin ,type_meibao,type_jingxiao ,maintain_order ,repair_order ,insurance_order ,device_order }
= =
await this._fetch_total_({field:[ 'type_4s', 'type_weixiu', 'type_yingai', 'type_jingpin','type_meibao', 'maintain_order','repair_order','insurance_order','device_order' ],isGetLast:true}) await this._fetch_total_({field:[ 'type_4s', 'type_weixiu', 'type_yingai', 'type_jingpin','type_meibao','type_jingxiao', 'maintain_order','repair_order','insurance_order','device_order' ],isGetLast:true})
//订单数量区域排名 //订单数量区域排名
const last = await this._fetch_summary_({isGetLast:true}); const last = await this._fetch_summary_({isGetLast:true});
const order_sort = [] const order_sort = []
const province = last[0].p const province = last[0].p
for (const key in province) { for (const key in province) {
if(key ==='0') continue
order_sort.push({prov_code:key,value:province[key].total_order}) order_sort.push({prov_code:key,value:province[key].total_order})
} }
order_sort.sort((a,b)=>b.value-a.value).length = 10 order_sort.sort((a,b)=>b.value-a.value).length = 10
...@@ -200,7 +202,7 @@ class MerchantController extends Controller { ...@@ -200,7 +202,7 @@ class MerchantController extends Controller {
// const device_type = await this.MerchantService.device_type() // const device_type = await this.MerchantService.device_type()
const { channel,device_type } = await this._get_stats(['channel','device_type']) const { channel,device_type } = await this._get_stats(['channel','device_type'])
const data = { const data = {
merchant_type : { type_4s, type_weixiu, type_yingai, type_jingpin,type_meibao }, // 商户类型 merchant_type : { type_4s, type_weixiu, type_yingai, type_jingpin,type_meibao,type_jingxiao }, // 商户类型
order_type: { maintain_order,repair_order,insurance_order,device_order }, // 商户订单类型分布 order_type: { maintain_order,repair_order,insurance_order,device_order }, // 商户订单类型分布
order_sort, //订单数量区域排名 order_sort, //订单数量区域排名
channel, // 商户渠道分布 channel, // 商户渠道分布
...@@ -209,6 +211,20 @@ class MerchantController extends Controller { ...@@ -209,6 +211,20 @@ class MerchantController extends Controller {
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/**
* @Router GET /screen/merchant/activation
* @Description 实时激活数据播报
* @Request query integer pid 省份id
*/
async activation({ query: { pid } }) {
const data = this.queue.peek();
// const { MERCHANT_ACTIVE_DATA_LASI_ID } = this.helper.constant;
// const _last_id = await this.CacheService.get(MERCHANT_ACTIVE_DATA_LASI_ID);
// this.queue.fill(async ()=>await this.MerchantService.activation({ pid, limit: this.queue.size(), last_id:_last_id }))
// .then(last_id=>last_id && this.CacheService.set(MERCHANT_ACTIVE_DATA_LASI_ID,last_id))
this.ctx.body = this.ServerResponse.Success(data);
}
} }
module.exports = MerchantController; module.exports = MerchantController;
...@@ -292,10 +292,10 @@ class UserController extends Controller { ...@@ -292,10 +292,10 @@ class UserController extends Controller {
*/ */
async activation({ query: { pid } }) { async activation({ query: { pid } }) {
const data = this.queue.peek(); const data = this.queue.peek();
const { USER_ACTIVE_DATA_LASI_ID } = this.helper.constant; // const { USER_ACTIVE_DATA_LASI_ID } = this.helper.constant;
const _last_id = await this.CacheService.get(USER_ACTIVE_DATA_LASI_ID); // const _last_id = await this.CacheService.get(USER_ACTIVE_DATA_LASI_ID);
this.queue.fill(async ()=>await this.UserService.activation({ pid, limit: this.queue.size(), last_id:_last_id })) // this.queue.fill(async ()=>await this.UserService.activation({ pid, limit: this.queue.size(), last_id:_last_id }))
.then(last_id=>last_id && this.CacheService.set(USER_ACTIVE_DATA_LASI_ID,last_id)) // .then(last_id=>last_id && this.CacheService.set(USER_ACTIVE_DATA_LASI_ID,last_id))
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-25 10:33:43 * @Last Modified time: 2020-01-04 12:52:09
*/ */
const moment = require("moment"); const moment = require("moment");
...@@ -62,57 +62,57 @@ exports.percent = (num, total, fixed = 2) => ...@@ -62,57 +62,57 @@ exports.percent = (num, total, fixed = 2) =>
/** /**
* 简单封装 sequelize 查询参数 * 简单封装 sequelize 查询参数
*/ */
exports.seq_option = function({ // exports.seq_option = function({
pid, // pid,
cid, // cid,
n, // n,
limit, // limit,
order, // order,
day, // day,
beginDate, // beginDate,
endDate // endDate
}) { // }) {
let where = {}; // let where = {};
const { between } = this.ctx.app.Sequelize.Op; // const { between } = this.ctx.app.Sequelize.Op;
if (cid) { // if (cid) {
where.city_code = cid; // where.city_code = cid;
} else if (pid) { // } else if (pid) {
where.prov_code = pid; // where.prov_code = pid;
} // }
if (day) { // if (day) {
//如果有具体天数 就直接查询具体一天的数据(优先具体哪一天) // //如果有具体天数 就直接查询具体一天的数据(优先具体哪一天)
where.day = day; // where.day = day;
} else if (n) { // } else if (n) {
// 查询近N天的数据 不包括今天 // // 查询近N天的数据 不包括今天
where.day = { // where.day = {
[between]: [this.date(n), this.format_end_date(this.date(-1))] // [between]: [this.date(n), this.format_end_date(this.date(-1))]
}; // };
} else if (n === 0) { // } else if (n === 0) {
// 查询 // // 查询
where.day = { // where.day = {
[between]: [this.date(0), this.format_end_date(this.date(0))] // [between]: [this.date(0), this.format_end_date(this.date(0))]
}; // };
} else if (beginDate) { // } else if (beginDate) {
if (!endDate) { // if (!endDate) {
endDate = beginDate; // endDate = beginDate;
} // }
if (!endDate.includes(":")) { // if (!endDate.includes(":")) {
endDate = this.format_end_date(endDate); // endDate = this.format_end_date(endDate);
} // }
where.day = { // where.day = {
[between]: [beginDate, endDate] // [between]: [beginDate, endDate]
}; // };
} // }
const option = { // const option = {
where, // where,
raw: true // raw: true
}; // };
if (limit) { // if (limit) {
option.limit = +limit; // option.limit = +limit;
} // }
if (order) { // if (order) {
option.order = order; // option.order = order;
} // }
return option; // return option;
}; // };
exports.constant = constant; exports.constant = constant;
...@@ -113,6 +113,11 @@ module.exports = app => { ...@@ -113,6 +113,11 @@ module.exports = app => {
allowNull: true, allowNull: true,
defaultValue: '0' defaultValue: '0'
}, },
type_jingxiao: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: { create_time: {
type: DataTypes.DATE, type: DataTypes.DATE,
allowNull: true allowNull: true
......
...@@ -27,6 +27,11 @@ module.exports = app => { ...@@ -27,6 +27,11 @@ module.exports = app => {
allowNull: true, allowNull: true,
defaultValue: '0' defaultValue: '0'
}, },
recent_renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
renew: { renew: {
type: DataTypes.INTEGER(10), type: DataTypes.INTEGER(10),
allowNull: true, allowNull: true,
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_carbrand', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false
},
brand_name: {
type: DataTypes.STRING(32),
allowNull: false
},
brand_cars: {
type: DataTypes.INTEGER(10),
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_carbrand'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_daily', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
day: {
type: DataTypes.DATE,
allowNull: false
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false
},
total_user: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
recent_renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
increase: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
journey: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
miles: {
type: "DOUBLE(12,2)",
allowNull: true,
defaultValue: '0.00'
},
online_time: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
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'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_drive_info', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
total: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_0_5: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_5_10: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_10_15: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_15_20: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_20_25: {
type: DataTypes.INTEGER(10),
allowNull: true
},
d_25_31: {
type: DataTypes.INTEGER(10),
allowNull: true
},
km_0_40: {
type: DataTypes.INTEGER(10),
allowNull: true
},
km_40_70: {
type: DataTypes.INTEGER(10),
allowNull: true
},
km_70_100: {
type: DataTypes.INTEGER(10),
allowNull: true
},
km_100_: {
type: DataTypes.INTEGER(10),
allowNull: true
},
w_0_10: {
type: DataTypes.INTEGER(10),
allowNull: true
},
w_10_20: {
type: DataTypes.INTEGER(10),
allowNull: true
},
w_20_30: {
type: DataTypes.INTEGER(10),
allowNull: true
},
w_30_50: {
type: DataTypes.INTEGER(10),
allowNull: true
},
w_50_: {
type: DataTypes.INTEGER(10),
allowNull: true
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_drive_info'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_gender', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false
},
gender_range: {
type: DataTypes.STRING(32),
allowNull: false
},
total: {
type: DataTypes.INTEGER(10),
allowNull: false,
defaultValue: '0'
},
male: {
type: DataTypes.INTEGER(11),
allowNull: false,
defaultValue: '0'
},
female: {
type: DataTypes.INTEGER(11),
allowNull: false,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_gender'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_city_realtime', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
online_total: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
online_time: {
type: DataTypes.BIGINT,
allowNull: true,
defaultValue: '0'
},
increase: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
active: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
renew: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_city_realtime'
});
Model.associate = function() {
}
return Model;
};
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_user_new_active_detail', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sn: {
type: DataTypes.STRING(32),
allowNull: false
},
active_time: {
type: DataTypes.DATE,
allowNull: false
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false
},
city_code: {
type: DataTypes.STRING(32),
allowNull: false
},
device_type: {
type: DataTypes.STRING(32),
allowNull: false
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_user_new_active_detail'
});
Model.associate = function() {
}
return Model;
};
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:18:45 * @Date: 2019-11-21 11:18:45
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2020-01-03 19:33:23 * @Last Modified time: 2020-01-04 11:05:44
*/ */
module.exports = app => { module.exports = app => {
app.router.get('/screen/merchant/total', app.controller.screen.merchant.total); app.router.get('/screen/merchant/total', app.controller.screen.merchant.total);
app.router.get('/screen/merchant/statistics', app.controller.screen.merchant.statistics); app.router.get('/screen/merchant/statistics', app.controller.screen.merchant.statistics);
app.router.get('/screen/merchant/trend', app.controller.screen.merchant.trend); app.router.get('/screen/merchant/trend', app.controller.screen.merchant.trend);
// app.router.get('/screen/merchant/trend_device', app.controller.screen.merchant.trend_device); app.router.get('/screen/merchant/activation', app.controller.screen.merchant.activation);
app.router.get('/screen/merchant/device_order_stat', app.controller.screen.merchant.device_order_stat); app.router.get('/screen/merchant/device_order_stat', app.controller.screen.merchant.device_order_stat);
}; };
\ No newline at end of file \ No newline at end of file
...@@ -38,7 +38,7 @@ class UpdateCacheMerchant extends Subscription { ...@@ -38,7 +38,7 @@ class UpdateCacheMerchant extends Subscription {
if (obj) { if (obj) {
const { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order, const { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order,
recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order, recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao } = obj; type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao } = obj;
target["total_merchant"] += +total_merchant; //商户总数 target["total_merchant"] += +total_merchant; //商户总数
target["total_device"] += +total_device; //订购设备总数 target["total_device"] += +total_device; //订购设备总数
target["total_amount"] += parseFloat(total_amount); // 订购设备总额 target["total_amount"] += parseFloat(total_amount); // 订购设备总额
...@@ -58,6 +58,7 @@ class UpdateCacheMerchant extends Subscription { ...@@ -58,6 +58,7 @@ class UpdateCacheMerchant extends Subscription {
target["type_yingai"] += +type_yingai; // 商户类型:音改店 target["type_yingai"] += +type_yingai; // 商户类型:音改店
target["type_jingpin"] += +type_jingpin; //商户类型:精品店 target["type_jingpin"] += +type_jingpin; //商户类型:精品店
target["type_meibao"] += +type_meibao; // 商户类型:美保店 target["type_meibao"] += +type_meibao; // 商户类型:美保店
target["type_jingxiao"] += +type_jingxiao; // 商户类型:经销商
} else { } else {
target["total_merchant"] = 0; //商户总数 target["total_merchant"] = 0; //商户总数
target["total_device"] = 0; //订购设备总数 target["total_device"] = 0; //订购设备总数
...@@ -78,6 +79,7 @@ class UpdateCacheMerchant extends Subscription { ...@@ -78,6 +79,7 @@ class UpdateCacheMerchant extends Subscription {
target["type_yingai"] = 0; // 商户类型:音改店 target["type_yingai"] = 0; // 商户类型:音改店
target["type_jingpin"] = 0; //商户类型:精品店 target["type_jingpin"] = 0; //商户类型:精品店
target["type_meibao"] = 0; // 商户类型:美保店 target["type_meibao"] = 0; // 商户类型:美保店
target["type_jingxiao"] = 0; // 商户类型:经销商
} }
return target; return target;
} }
...@@ -86,15 +88,15 @@ class UpdateCacheMerchant extends Subscription { ...@@ -86,15 +88,15 @@ class UpdateCacheMerchant extends Subscription {
const prov_code = f(merchant); const prov_code = f(merchant);
let { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order, let { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order,
recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order, recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,day} = merchant; type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,day} = merchant;
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], { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order, data[day] = __init_or_plus__(data[day], { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order,
recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order, recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao }); // 累加全国总数值 type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao }); // 累加全国总数值
data[day]["p"][prov_code] = { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order, data[day]["p"][prov_code] = { total_merchant, total_device, total_amount, active_merchant, use_sys_merchant, total_order, today_order,
recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order, recent_7day_order, recent_7day_active, recent_7day_use,maintain_order,repair_order,insurance_order,device_order,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao }; type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao };
}.bind(this) }.bind(this)
); );
return { data, date }; return { data, date };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: limin * @Author: limin
* @Date: 2019-11-21 11:18:37 * @Date: 2019-11-21 11:18:37
* @Last Modified by: limin * @Last Modified by: limin
* @Last Modified time: 2020-01-03 19:36:44 * @Last Modified time: 2020-01-04 12:53:22
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
...@@ -19,37 +19,36 @@ class MerchantService extends Service { ...@@ -19,37 +19,36 @@ class MerchantService extends Service {
*/ */
_reg_models_alias() { _reg_models_alias() {
const { const {
TDeviceOnline, TDeviceOnline,
TMerchantChannelStat, TMerchantChannelStat,
TMerchantDailyStat, TMerchantDailyStat,
TMerchantDeviceOrderStat, TMerchantDeviceOrderStat,
TMerchantOrderDetail, TMerchantOrderDetail,
TMerchantOrderDeviceStat, TMerchantOrderDeviceStat,
TMerchantOrderStat, TMerchantOrderStat,
TMerchantRealtime, TMerchantRealtime,
TProvince, TProvince,
TCity TCity
} = this.app.model.Screen.Merchant; } = this.app.model.Screen.Merchant;
this.MDO = TDeviceOnline; this.MDO = TDeviceOnline;
this.MCS = TMerchantChannelStat; this.MCS = TMerchantChannelStat;
this.MCDS = TMerchantDailyStat; this.MCDS = TMerchantDailyStat;
this.MDOS = TMerchantDeviceOrderStat; this.MDOS = TMerchantDeviceOrderStat;
this.MOD = TMerchantOrderDetail; this.MOD = TMerchantOrderDetail;
this.MODS = TMerchantOrderDeviceStat; this.MODS = TMerchantOrderDeviceStat;
this.MOS = TMerchantOrderStat; this.MOS = TMerchantOrderStat;
this.MRT = TMerchantRealtime; this.MRT = TMerchantRealtime;
this.MProvice = TProvince; this.MProvice = TProvince;
this.MCity = TCity; this.MCity = TCity;
} }
/** /**
* 绑定表关系 * 绑定表关系
*/ */
_associate() { _associate() {}
}
__build__option__( opt={} ){ __build__option__(opt = {}) {
let {day,beginDate,endDate,limit,order} = opt let { day, beginDate, endDate, limit, order } = opt;
const { between } = this.app.Sequelize.Op; const { between } = this.app.Sequelize.Op;
let where = {}; let where = {};
if (day) { if (day) {
...@@ -77,7 +76,7 @@ class MerchantService extends Service { ...@@ -77,7 +76,7 @@ class MerchantService extends Service {
option.order = order; option.order = order;
} }
return option; return option;
}; }
/** /**
* @param field {String} * @param field {String}
...@@ -85,8 +84,8 @@ class MerchantService extends Service { ...@@ -85,8 +84,8 @@ class MerchantService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 获取商户统计数 (天) * @Description 获取商户统计数 (天)
*/ */
async merchant_summary_by_day({beginDate, endDate}) { async merchant_summary_by_day({ beginDate, endDate }) {
var option = this.__build__option__({beginDate, endDate}); var option = this.__build__option__({ beginDate, endDate });
const data = await this.MCDS.findAll(option); const data = await this.MCDS.findAll(option);
return data; return data;
} }
...@@ -109,25 +108,25 @@ class MerchantService extends Service { ...@@ -109,25 +108,25 @@ class MerchantService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 订购设备趋势 * @Description 订购设备趋势
*/ */
async device_order({beginDate,endDate}) { async device_order({ beginDate, endDate }) {
const { col, fn } = this.app.Sequelize; const { col, fn } = this.app.Sequelize;
var option = this.__build__option__(); var option = this.__build__option__();
Object.assign(option, { Object.assign(option, {
attributes: [ attributes: [
'prov_code', "prov_code",
"month", "month",
[fn("SUM", col("order_total")), "order_total"], [fn("SUM", col("order_total")), "order_total"],
[fn("SUM", col("sale_total")), "sale_total"], [fn("SUM", col("sale_total")), "sale_total"],
[fn("SUM", col("stock_total")), "stock_total"], [fn("SUM", col("stock_total")), "stock_total"]
], ],
group:'month', group: "month",
where:{ where: {
month:{ month: {
[this.app.Sequelize.Op.gt]:beginDate, [this.app.Sequelize.Op.gt]: beginDate,
[this.app.Sequelize.Op.lt]:endDate, [this.app.Sequelize.Op.lt]: endDate
} }
} }
}) });
const data = await this.MDOS.findAll(option); const data = await this.MDOS.findAll(option);
return data; return data;
} }
...@@ -138,18 +137,15 @@ class MerchantService extends Service { ...@@ -138,18 +137,15 @@ class MerchantService extends Service {
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 商户渠道分布 * @Description 商户渠道分布
*/ */
async channel_stat({limit}) { async channel_stat({ limit }) {
const { col, fn } = this.app.Sequelize; const { col, fn } = this.app.Sequelize;
var option = this.__build__option__(); var option = this.__build__option__();
Object.assign(option, { Object.assign(option, {
attributes: [ attributes: ["channel", [fn("SUM", col("merchant_total")), "total"]],
'channel', group: "channel"
[fn("SUM", col("merchant_total")), "total"],
],
group:'channel'
}); });
const data = await this.MCS.findAll(option); const data = await this.MCS.findAll(option);
data.sort((a,b)=>b.total-a.total).length = limit data.sort((a, b) => b.total - a.total).length = limit;
return data; return data;
} }
...@@ -163,15 +159,66 @@ class MerchantService extends Service { ...@@ -163,15 +159,66 @@ class MerchantService extends Service {
const { col, fn } = this.app.Sequelize; const { col, fn } = this.app.Sequelize;
var option = this.__build__option__(); var option = this.__build__option__();
Object.assign(option, { Object.assign(option, {
attributes: [ attributes: ["device_type", [fn("SUM", col("device_total")), "total"]],
'device_type', group: "device_type"
[fn("SUM", col("device_total")), "total"],
],
group:'device_type'
}); });
const data = await this.MODS.findAll(option); const data = await this.MODS.findAll(option);
return data; return data;
} }
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 根据id 获取 激活数据
*/
async merchant_active({ limit }) {
var option = this.__build__option__({ limit, order: [["id", "DESC"]] });
Object.assign(option, {
attributes: [
"id",
"merchant",
"order_time",
"order_no",
"total",
"prov_code",
"city_code",
"device_type"
]
});
const data = await this.MOD.findAll(option);
return data;
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 获取用户激活详情
*/
async activation({ pid, limit, last_id }) {
const { app, service } = this;
var option = service.screen.merchant.__build__option__({ pid, limit });
Object.assign(option.where, {
id: {
[app.Sequelize.Op.gt]: last_id
}
});
Object.assign(option, {
attributes: [
"id",
"merchant",
"order_time",
"order_no",
"total",
"prov_code",
"city_code",
"device_type"
]
});
const data = await service.screen.merchant.MOD.findAll(option);
return data;
}
} }
module.exports = MerchantService; module.exports = MerchantService;
...@@ -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-12-19 15:49:03 * @Last Modified time: 2020-01-04 10:25:52
*/ */
/* eslint valid-jsdoc: "off" */ /* eslint valid-jsdoc: "off" */
...@@ -23,6 +23,14 @@ module.exports = appInfo => { ...@@ -23,6 +23,14 @@ module.exports = appInfo => {
level: "INFO", level: "INFO",
dir: path.join(__dirname, "../logs/pro") // 保存路径为工程路径下`logs/pro` dir: path.join(__dirname, "../logs/pro") // 保存路径为工程路径下`logs/pro`
}; };
config.sequelize = {
dialect: "mysql",
host: "14.17.100.222",
port: "3307",
database: "glsx_data_screen",
username: "dev_limin",
password: "fdseooui"
};
// add your user config here // add your user config here
// myAppName: 'egg', // myAppName: 'egg',
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!