WeighExceptedController.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\OrderPackage;
  4. use App\Services\OrderPackageService;
  5. use Exception;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Gate;
  8. use Illuminate\Support\Facades\Http;
  9. class WeighExceptedController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. * @param Request $request
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function indexCreate(Request $request)
  17. {
  18. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  19. /** @var OrderPackageService */
  20. $weightExcepteds = app('orderPackageService')->createExceptionPaginate($request->paginate ?? 50);
  21. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
  22. }
  23. public function indexIssued(Request $request)
  24. {
  25. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  26. $weightExcepteds=app('orderPackageService')->issueExceptionPaginate($request->paginate ?? 50);
  27. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
  28. }
  29. public function export($type ,Request $request){
  30. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  31. if ($type == 'indexIssued'){
  32. if ($request->checkAllSign){
  33. $params = $request->input();
  34. unset($params['checkAllSign']);
  35. $sql = app('weighExceptedService')->getIssuedExceptionSql($params);
  36. }else $sql=app('weighExceptedService')->getIssuedExceptionSql(['id'=>$request->data]);
  37. $post = Http::post(config('go.export.url'),['type'=>'packageIssuedException','sql'=>$sql]);
  38. if ($post->status() == 500){
  39. throw new Exception($post->header("Msg"));
  40. }
  41. return response($post,200, [
  42. "Content-type"=>"application/octet-stream",
  43. "Content-Disposition"=>"attachment; filename=下发异常记录-".date('ymdHis').'.xlsx',
  44. ]);
  45. }else{
  46. if ($request->checkAllSign){
  47. $params = $request->input();
  48. unset($params['checkAllSign']);
  49. $sql = app('weighExceptedService')->getCreateExceptionSql($params);
  50. }else $sql=app('weighExceptedService')->getCreateExceptionSql(['id'=>$request->data]);
  51. $post = Http::post(config('go.export.url'),['type'=>'packageCreateException','sql'=>$sql]);
  52. if ($post->status() == 500){
  53. throw new Exception($post->header("Msg"));
  54. }
  55. return response($post,200, [
  56. "Content-type"=>"application/octet-stream",
  57. "Content-Disposition"=>"attachment; filename=录入异常记录-".date('ymdHis').'.xlsx',
  58. ]);
  59. }
  60. }
  61. }