Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx-business
/
glsx-data-screen-server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 35e5e5e1
authored
Jan 08, 2020
by
liimin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
调整
1 parent
548090f3
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
70 additions
and
23 deletions
app/common/queue.js
app/controller/screen/merchant.js
app/extend/helper.js
app/model/screen/merchant/t_merchant_daily_stat.js
app/model/screen/merchant/t_merchant_device_order_stat.js
app/model/screen/merchant/t_merchant_realtime.js
app/schedule/update_cache_merchant.js
app/service/screen/merchant.js
app/common/queue.js
View file @
35e5e5e
...
@@ -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-0
4 12:17:19
* @Last Modified time: 2020-01-0
8 14:08:08
*/
*/
// const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
// const items = new WeakMap(); //WeakMap对象是密钥/值对的集合,其中密钥被弱引用。键必须是对象,值可以是任意值。
...
...
app/controller/screen/merchant.js
View file @
35e5e5e
...
@@ -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-0
4 19:05:0
1
* @Last Modified time: 2020-01-0
8 13:44:1
1
*/
*/
"use strict"
;
"use strict"
;
...
@@ -143,40 +143,43 @@ class MerchantController extends Controller {
...
@@ -143,40 +143,43 @@ class MerchantController extends Controller {
/**
/**
* @Router GET /screen/merchant/total
* @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
()
{
async
total
()
{
var
merchant_total
=
await
this
.
_fetch_total_
({
field
:
'total_merchant'
,
isGetLast
:
true
})
let
{
total_merchant
:
merchant_total
,
total_order
:
order_total
}
=
await
this
.
_fetch_total_
({
field
:[
'total_merchant'
,
'total_order'
],
isGetLast
:
true
})
var
order_total
=
await
this
.
_fetch_total_
({
field
:
'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
=
await
this
.
MerchantService
.
merchant_realtime
();
const
realtime_new_order
=
realtime
.
reduce
((
pre
,
next
)
=>
pre
+
+
next
[
'new_order'
],
0
);
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
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
;
merchant_total
+=
~~
realtime_new_merchant
;
order_total
+=
~~
realtime_new_order
;
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
);
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
/**
/**
* @Router GET /screen/merchant/statistics
* @Router GET /screen/merchant/statistics
* @Description 数据大屏-数据统计 1.
近七天订单数(recent_7day_order) 2.商户订购设备数(total_device) 3.商户订购设备总额(total_amount) 4.商户活跃度(active_merchant) 5. 当日活跃商户(active_mercha
nt)
* @Description 数据大屏-数据统计 1.
近七天订单数(recent_7day_order)2.商户订购设备数(total_device)3.商户订购设备总额(total_amount)4.商户活跃度(active_perce
nt)
* @Request query integer pid 省份id
* @Request query integer pid 省份id
*/
*/
async
statistics
()
{
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
})
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
,
total_merchant
);
const
active_percent
=
this
.
helper
.
percent
(
active_merchant
,
recent_merchant
)
const
data
=
{
recent_7day_order
,
total_device
,
total_amount
,
active_percent
,
active_merchant
}
const
data
=
{
recent_7day_order
,
total_device
,
total_amount
,
active_percent
}
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
/**
/**
* @Router GET /screen/merchant/trend
* @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
()
{
async
trend
()
{
const
{
active_trend
:
active
,
order_trend
}
=
await
this
.
_get_stats
([
'order_trend'
,
'active_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
merchant_data
=
await
this
.
_fetch_detail_by_range_
({
field
:[
'today_device_order'
,
'today_insurance_order'
,
'today_repair_order'
,
'today_maintain_order'
]});
const
data
=
{
order_trend
,
merchant_data
,
active
}
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
);
this
.
ctx
.
body
=
this
.
ServerResponse
.
Success
(
data
);
}
}
...
@@ -219,7 +222,7 @@ class MerchantController extends Controller {
...
@@ -219,7 +222,7 @@ class MerchantController extends Controller {
/**
/**
* @Router GET /screen/merchant/activation
* @Router GET /screen/merchant/activation
* @Description 实时激活数据播报
* @Description 实时激活数据播报
订单类型(order_type):0:设备激活 1:订购设备 2:保险下单 3:维修订单 4:保养
* @Request query integer pid 省份id
* @Request query integer pid 省份id
*/
*/
async
activation
({
query
:
{
pid
}
})
{
async
activation
({
query
:
{
pid
}
})
{
...
...
app/extend/helper.js
View file @
35e5e5e
...
@@ -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: 2020-01-0
4 12:52:09
* @Last Modified time: 2020-01-0
8 13:51:53
*/
*/
const
moment
=
require
(
"moment"
);
const
moment
=
require
(
"moment"
);
...
@@ -57,7 +57,8 @@ exports.json_stringify = obj => {
...
@@ -57,7 +57,8 @@ exports.json_stringify = obj => {
*
*
*/
*/
exports
.
percent
=
(
num
,
total
,
fixed
=
2
)
=>
exports
.
percent
=
(
num
,
total
,
fixed
=
2
)
=>
(
~~
((
~~
num
/
~~
total
)
*
100
).
toFixed
(
fixed
))
+
"%"
;
(
Math
.
round
(
num
/
total
*
10000
)
/
100.00
+
"%"
);
// (~~((~~num / ~~total) * 100).toFixed(fixed)) + "%";
/**
/**
* 简单封装 sequelize 查询参数
* 简单封装 sequelize 查询参数
...
...
app/model/screen/merchant/t_merchant_daily_stat.js
View file @
35e5e5e
...
@@ -58,6 +58,26 @@ module.exports = app => {
...
@@ -58,6 +58,26 @@ module.exports = app => {
allowNull
:
true
,
allowNull
:
true
,
defaultValue
:
'0'
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
:
{
recent_7day_order
:
{
type
:
DataTypes
.
INTEGER
(
10
),
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
,
allowNull
:
true
,
...
...
app/model/screen/merchant/t_merchant_device_order_stat.js
View file @
35e5e5e
...
@@ -38,6 +38,11 @@ module.exports = app => {
...
@@ -38,6 +38,11 @@ module.exports = app => {
allowNull
:
true
,
allowNull
:
true
,
defaultValue
:
'0'
defaultValue
:
'0'
},
},
recent_merchant
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
,
defaultValue
:
'0'
},
create_time
:
{
create_time
:
{
type
:
DataTypes
.
DATE
,
type
:
DataTypes
.
DATE
,
allowNull
:
true
allowNull
:
true
...
...
app/model/screen/merchant/t_merchant_realtime.js
View file @
35e5e5e
...
@@ -25,6 +25,11 @@ module.exports = app => {
...
@@ -25,6 +25,11 @@ module.exports = app => {
allowNull
:
true
,
allowNull
:
true
,
defaultValue
:
'0'
defaultValue
:
'0'
},
},
active_merchant
:
{
type
:
DataTypes
.
INTEGER
(
10
),
allowNull
:
true
,
defaultValue
:
'0'
},
create_time
:
{
create_time
:
{
type
:
DataTypes
.
DATE
,
type
:
DataTypes
.
DATE
,
allowNull
:
true
allowNull
:
true
...
...
app/schedule/update_cache_merchant.js
View file @
35e5e5e
...
@@ -38,7 +38,8 @@ class UpdateCacheMerchant extends Subscription {
...
@@ -38,7 +38,8 @@ 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
,
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_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
);
// 订购设备总额
...
@@ -60,6 +61,10 @@ class UpdateCacheMerchant extends Subscription {
...
@@ -60,6 +61,10 @@ class UpdateCacheMerchant extends Subscription {
target
[
"type_meibao"
]
+=
+
type_meibao
;
// 商户类型:美保店
target
[
"type_meibao"
]
+=
+
type_meibao
;
// 商户类型:美保店
target
[
"type_jingxiao"
]
+=
+
type_jingxiao
;
// 商户类型:经销商
target
[
"type_jingxiao"
]
+=
+
type_jingxiao
;
// 商户类型:经销商
target
[
"recent_merchant"
]
+=
+
recent_merchant
;
// 近活跃商户
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
{
}
else
{
target
[
"total_merchant"
]
=
0
;
//商户总数
target
[
"total_merchant"
]
=
0
;
//商户总数
target
[
"total_device"
]
=
0
;
//订购设备总数
target
[
"total_device"
]
=
0
;
//订购设备总数
...
@@ -82,6 +87,10 @@ class UpdateCacheMerchant extends Subscription {
...
@@ -82,6 +87,10 @@ class UpdateCacheMerchant extends Subscription {
target
[
"type_meibao"
]
=
0
;
// 商户类型:美保店
target
[
"type_meibao"
]
=
0
;
// 商户类型:美保店
target
[
"type_jingxiao"
]
=
0
;
// 商户类型:经销商
target
[
"type_jingxiao"
]
=
0
;
// 商户类型:经销商
target
[
"recent_merchant"
]
=
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
;
return
target
;
}
}
...
@@ -90,15 +99,18 @@ class UpdateCacheMerchant extends Subscription {
...
@@ -90,15 +99,18 @@ 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
,
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
;
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_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
,
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_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
)
}.
bind
(
this
)
);
);
return
{
data
,
date
};
return
{
data
,
date
};
...
...
app/service/screen/merchant.js
View file @
35e5e5e
...
@@ -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-0
4 19:12:53
* @Last Modified time: 2020-01-0
8 13:41:20
*/
*/
const
Service
=
require
(
"egg"
).
Service
;
const
Service
=
require
(
"egg"
).
Service
;
...
@@ -85,7 +85,7 @@ class MerchantService extends Service {
...
@@ -85,7 +85,7 @@ class MerchantService extends Service {
* @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
,
order
:
[[
"day"
,
"ASC"
]]
});
const
data
=
await
this
.
MCDS
.
findAll
(
option
);
const
data
=
await
this
.
MCDS
.
findAll
(
option
);
return
data
;
return
data
;
}
}
...
@@ -145,6 +145,7 @@ class MerchantService extends Service {
...
@@ -145,6 +145,7 @@ class MerchantService extends Service {
"prov_code"
,
"prov_code"
,
"month"
,
"month"
,
[
fn
(
"SUM"
,
col
(
"active_merchant"
)),
"active_merchant"
],
[
fn
(
"SUM"
,
col
(
"active_merchant"
)),
"active_merchant"
],
[
fn
(
"SUM"
,
col
(
"recent_merchant"
)),
"recent_merchant"
],
],
],
group
:
"month"
,
group
:
"month"
,
where
:
{
where
:
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment