Commit c698fed5 by liimin

商户接口数据缓存

1 parent aa901e5e
...@@ -9,7 +9,7 @@ module.exports = { ...@@ -9,7 +9,7 @@ module.exports = {
PREFIX: '_glsx_data_screen_', PREFIX: '_glsx_data_screen_',
USER_SUMMARY_30_DAY:'user_summary_30_day', USER_SUMMARY_30_DAY:'user_summary_30_day',
MERCHANT_SUMMARY_30_DAY:'merchant_summary_30_day', MERCHANT_SUMMARY_30_DAY:'merchant_summary_30_day',
MERCHANT_SUMMARY_LAST:'merchant_summary_last', 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'
}; };
\ 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-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-25 21:32:08 * @Last Modified time: 2019-12-26 18:25:56
*/ */
"use strict"; "use strict";
...@@ -39,15 +39,13 @@ class MerchantController extends Controller { ...@@ -39,15 +39,13 @@ class MerchantController extends Controller {
* 对比和获取内存中的数据(总共30天,每天通过定时任务更新) * 对比和获取内存中的数据(总共30天,每天通过定时任务更新)
* 如果获取的时候数据还是最新则手动触发定时任务更新一次 * 如果获取的时候数据还是最新则手动触发定时任务更新一次
*/ */
async _compare_get_(isRunTask){ async _compare_get_(isRunTask,type = this.helper.constant.MERCHANT_SUMMARY_30_DAY){
var { yesterday, cache_data_last_date_merchant } = await this._fetch_date_in_cache_(); var { yesterday, cache_data_last_date_merchant } = await this._fetch_date_in_cache_();
if(!this.helper.moment(cache_data_last_date_merchant).isSame(yesterday) && isRunTask){ //如果 内存中的数据的日期不是昨天的 则手动启动定时器 更新缓存数据 if(!this.helper.moment(cache_data_last_date_merchant).isSame(yesterday) && isRunTask){ //如果 内存中的数据的日期不是昨天的 则手动启动定时器 更新缓存数据
await this.app.runSchedule('update_cache_merchant'); await this.app.runSchedule('update_cache_merchant');
} }
const { MERCHANT_SUMMARY_30_DAY, MERCHANT_SUMMARY_LAST } = this.helper.constant; const summary = await this.CacheService.get(type) || [];
const summary_30_day = await this.CacheService.get(MERCHANT_SUMMARY_30_DAY) || []; return summary
const summary_last = await this.CacheService.get(MERCHANT_SUMMARY_LAST)||[];
return {summary_30_day,summary_last}
} }
/** /**
...@@ -55,36 +53,61 @@ class MerchantController extends Controller { ...@@ -55,36 +53,61 @@ class MerchantController extends Controller {
* 比较数据时间 如果不是昨天的数据 则启动定时任务 更新一遍数据 再次获取数据并返回 * 比较数据时间 如果不是昨天的数据 则启动定时任务 更新一遍数据 再次获取数据并返回
*/ */
async _fetch_summary_( { beginDate,endDate,isGetLast }, fn ){ async _fetch_summary_( { beginDate,endDate,isGetLast }, fn ){
var {summary_30_day,summary_last}= await this._compare_get_(isGetLast); var summary_30_day= await this._compare_get_(isGetLast);
console.log(summary_30_day,summary_last);
const { moment } =this.helper const { moment } =this.helper
var result=[]; var result=[];
if(isGetLast){ if(isGetLast){
// const { cache_data_last_date_merchant } = await this._fetch_date_in_cache_(); const { cache_data_last_date_merchant } = await this._fetch_date_in_cache_();
result = summary_last; result = summary_30_day[cache_data_last_date_merchant];
// fn && fn(cache_data_last_date_merchant,summary_last) fn && fn(cache_data_last_date_merchant,summary_30_day[cache_data_last_date_merchant])
}else if(beginDate){ }else if(beginDate){
endDate = endDate || beginDate; endDate = endDate || beginDate;
if(moment(beginDate).isSame(endDate) ){ if(moment(beginDate).isSame(endDate) ){
result.push(summary_30_day.find(obj=>moment(beginDate).isSame(obj.day))) result.push(summary_30_day[beginDate])
// fn && fn(beginDate,result) fn && fn(beginDate,summary_30_day[beginDate])
}else{ }else{
result = summary_30_day.filter( for(const day in summary_30_day){
obj=>moment(obj.day).isBetween(beginDate,endDate) if(moment(day).isBetween(beginDate,endDate)
||moment(obj.day).isSame(beginDate) || moment(day).isSame(beginDate)
||moment(obj.day).isSame(endDate)) || moment(day).isSame(endDate)){
// fn && fn(day,result) result.push(summary_30_day[day])
fn && fn(day,summary_30_day[day])
}
}
} }
}else{ }else{
result = summary_30_day if(fn){
for(const day in summary_30_day){
fn(day,summary_30_day[day])
}
}
result = Object.values(summary_30_day)
} }
return result return result ||[]
} }
async _fetch_total_({ field,isGetLast } ){ async _fetch_total_({ field,isGetLast } ){
const _summary = await this._fetch_summary_({isGetLast}); const _summary = await this._fetch_summary_({isGetLast});
return this._set_(field,(f)=>(_summary.reduce((pre,next)=>pre + +next[f],0))); return this._set_(field,(f)=>_summary[f] || 0);
}
/**
* 内部方法 从内存获取 范围时间内的数据
*/
async _fetch_detail_by_range_({ pid,field, beginDate,endDate } ){
var res = []
var _set = this._set_
var data = null
await this._fetch_summary_({ beginDate, endDate },async (day,value)=>{
var fn = null;
if (pid) {
fn = async f=>value && value['p'][pid] ? value['p'][pid][f]:0
}else{
fn = async f=>value ? value[f]:0
}
data = await _set(field,fn);
res.push({ day, data })
});
return res;
} }
/** /**
...@@ -106,6 +129,16 @@ class MerchantController extends Controller { ...@@ -106,6 +129,16 @@ class MerchantController extends Controller {
} }
/** /**
* 内部帮助方法
* @param {*} field
* @param {*} fn
*/
async _get_stats(){
const result = await this._compare_get_(true,this.helper.constant.MERCHANT_SUMMARY_STATS);
return result
}
/**
* @Router GET /screen/merchant/total * @Router GET /screen/merchant/total
* @Description 数据大屏-商户总数统计.---- 广联商户总数 商户累计订单数 当日订单数 * @Description 数据大屏-商户总数统计.---- 广联商户总数 商户累计订单数 当日订单数
*/ */
...@@ -127,71 +160,38 @@ class MerchantController extends Controller { ...@@ -127,71 +160,38 @@ class MerchantController extends Controller {
*/ */
async statistics() { async statistics() {
const summary = await this._fetch_total_({ field:['recent_7day_active','recent_7day_use','recent_7day_order','total_device','total_amount','active_merchant','use_sys_merchant']}) const summary = await this._fetch_total_({ field:['recent_7day_active','recent_7day_use','recent_7day_order','total_device','total_amount','active_merchant','use_sys_merchant']})
console.log(summary);
const data = { summary } const data = { summary }
this.ctx.body = this.ServerResponse.Success(data);
}
/**
* @Router GET /screen/user/gender
* @Description 数据大屏-用户性别、年龄段、以及数量的占比 2: 00后,3: 90后,4: 80后,5: 70后,6: 60后,7:其他
* @Request query integer pid 省份id
* @Request query integer cid 城市id
*/
async gender({ query: { pid,cid } }) {
const data = await this.UserService.user_gender({ pid,cid })
this.ctx.body = this.ServerResponse.Success(data);
}
/**
* @Router GET /screen/user/city_range
* @Description 数据大屏-城市排行
* @Request query integer pid 省份id
* @Request query integer n 前 n名 默认 5
*/
async city_range({ query: { pid, n = 5 } }) {
const data = await this.UserService.city_range( { pid, limit:n })
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/**
* @Router GET /screen/user/city_range
* @Description 数据大屏-车辆品牌分布
* @Request query integer pid 省份id
* @Request query integer cid 城市id
* @Request query integer n 前 n名 默认 6
*/
async car_brand_range({ query: { pid, cid, n = 6 } }) {
const data = await this.UserService.car_brand_range( { pid, cid, limit:n })
this.ctx.body = this.ServerResponse.Success(data);
}
/** /**
* @Router GET /screen/user/drive_range * @Router GET /screen/merchant/trend
* @Description 数据大屏-出行分布 * @Description 数据大屏-1 商户订单趋势 2.设备订购趋势, 3.商户活跃趋势 4.系统使用率趋势
* @Request query integer pid 省份id * @Request query integer n 近N天数据 默认 30天
* @Request query integer cid 城市id * @Request query string beginDate 查询开始时间 (2019-12-12)
* @Request query string endDate 查询结束时间 (2019-12-12)
*/ */
async drive_range({ query: { pid, cid } }) { async trend({ query: {pid, type, n = 30, beginDate , endDate } }) {
const data = await this.UserService.drive_range( { pid, cid }) if(n){
if(n===30){
beginDate = endDate = null;
}else{
beginDate = this.helper.date(-n);
var { yesterday:endDate } = await this._fetch_date_in_cache_();
}
}
type = type ? ( type.includes(',') ? type.split(',') : type ) : [ 'maintain_order', 'repair_order', 'insurance_order', 'device_order', 'recent_7day_active','recent_7day_use','active_merchant','use_sys_merchant','total_merchant' ];
const data = await this._fetch_detail_by_range_( { pid, field:type,beginDate, endDate } )
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
* @Router GET /screen/user/trend * @Router GET /screen/merchant/trend_device
* @Description 数据大屏-1 用户新增趋势 2.用户活跃趋势, 3.用户付费趋势 4.用户车辆出行趋势 * @Description 数据大屏-订购设备趋势
* @Request query integer pid 省份id
* @Request query integer cid 城市id
* @Request query string type 趋势类别 u:用户总数 i: 用户新增趋势 a: 用户活跃趋势, r:用户付费趋势 j:用户车辆出行趋势(多个',' 隔开 默认:['u','i','a','r','j'])
* @Request query integer n 近N天数据 默认 30天 * @Request query integer n 近N天数据 默认 30天
* @Request query string beginDate 查询开始时间 (2019-12-12) * @Request query string beginDate 查询开始时间 (2019-12-12)
* @Request query string endDate 查询结束时间 (2019-12-12) * @Request query string endDate 查询结束时间 (2019-12-12)
*/ */
async trend({ query: { pid, cid, type, n = 30, beginDate , endDate } }) { async trend_device({ query: {pid, type, n = 30, beginDate , endDate } }) {
if(n){ if(n){
if(n===30){ if(n===30){
beginDate = endDate = null; beginDate = endDate = null;
...@@ -200,8 +200,28 @@ class MerchantController extends Controller { ...@@ -200,8 +200,28 @@ class MerchantController extends Controller {
var { yesterday:endDate } = await this._fetch_date_in_cache_(); var { yesterday:endDate } = await this._fetch_date_in_cache_();
} }
} }
type = type ? ( type.includes(',') ? type.split(',') : type ) : [ 'u', 'i', 'a', 'r', 'j' ]; type = type ? ( type.includes(',') ? type.split(',') : type ) : [ 'maintain_order', 'repair_order', 'insurance_order', 'device_order', 'recent_7day_active','recent_7day_use','active_merchant','use_sys_merchant','total_merchant' ];
const data = await this._fetch_detail_by_range_( { pid, cid, field:type,beginDate, endDate } ) const data = await this._fetch_detail_by_range_( { pid, field:type,beginDate, endDate } )
this.ctx.body = this.ServerResponse.Success(data);
}
/**
* @Router GET /screen/merchant/trend_device
* @Description 数据大屏-设备订单统计 1.商户订单类型分布 2.订购设备类型分布
* @Request query integer n 近N天数据 默认 30天
* @Request query string beginDate 查询开始时间 (2019-12-12)
* @Request query string endDate 查询结束时间 (2019-12-12)
*/
async device_order_stat() {
const q = this._fetch_total_({field:[ 'type_4s', 'type_weixiu', 'type_yingai', 'type_jingpin','type_meibao', 'maintain_order','repair_order','insurance_order','device_order','p' ],isGetLast:true})
const { type_4s, type_weixiu, type_yingai, type_jingpin,type_meibao,maintain_order,repair_order,insurance_order,device_order } =q
const data = {}
data.merchant_type = { type_4s, type_weixiu, type_yingai, type_jingpin,type_meibao } // 商户类型
data.order_type={ maintain_order,repair_order,insurance_order,device_order } // 订单类型
//订单数量区域排名
// Object.values(p).sort(obj=>obj.)
this.ctx.body = this.ServerResponse.Success(data); this.ctx.body = this.ServerResponse.Success(data);
} }
/** /**
......
/* indent size: 2 */
module.exports = app => {
const DataTypes = app.Sequelize;
const Model = app.model.define('t_merchant_summary_stat', {
id: {
type: DataTypes.INTEGER(10),
allowNull: false,
primaryKey: true,
autoIncrement: true
},
prov_code: {
type: DataTypes.STRING(32),
allowNull: false,
unique: true
},
type_4s: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
type_weixiu: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
type_yingai: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
type_jingpin: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
type_meibao: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
merchant_total: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
order_total: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
maintain_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
repair_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
insurance_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
device_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
},
update_time: {
type: DataTypes.DATE,
allowNull: true
}
}, {
tableName: 't_merchant_summary_stat'
});
Model.associate = function() {
}
return Model;
};
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
* @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: 2019-12-25 21:16:31 * @Last Modified time: 2019-12-26 15:55:15
*/ */
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);
}; };
\ No newline at end of file \ No newline at end of file
...@@ -29,11 +29,82 @@ class UpdateCacheMerchant extends Subscription { ...@@ -29,11 +29,82 @@ class UpdateCacheMerchant extends Subscription {
}; };
} }
_group(merchants, f) {
const data = {
};
var date= this.app.config.sys.init_date;
function __init_or_plus__(target, obj) {
target = target || {};
if (obj) {
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,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao } = obj;
target["total_merchant"] += +total_merchant; //商户总数
target["total_device"] += +total_device; //订购设备总数
target["total_amount"] += parseFloat(total_amount); // 订购设备总额
target["active_merchant"] += +active_merchant; // 活跃商户
target["use_sys_merchant"] += +use_sys_merchant; // 使用的商户
target["total_order"] += +total_order; // 累计订单数
target["today_order"] += +today_order; // 当日订单数
target["recent_7day_order"] += +recent_7day_order; // 近7日订单数
target["recent_7day_active"] += +recent_7day_active; // 近7日活跃商户数
target["recent_7day_use"] += +recent_7day_use; // 近7日使用商户数
target["maintain_order"] += +maintain_order; // 保养订单数量
target["repair_order"] += +repair_order; // 送修订单数量
target["insurance_order"] += +insurance_order; // 保险订单数量
target["device_order"] += +device_order; // 保险订单数量
target["type_4s"] += +type_4s; // 商户类型:4S店
target["type_weixiu"] += +type_weixiu; //商户类型:维修店
target["type_yingai"] += +type_yingai; // 商户类型:音改店
target["type_jingpin"] += +type_jingpin; //商户类型:精品店
target["type_meibao"] += +type_meibao; // 商户类型:美保店
} else {
target["total_merchant"] = 0; //商户总数
target["total_device"] = 0; //订购设备总数
target["total_amount"] = 0; // 订购设备总额
target["active_merchant"] = 0; // 活跃商户
target["use_sys_merchant"] = 0; // 使用的商户
target["total_order"] = 0; // 累计订单数
target["today_order"] = 0; // 当日订单数
target["recent_7day_order"] = 0; // 近7日订单数
target["recent_7day_active"] = 0; // 近7日活跃商户数
target["recent_7day_use"] = 0; // 近7日使用商户数
target["maintain_order"] = 0; // 保养订单数量
target["repair_order"] = 0; // 送修订单数量
target["insurance_order"] = 0; // 保险订单数量
target["device_order"] = 0; // 保险订单数量
target["type_4s"] = 0; // 商户类型:4S店
target["type_weixiu"] = 0; //商户类型:维修店
target["type_yingai"] = 0; // 商户类型:音改店
target["type_jingpin"] = 0; //商户类型:精品店
target["type_meibao"] = 0; // 商户类型:美保店
}
return target;
}
merchants.forEach(
function(merchant) {
const prov_code = f(merchant);
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,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,day} = merchant;
date = this.helper.moment(day).isAfter(date) ? day : date;
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,
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 }); // 累加全国总数值
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,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao };
}.bind(this)
);
return { data, date };
}
// subscribe 是真正定时任务执行时被运行的函数 // subscribe 是真正定时任务执行时被运行的函数
async subscribe() { async subscribe() {
this.logger.info("===============执行日常任务-缓存每日统计数据(商户总30天) begin=================="); this.logger.info("===============执行日常任务-缓存每日统计数据(商户总30天) begin==================");
const { moment, constant } = this.helper; const { moment, constant } = this.helper;
const { DATES,MERCHANT_SUMMARY_30_DAY } = constant; const { DATES,MERCHANT_SUMMARY_30_DAY,MERCHANT_SUMMARY_STATS } = constant;
const dates = await this.CacheService.get(DATES); const dates = await this.CacheService.get(DATES);
var { cache_update_time_merchant, cache_data_last_date_merchant } = dates var { cache_update_time_merchant, cache_data_last_date_merchant } = dates
const { user_cache_update_time_diff } = this.app.config.sys; const { user_cache_update_time_diff } = this.app.config.sys;
...@@ -44,18 +115,28 @@ class UpdateCacheMerchant extends Subscription { ...@@ -44,18 +115,28 @@ class UpdateCacheMerchant extends Subscription {
const yesterday = this.helper.date(-1); const yesterday = this.helper.date(-1);
const day30before = this.helper.date(-30); const day30before = this.helper.date(-30);
// 查询昨天 所有城市 分别 对应的 用户总数 列表 // 查询昨天 所有城市 分别 对应的 用户总数 列表
const _merchants_summary = await this.MerchantService.merchant_summary_last()
const _merchants_daily = await this.MerchantService.merchant_summary_by_day({beginDate: day30before, endDate: yesterday}) const _merchants_daily = await this.MerchantService.merchant_summary_by_day({beginDate: day30before, endDate: yesterday})
if (_merchants_daily.length) { if (_merchants_daily.length) {
const date = this.helper.moment(_merchants_daily[_merchants_daily.length-1].day) var {data, date } = this._group(_merchants_daily, merchant => merchant.prov_code);
if( moment(date).isAfter( cache_data_last_date_merchant) ){ //当前数据最新时间 大于 上一次缓存数据的最新时间 才写入缓存 if( moment(date).isAfter( cache_data_last_date_merchant) ){ //当前数据最新时间 大于 上一次缓存数据的最新时间 才写入缓存
await this.CacheService.set( await this.CacheService.set(
MERCHANT_SUMMARY_30_DAY, MERCHANT_SUMMARY_30_DAY,
_merchants_daily data
); );
// STAT
const _last_month_ =moment().format('YYYY-MM')
const _last_month_7 =moment().subtract(7, 'months').format('YYYY-MM')
const _order_trend = await this.MerchantService.device_order({beginDate: _last_month_7, endDate: _last_month_}) //订购设备趋势
const _channel_stat = await this.MerchantService.channel_stat({limit: 6}) //商户渠道分布
const _device_type = await this.MerchantService.device_type() //订购设备类型分布
const _stats={
'order_trend':_order_trend, //订购设备趋势
'channel':_channel_stat,//商户渠道分布
'device_type':_device_type //订购设备类型分布
}
await this.CacheService.set( await this.CacheService.set(
MERCHANT_SUMMARY_LAST, MERCHANT_SUMMARY_STATS,
_merchants_summary _stats
); );
this.logger.info("merchant_summary_%s",date); this.logger.info("merchant_summary_%s",date);
}else{ }else{
......
...@@ -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: 2019-12-25 21:25:11 * @Last Modified time: 2019-12-26 18:32:25
*/ */
const Service = require("egg").Service; const Service = require("egg").Service;
...@@ -20,25 +20,23 @@ class MerchantService extends Service { ...@@ -20,25 +20,23 @@ class MerchantService extends Service {
_reg_models_alias() { _reg_models_alias() {
const { const {
TDeviceOnline, TDeviceOnline,
TMerchantChannerStat, TMerchantChannelStat,
TMerchantDailyStat, TMerchantDailyStat,
TMerchantDeviceOrderStat, TMerchantDeviceOrderStat,
TMerchantOrderDetail, TMerchantOrderDetail,
TMerchantOrderDeviceStat, TMerchantOrderDeviceStat,
TMerchantOrderStat, TMerchantOrderStat,
TMerchantSummaryStat,
TMerchantRealtime, TMerchantRealtime,
TProvince, TProvince,
TCity TCity
} = this.app.model.Screen.Merchant; } = this.app.model.Screen.Merchant;
this.MDO = TDeviceOnline; this.MDO = TDeviceOnline;
this.MCS = TMerchantChannerStat; 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.MSS = TMerchantSummaryStat;
this.MRT = TMerchantRealtime; this.MRT = TMerchantRealtime;
this.MProvice = TProvince; this.MProvice = TProvince;
this.MCity = TCity; this.MCity = TCity;
...@@ -81,15 +79,27 @@ class MerchantService extends Service { ...@@ -81,15 +79,27 @@ class MerchantService extends Service {
return option; return option;
}; };
/** /**
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 获取商户统计总数 * @Description 获取商户统计数 (天)
*/ */
async merchant_summary_last() { async merchant_summary_by_day({beginDate, endDate}) {
var option = this.__build__option__({beginDate, endDate});
const data = await this.MCDS.findAll(option);
return data;
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 获取实时数据(详细)
*/
async merchant_realtime() {
var option = this.__build__option__(); var option = this.__build__option__();
const data = await this.MSS.findAll(option); const data = await this.MRT.findAll(option);
return data; return data;
} }
...@@ -97,11 +107,26 @@ class MerchantService extends Service { ...@@ -97,11 +107,26 @@ class MerchantService extends Service {
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 获取商户统计数 (天) * @Description 订购设备趋势
*/ */
async merchant_summary_by_day({beginDate, endDate}) { async device_order({beginDate,endDate}) {
var option = this.__build__option__({beginDate, endDate}); var option = this.__build__option__();
const data = await this.MCDS.findAll(option); Object.assign(option, {
attributes: [
'prov_code',
"month",
'order_total',
'sale_total',
'stock_total'
],
where:{
month:{
[this.app.Sequelize.Op.gt]:beginDate,
[this.app.Sequelize.Op.lt]:endDate,
}
}
})
const data = await this.MDOS.findAll(option);
return data; return data;
} }
...@@ -109,11 +134,30 @@ class MerchantService extends Service { ...@@ -109,11 +134,30 @@ class MerchantService extends Service {
* @param field {String} * @param field {String}
* @param value {String} * @param value {String}
* @return {Promise.<boolean>} * @return {Promise.<boolean>}
* @Description 获取实时数据(详细) * @Description 商户渠道分布
*/ */
async merchant_realtime() { async channel_stat({limit}) {
var option = this.__build__option__({limit,order:[["merchant_total", "DESC"]]});
const data = await this.MCS.findAll(option);
return data;
}
/**
* @param field {String}
* @param value {String}
* @return {Promise.<boolean>}
* @Description 设备类型分布
*/
async device_type() {
var option = this.__build__option__(); var option = this.__build__option__();
const data = await this.MRT.findAll(option); Object.assign(option, {
attributes: [
'prov_code',
"device_type",
'device_total'
]
})
const data = await this.MODS.findAll(option);
return data; return data;
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!