105 lines
2.5 KiB
PHP
105 lines
2.5 KiB
PHP
<?php
|
|
namespace App\Domains\Stats\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use App\Exceptions\NotAllowedException;
|
|
use App\Domains\Stats\Exports\OrderExport;
|
|
use App\Domains\Stats\Services\OrderService;
|
|
use App\Domains\Export\Services\ExportService;
|
|
use App\Domains\Stats\Exports\OrderDetailExport;
|
|
|
|
class OrderController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $orderService;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, OrderService $orderService)
|
|
{
|
|
$this->request = $request;
|
|
$this->orderService = $orderService;
|
|
}
|
|
|
|
/**
|
|
* 列表.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$conditions = $this->request->all();
|
|
|
|
$res = $this->orderService->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 OrderExport($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->orderService->detail($conditions);
|
|
|
|
return res($res, '统计明细', 201);
|
|
}
|
|
|
|
/**
|
|
* 统计明细导出.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function detailExport()
|
|
{
|
|
$conditions = $this->request->except(['page', 'limit']);
|
|
$conditions['order_id'] = $this->request->ids('order_id');
|
|
|
|
if (!$class = OrderService::$classes[$conditions['type']]) {
|
|
throw new NotAllowedException('统计类型不存在');
|
|
}
|
|
|
|
$repository = app($class);
|
|
|
|
$total = $repository->withConditions($conditions)->applyConditions()->getCountForPagination();
|
|
|
|
try {
|
|
$export = new OrderDetailExport($conditions);
|
|
|
|
$queue = $total > 6000;
|
|
|
|
$url = ExportService::store($export, $this->disk, $queue);
|
|
} catch (\Exception $e) {
|
|
throw $e;
|
|
}
|
|
|
|
return res($url, '导出成功', 201);
|
|
}
|
|
}
|