ProcessStatisticController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Process;
  4. use App\Services\ProcessStatisticService;
  5. use Exception;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Gate;
  8. use Illuminate\Support\Facades\Http;
  9. class ProcessStatisticController extends Controller
  10. {
  11. public function index(Request $request){
  12. /** @var ProcessStatisticService $processStatistics */
  13. $processStatistics=app("processStatisticService")->paginate($request->input());
  14. $owners=app("ownerService")->getSelection();
  15. $processMethods=app("processMethodService")->getSelection();
  16. return view('process.statistic',['processStatistics'=>$processStatistics,'owners'=>$owners,'processMethods'=>$processMethods]);
  17. }
  18. public function export(Request $request){
  19. if(!Gate::allows('二次加工管理-查询')){ return '没有权限'; }
  20. if ($request->checkAllSign){
  21. $params = $request->input();
  22. unset($params['checkAllSign']);
  23. $sql = app('processStatisticService')->getSql($params);
  24. }else $sql = app('processStatisticService')->getSql(["process_id"=>$request->data]);
  25. $post = Http::post(config('go.export.url'),['type'=>'processStatistic','sql'=>$sql]);
  26. if ($post->status() == 500){
  27. throw new Exception($post->header("Msg"));
  28. }
  29. return response($post,200, [
  30. "Content-type"=>"application/octet-stream",
  31. "Content-Disposition"=>"attachment; filename=二次加工统计记录-".date('ymdHis').'.xlsx',
  32. ]);
  33. }
  34. }