vd/app/Domains/Stats/Http/Controllers/CompanyReportController.php
zhouhq@fxft.net b43e214553 //套餐新增流量套餐类型字段相关查询
//数据统计-用户月报表新增流量套餐类型关联查询
2020-03-30 16:43:49 +08:00

100 lines
2.5 KiB
PHP

<?php
namespace App\Domains\Stats\Http\Controllers;
use Illuminate\Http\Request;
use App\Domains\Export\Services\ExportService;
use App\Domains\Stats\Exports\CompanyReportExport;
use App\Domains\Stats\Services\CompanyReportService;
use App\Domains\Stats\Exports\CompanyReportDetailExport;
use App\Domains\Virtual\Repositories\OrderCardPartitionRepository;
class CompanyReportController extends Controller
{
protected $request;
protected $companyReportService;
/**
* 构造函数,自动注入.
*/
public function __construct(Request $request, CompanyReportService $companyReportService)
{
$this->request = $request;
$this->companyReportService = $companyReportService;
}
/**
* 列表.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$conditions = $this->request->all();
$conditions['virtual_order_cards_partition.type'] = $this->request->ids('type');
$res = $this->companyReportService->index($conditions);
return res($res, '企业月报表', 201);
}
/**
* 导出.
*
* @return \Illuminate\Http\Response
*/
public function export()
{
$conditions = $this->request->except(['page', 'limit']);
$conditions['limit'] = 0;
try {
$export = new CompanyReportExport($conditions);
$url = ExportService::store($export, $this->disk);
} catch (\Exception $e) {
throw $e;
}
return res($url, '导出成功', 201);
}
/**
* 统计明细.
*
* @return \Illuminate\Http\Response
*/
public function detail()
{
$conditions = $this->request->all();
$res = $this->companyReportService->detail($conditions);
return res($res, '统计明细', 201);
}
/**
* 统计明细导出.
*
* @return \Illuminate\Http\Response
*/
public function detailExport(OrderCardPartitionRepository $repository)
{
$conditions = $this->request->except(['page', 'limit']);
$total = $repository->withConditions($conditions)->applyConditions()->count();
try {
$export = new CompanyReportDetailExport($conditions);
$queue = $total > CompanyReportDetailExport::$chunkSize * 50;
$url = ExportService::store($export, $this->disk, $queue);
} catch (\Exception $e) {
throw $e;
}
return res($url, '导出成功', 201);
}
}