用户数统计
This commit is contained in:
parent
b84825cf8b
commit
86d1e1e18d
38
app/Domains/Stats/Http/Controllers/QuantityController.php
Normal file
38
app/Domains/Stats/Http/Controllers/QuantityController.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Stats\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Domains\Stats\Services\QuantityService;
|
||||
|
||||
/**
|
||||
* 数量统计
|
||||
*/
|
||||
class QuantityController extends Controller
|
||||
{
|
||||
protected $request;
|
||||
protected $renewalService;
|
||||
|
||||
/**
|
||||
* 构造函数,自动注入.
|
||||
*/
|
||||
public function __construct(Request $request, QuantityService $quantityService)
|
||||
{
|
||||
$this->request = $request;
|
||||
$this->quantityService = $quantityService;
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$conditions = $this->request->all();
|
||||
|
||||
$res = $this->quantityService->index($conditions);
|
||||
|
||||
return res($res, '数量统计', 201);
|
||||
}
|
||||
}
|
94
app/Domains/Stats/Services/QuantityService.php
Normal file
94
app/Domains/Stats/Services/QuantityService.php
Normal file
@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Stats\Services;
|
||||
|
||||
use App\Core\Service;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Domains\Virtual\Services\CompanyService;
|
||||
|
||||
class QuantityService extends Service
|
||||
{
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct() { }
|
||||
|
||||
/**
|
||||
* 统计
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function index(array $conditions = [])
|
||||
{
|
||||
$conditions['start_time'];
|
||||
|
||||
$conditions['end_time'];
|
||||
|
||||
|
||||
// $sql = "SELECT
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS all_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS charge_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS new_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS expire_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS renew_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS activate_month,
|
||||
// SUM(CASE WHEN created_at >= '2019-12-31 00:00:00' AND created_at <= '2019-12-31 00:00:00' AND type = 0 THEN 1 ELSE 0 END) AS stop_month,
|
||||
// FROM virtual_order_cards_partition"
|
||||
|
||||
// $diff = Carbon::parse($conditions['end_time'])->diffInMonths(Carbon::parse($conditions['start_time']));
|
||||
|
||||
// $start = Carbon::parse($conditions['start_time']);
|
||||
// for ($i=0; $i < $diff; $i++) {
|
||||
// $month = $start->copy()->addMonths($i);
|
||||
|
||||
|
||||
// # code...
|
||||
// }
|
||||
|
||||
$sql = 'SELECT c.company_id, count(*) AS activates, SUM(CASE WHEN p.id IS NOT NULL THEN 1 ELSE 0 END) AS renewals ' .
|
||||
'FROM virtual_order_cards AS c ' .
|
||||
'LEFT JOIN virtual_order_cards_partition AS p ON p.type IN (1, 2) AND p.sim = c.sim ';
|
||||
$where = 'WHERE c.service_start_at IS NOT NULL ';
|
||||
$group = 'GROUP BY c.company_id ';
|
||||
|
||||
if($conditions['company_id']){
|
||||
$where .= 'AND c.company_id = ' . $conditions['company_id'] . ' ';
|
||||
}
|
||||
|
||||
if($conditions['activate_start_time']){
|
||||
$where .= "AND c.service_start_at >= '" . $conditions['activate_start_time'] . "' ";
|
||||
}
|
||||
|
||||
if($conditions['activate_end_time']){
|
||||
$where .= "AND c.service_end_at <= '" . $conditions['activate_end_time'] . "' ";
|
||||
}
|
||||
|
||||
if($conditions['renewal_start_time']){
|
||||
$where .= "AND p.service_start_at >= '" . $conditions['renewal_start_time'] . "' ";
|
||||
}
|
||||
|
||||
if($conditions['renewal_start_time']){
|
||||
$where .= "AND p.service_start_at >= '" . $conditions['renewal_start_time'] . "' ";
|
||||
}
|
||||
|
||||
$sql = $sql . $where . $group;
|
||||
|
||||
$data = DB::select($sql);
|
||||
|
||||
if(!$data){
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach ($data as &$item) {
|
||||
$item = (array)$item;
|
||||
$item['company_name'] = CompanyService::load($item['company_id'])['name'];
|
||||
$item['ratio'] = $item['activates'] == 0 ? 0 : $item['renewals']/$item['activates'];
|
||||
$item['ratio'] = sprintf('%.02f', $item['ratio']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -208,7 +208,7 @@ class FlowPoolController extends Controller
|
||||
'company_id' => $flowPool->company_id,
|
||||
'package_id' => $package_ids,
|
||||
'unit_price' => 0,
|
||||
'uncancelled' => 1,
|
||||
// 'uncancelled' => 1,
|
||||
];
|
||||
|
||||
$cards = $repository->skipCache()->select([
|
||||
|
@ -141,7 +141,7 @@ class FlowPoolService extends Service
|
||||
'company_id' => $company_ids,
|
||||
'package_id' => $package_ids,
|
||||
'unit_price' => 0,
|
||||
'uncancelled' => 1,
|
||||
// 'uncancelled' => 1,
|
||||
];
|
||||
|
||||
$cards = app(OrderCardPartitionRepository::class)->skipCache()->select([
|
||||
@ -455,7 +455,7 @@ class FlowPoolService extends Service
|
||||
'company_id' => $flowPool->company_id,
|
||||
'package_id' => array_keys($settings),
|
||||
'unit_price' => 0,
|
||||
'uncancelled' => 1,
|
||||
// 'uncancelled' => 1,
|
||||
];
|
||||
|
||||
$cards = app(OrderCardPartitionRepository::class)->skipCache()->selectRaw('distinct sim as sim, package_id')->withConditions($cardConditions)->get();
|
||||
|
Loading…
x
Reference in New Issue
Block a user