Commit 35e5e5e1 by liimin

调整

1 parent 548090f3
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-12-06 14:58:35
* @Last Modified by: limin
* @Last Modified time: 2020-01-04 12:17:19
* @Last Modified time: 2020-01-08 14:08:08
*/
// const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:20:01
* @Last Modified by: limin
* @Last Modified time: 2020-01-04 19:05:01
* @Last Modified time: 2020-01-08 13:44:11
*/
"use strict";
......@@ -143,40 +143,43 @@ class MerchantController extends Controller {
/**
* @Router GET /screen/merchant/total
* @Description 数据大屏-商户总数统计.---- 广联商户总数(merchant_total) 商户累计订单数(order_total) 当日订单数(realtime_new_order)
* @Description 数据大屏-商户总数统计.---- 广联商户总数(merchant_total) 商户累计订单数(order_total) 当日订单数(realtime_new_order) 当日活跃商户(active_merchant)
*/
async total() {
var merchant_total = await this._fetch_total_({ field:'total_merchant',isGetLast:true})
var order_total = await this._fetch_total_({ field:'total_order',isGetLast:true})
let { total_merchant:merchant_total, total_order:order_total } = await this._fetch_total_({ field:['total_merchant','total_order'],isGetLast:true})
// var merchant_total = await this._fetch_total_({ field:'total_merchant',isGetLast:true})
// var order_total = await this._fetch_total_({ field:'total_order',isGetLast:true})
const realtime = await this.MerchantService.merchant_realtime();
const realtime_new_order = realtime.reduce((pre,next)=>pre + +next['new_order'],0);
const realtime_new_merchant = realtime.reduce((pre,next)=>pre + +next['new_merchant'],0);
const active_merchant = realtime.reduce((pre,next)=>pre + +next['active_merchant'],0);
merchant_total += ~~realtime_new_merchant;
order_total += ~~realtime_new_order;
const data = { merchant_total, order_total, realtime_new_order };
const data = { merchant_total, order_total, realtime_new_order, active_merchant };
this.ctx.body = this.ServerResponse.Success(data);
}
/**
* @Router GET /screen/merchant/statistics
* @Description 数据大屏-数据统计 1. 近七天订单数(recent_7day_order) 2.商户订购设备数(total_device) 3.商户订购设备总额(total_amount) 4.商户活跃度(active_merchant) 5. 当日活跃商户(active_merchant)
* @Description 数据大屏-数据统计 1.近七天订单数(recent_7day_order)2.商户订购设备数(total_device)3.商户订购设备总额(total_amount)4.商户活跃度(active_percent)
* @Request query integer pid 省份id
*/
async statistics() {
const {recent_7day_order,total_device,total_amount,active_merchant,total_merchant}
const {recent_7day_order,total_device,total_amount,recent_merchant,active_merchant}
=
await this._fetch_total_({ field:['recent_7day_order','total_device','total_amount','active_merchant','total_merchant'],isGetLast:true})
const active_percent = this.helper.percent(active_merchant,total_merchant);
const data = { recent_7day_order,total_device , total_amount,active_percent,active_merchant}
await this._fetch_total_({ field:['recent_7day_order','total_device','total_amount','recent_merchant','active_merchant'],isGetLast:true})
const active_percent = this.helper.percent(active_merchant,recent_merchant)
const data = { recent_7day_order,total_device , total_amount,active_percent}
this.ctx.body = this.ServerResponse.Success(data);
}
/**
* @Router GET /screen/merchant/trend
* @Description 数据大屏-1 商户订单趋势(merchant_data) 2.设备订购趋势(order_trend), 3.商户活跃度(active) 4:(活跃商户数 TODO)
* @Description 数据大屏-1 商户订单趋势(merchant_data today_device_order:当日设备订单数量,today_insurance_order:当日保险订单数量,today_repair_order:当日送修订单数量,today_maintain_order:当日保养订单数量) 2.设备订购趋势(order_trend), 3.商户活跃度(active_merchant/recent_merchant) 4:(活跃商户数 active_merchant)
*/
async trend() {
const { active_trend:active, order_trend} = await this._get_stats(['order_trend','active_trend']) //月度数据
const merchant_data = await this._fetch_detail_by_range_({ field:['maintain_order','repair_order','insurance_order','device_order']});
const data = { order_trend,merchant_data,active }
const merchant_data = await this._fetch_detail_by_range_({ field:['today_device_order','today_insurance_order','today_repair_order','today_maintain_order' ]});
const active_merchant = await this._fetch_detail_by_range_({ field:['active_merchant']});
const data = { order_trend,merchant_data,active,active_merchant }
this.ctx.body = this.ServerResponse.Success(data);
}
......@@ -219,7 +222,7 @@ class MerchantController extends Controller {
/**
* @Router GET /screen/merchant/activation
* @Description 实时激活数据播报
* @Description 实时激活数据播报 订单类型(order_type):0:设备激活 1:订购设备 2:保险下单 3:维修订单 4:保养
* @Request query integer pid 省份id
*/
async activation({ query: { pid } }) {
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:19:43
* @Last Modified by: limin
* @Last Modified time: 2020-01-04 12:52:09
* @Last Modified time: 2020-01-08 13:51:53
*/
const moment = require("moment");
......@@ -57,7 +57,8 @@ exports.json_stringify = obj => {
*
*/
exports.percent = (num, total, fixed = 2) =>
(~~((~~num / ~~total) * 100).toFixed(fixed)) + "%";
(Math.round(num / total * 10000) / 100.00 + "%");
// (~~((~~num / ~~total) * 100).toFixed(fixed)) + "%";
/**
* 简单封装 sequelize 查询参数
......
......@@ -58,6 +58,26 @@ module.exports = app => {
allowNull: true,
defaultValue: '0'
},
today_device_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
today_insurance_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
today_repair_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
today_maintain_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
recent_7day_order: {
type: DataTypes.INTEGER(10),
allowNull: true,
......
......@@ -38,6 +38,11 @@ module.exports = app => {
allowNull: true,
defaultValue: '0'
},
recent_merchant: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
......
......@@ -25,6 +25,11 @@ module.exports = app => {
allowNull: true,
defaultValue: '0'
},
active_merchant: {
type: DataTypes.INTEGER(10),
allowNull: true,
defaultValue: '0'
},
create_time: {
type: DataTypes.DATE,
allowNull: true
......
......@@ -38,7 +38,8 @@ class UpdateCacheMerchant extends Subscription {
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,type_jingxiao,recent_merchant } = obj;
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,recent_merchant,
today_device_order,today_insurance_order,today_repair_order,today_maintain_order } = obj;
target["total_merchant"] += +total_merchant; //商户总数
target["total_device"] += +total_device; //订购设备总数
target["total_amount"] += parseFloat(total_amount); // 订购设备总额
......@@ -60,6 +61,10 @@ class UpdateCacheMerchant extends Subscription {
target["type_meibao"] += +type_meibao; // 商户类型:美保店
target["type_jingxiao"] += +type_jingxiao; // 商户类型:经销商
target["recent_merchant"] += +recent_merchant; // 近活跃商户
target["today_device_order"] += +today_device_order; // 当日设备订单数量
target["today_insurance_order"] += +today_insurance_order; // 当日保险订单数量
target["today_repair_order"] += +today_repair_order; // 当日送修订单数量
target["today_maintain_order"] += +today_maintain_order; // 当日保养订单数量
} else {
target["total_merchant"] = 0; //商户总数
target["total_device"] = 0; //订购设备总数
......@@ -82,6 +87,10 @@ class UpdateCacheMerchant extends Subscription {
target["type_meibao"] = 0; // 商户类型:美保店
target["type_jingxiao"] = 0; // 商户类型:经销商
target["recent_merchant"] = 0; //近活跃商户
target["today_device_order"] = 0; //当日设备订单数量
target["today_insurance_order"] = 0; //当日保险订单数量
target["today_repair_order"] = 0; //当日送修订单数量
target["today_maintain_order"] = 0; //当日保养订单数量
}
return target;
}
......@@ -90,15 +99,18 @@ class UpdateCacheMerchant extends Subscription {
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,type_jingxiao,recent_merchant,day} = merchant;
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,recent_merchant,
today_device_order,today_insurance_order,today_repair_order,today_maintain_order,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,type_jingxiao,recent_merchant }); // 累加全国总数值
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,recent_merchant,
today_device_order,today_insurance_order,today_repair_order,today_maintain_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,
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,recent_merchant };
type_4s,type_weixiu,type_yingai,type_jingpin,type_meibao,type_jingxiao,recent_merchant,
today_device_order,today_insurance_order,today_repair_order,today_maintain_order };
}.bind(this)
);
return { data, date };
......
......@@ -2,7 +2,7 @@
* @Author: limin
* @Date: 2019-11-21 11:18:37
* @Last Modified by: limin
* @Last Modified time: 2020-01-04 19:12:53
* @Last Modified time: 2020-01-08 13:41:20
*/
const Service = require("egg").Service;
......@@ -85,7 +85,7 @@ class MerchantService extends Service {
* @Description 获取商户统计数 (天)
*/
async merchant_summary_by_day({ beginDate, endDate }) {
var option = this.__build__option__({ beginDate, endDate });
var option = this.__build__option__({ beginDate, endDate,order: [["day", "ASC"]] });
const data = await this.MCDS.findAll(option);
return data;
}
......@@ -145,6 +145,7 @@ class MerchantService extends Service {
"prov_code",
"month",
[fn("SUM", col("active_merchant")), "active_merchant"],
[fn("SUM", col("recent_merchant")), "recent_merchant"],
],
group: "month",
where: {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!