This commit is contained in:
邓皓元 2019-10-16 16:36:31 +08:00
parent 4ccacd0148
commit 6f14bf50c3
3 changed files with 374 additions and 0 deletions

View File

@ -138,6 +138,7 @@ class OrderService extends Service
14432 => ['members' => 3, 'counts' => 3, 'custom_price' => 150], // 深圳市美凯欣科技有限公司银行转账Y02
16358 => ['members' => 3, 'counts' => 3, 'custom_price' => 64.5], // 深圳市美凯欣科技有限公司银行转账Y02
7734 => ['members' => -1, 'counts' => -1, 'custom_price' => -50], // 深圳思畅智能系统有限公司银行转账Y02
// 19585 => ['members' => 25, 'counts' => 25, 'custom_price' => 425], // 深圳市康凯斯信息技术有限公司Y-02 2017-11
];
$o_ids = str_to_array($item->order_id);

View File

@ -55,6 +55,9 @@ class CardController extends Controller
$conditions['id'] = intval(str_replace('No', '', $conditions['id']));
}
unset($conditions['orderBy']);
unset($conditions['sortedBy']);
$conditions['type'] = 0;
$total = app(OrderCardPartitionRepository::class)->withConditions($conditions)->applyConditions()->count();

View File

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