100 lines
2.4 KiB
PHP
100 lines
2.4 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['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 > 50000;
|
|
|
|
$url = ExportService::store($export, $this->disk, $queue);
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
|
|
return res($url, '导出成功', 201);
|
|
}
|
|
}
|