This commit is contained in:
邓皓元 2019-10-23 18:06:28 +08:00
parent 420ecb8b3d
commit 3ad17f9d0c

View File

@ -4,181 +4,181 @@ use Illuminate\Support\Carbon;
require_once realpath(dirname(__FILE__) . '/TestCase.php'); require_once realpath(dirname(__FILE__) . '/TestCase.php');
function stat_echo_total($sql) // function stat_echo_total($sql)
{ // {
$start = Carbon::parse('2018-01-01'); // $start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01'); // $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start); // $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) { // for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth(); // $month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Y-m-d H:i:s')]); // $res = DB::select($sql, [$month->format('Y-m-d H:i:s')]);
foreach ($res as $key => $value) { // foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL; // echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// break 2; // // break 2;
} // }
} // }
} // }
// 总用户数 // // 总用户数
echo "总用户数,类型,数量" . PHP_EOL; // echo "总用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.created_at < ? // c.created_at < ?
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_total($sql); // stat_echo_total($sql);
// 2G用户数 // // 2G用户数
echo "2G用户数,类型,数量" . PHP_EOL; // echo "2G用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.service_start_at < ? and // c.service_start_at < ? and
pack.flows <= 100 // pack.flows <= 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_total($sql); // stat_echo_total($sql);
// 4G用户数 // // 4G用户数
echo "4G用户数,类型,数量" . PHP_EOL; // echo "4G用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.created_at < ? and // c.created_at < ? and
pack.flows > 100 // pack.flows > 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_total($sql); // stat_echo_total($sql);
function stat_echo_service($sql) // function stat_echo_service($sql)
{ // {
$start = Carbon::parse('2018-01-01'); // $start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01'); // $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start); // $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) { // for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth(); // $month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Y-m-d H:i:s'), $month->format('Y-m-d H:i:s')]); // $res = DB::select($sql, [$month->format('Y-m-d H:i:s'), $month->format('Y-m-d H:i:s')]);
foreach ($res as $key => $value) { // foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL; // echo $month->format('Y-m') . ',' . $value->vehicle . ',' . $value->count . PHP_EOL;
// break 2; // // break 2;
} // }
} // }
} // }
// 活跃用户数 // // 活跃用户数
echo "活跃用户数,类型,数量" . PHP_EOL; // echo "活跃用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? // c.service_start_at < ? and c.service_end_at > ?
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_service($sql); // stat_echo_service($sql);
// 活跃2G用户数 // // 活跃2G用户数
echo "活跃2G用户数,类型,数量" . PHP_EOL; // echo "活跃2G用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and // c.service_start_at < ? and c.service_end_at > ? and
pack.flows <= 100 // pack.flows <= 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_service($sql); // stat_echo_service($sql);
// 活跃4G用户数 // // 活跃4G用户数
echo "活跃4G用户数,类型,数量" . PHP_EOL; // echo "活跃4G用户数,类型,数量" . PHP_EOL;
$sql = " // $sql = "
select // select
count(distinct sim), // count(distinct sim),
p.vehicle // p.vehicle
from // from
virtual_order_cards_partition c // virtual_order_cards_partition c
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
c.deleted_at is null and // c.deleted_at is null and
c.refunded_at is null and // c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and // c.service_start_at < ? and c.service_end_at > ? and
pack.flows > 100 // pack.flows > 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_service($sql); // stat_echo_service($sql);
@ -217,7 +217,8 @@ join virtual_packages pack on
where where
c.deleted_at is null and c.deleted_at is null and
c.refunded_at is null and c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? c.service_start_at < ? and c.service_end_at > ? and
pack.flowed = 0
group by group by
p.vehicle p.vehicle
"; ";
@ -243,7 +244,8 @@ where
c.deleted_at is null and c.deleted_at is null and
c.refunded_at is null and c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and c.service_start_at < ? and c.service_end_at > ? and
pack.flows <= 100 pack.flows <= 100 and
pack.flowed = 0
group by group by
p.vehicle p.vehicle
"; ";
@ -269,7 +271,8 @@ where
c.deleted_at is null and c.deleted_at is null and
c.refunded_at is null and c.refunded_at is null and
c.service_start_at < ? and c.service_end_at > ? and c.service_start_at < ? and c.service_end_at > ? and
pack.flows > 100 pack.flows > 100 and
pack.flowed = 0
group by group by
p.vehicle p.vehicle
"; ";
@ -277,94 +280,94 @@ group by
stat_echo_price($sql); stat_echo_price($sql);
function stat_echo_flow($sql) // function stat_echo_flow($sql)
{ // {
$start = Carbon::parse('2018-01-01'); // $start = Carbon::parse('2018-01-01');
$end = Carbon::parse('2019-10-01'); // $end = Carbon::parse('2019-10-01');
$j = $end->diffInMonths($start); // $j = $end->diffInMonths($start);
for ($i=0; $i < $j; $i++) { // for ($i=0; $i < $j; $i++) {
$month = $start->copy()->addMonths($i)->endOfMonth(); // $month = $start->copy()->addMonths($i)->endOfMonth();
$res = DB::select($sql, [$month->format('Ym')]); // $res = DB::select($sql, [$month->format('Ym')]);
foreach ($res as $key => $value) { // foreach ($res as $key => $value) {
echo $month->format('Y-m') . ',' . $value->vehicle . ',' . sprintf("%.02f", $value->avg) . PHP_EOL; // echo $month->format('Y-m') . ',' . $value->vehicle . ',' . sprintf("%.02f", $value->avg) . PHP_EOL;
// break 2; // // break 2;
} // }
} // }
} // }
// 用户平均使用流量 // // 用户平均使用流量
echo "用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL; // echo "用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = " // $sql = "
select // select
avg(f.mebibyte), // avg(f.mebibyte),
p.vehicle // p.vehicle
from // from
virtual_flow_pool_months f // virtual_flow_pool_months f
join virtual_order_cards c on // join virtual_order_cards c on
f.sim = c.sim // f.sim = c.sim
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
f.month = ? // f.month = ?
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_flow($sql); // stat_echo_flow($sql);
// 2G用户平均使用流量 // // 2G用户平均使用流量
echo "2G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL; // echo "2G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = " // $sql = "
select // select
avg(f.mebibyte), // avg(f.mebibyte),
p.vehicle // p.vehicle
from // from
virtual_flow_pool_months f // virtual_flow_pool_months f
join virtual_order_cards c on // join virtual_order_cards c on
f.sim = c.sim // f.sim = c.sim
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
f.month = ? and // f.month = ? and
pack.flows <= 100 // pack.flows <= 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_flow($sql); // stat_echo_flow($sql);
// 4G用户平均使用流量 // // 4G用户平均使用流量
echo "4G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL; // echo "4G用户平均使用流量,类型,平均流量(Mib)" . PHP_EOL;
$sql = " // $sql = "
select // select
avg(f.mebibyte), // avg(f.mebibyte),
p.vehicle // p.vehicle
from // from
virtual_flow_pool_months f // virtual_flow_pool_months f
join virtual_order_cards c on // join virtual_order_cards c on
f.sim = c.sim // f.sim = c.sim
join virtual_properties p on // join virtual_properties p on
p.company_id = c.company_id and // p.company_id = c.company_id and
p.package_id = c.package_id // p.package_id = c.package_id
join virtual_packages pack on // join virtual_packages pack on
pack.id = c.package_id and // pack.id = c.package_id and
pack.deleted_at is null // pack.deleted_at is null
where // where
f.month = ? and // f.month = ? and
pack.flows > 100 // pack.flows > 100
group by // group by
p.vehicle // p.vehicle
"; // ";
stat_echo_flow($sql); // stat_echo_flow($sql);