WeighExceptedController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\Export;
  4. use App\Package;
  5. use Exception;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Support\Facades\Gate;
  9. use Illuminate\Support\Facades\Http;
  10. use Maatwebsite\Excel\Facades\Excel;
  11. class WeighExceptedController extends Controller
  12. {
  13. /**
  14. * Display a listing of the resource.
  15. * @param Request $request
  16. * @return \Illuminate\Http\Response
  17. */
  18. public function indexCreate(Request $request)
  19. {
  20. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  21. $paginate=$request->input('paginate');
  22. $weightExcepteds=Package::query()->select('id','status','logistic_number','logistic_id','measuring_machine_id','weighed_at','weight','length','width','height','bulk','paper_box_id')->
  23. where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC');
  24. if ($paginate){
  25. $weightExcepteds=$weightExcepteds->paginate($paginate);
  26. }else{
  27. $weightExcepteds=$weightExcepteds->paginate(50);
  28. };
  29. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
  30. }
  31. public function indexIssued(Request $request)
  32. {
  33. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  34. $paginate=$request->input('paginate');
  35. $weightExcepteds=Package::query()->select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
  36. where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC');
  37. if ($paginate){
  38. $weightExcepteds=$weightExcepteds->paginate($paginate);
  39. }else{
  40. $weightExcepteds=$weightExcepteds->paginate(50);
  41. };
  42. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
  43. }
  44. public function export($type ,Request $request){
  45. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  46. if ($type == 'indexIssued'){
  47. if ($request->checkAllSign){
  48. $params = $request->input();
  49. unset($params['checkAllSign']);
  50. $sql = app('weighExceptedService')->getIssuedExceptionSql($params);
  51. }else $sql=app('weighExceptedService')->getIssuedExceptionSql(['id'=>$request->data]);
  52. $post = Http::post(config('go.export.url'),['type'=>'packageIssuedException','sql'=>$sql]);
  53. if ($post->status() == 500){
  54. throw new Exception($post->header("Msg"));
  55. }
  56. return response($post,200, [
  57. "Content-type"=>"application/octet-stream",
  58. "Content-Disposition"=>"attachment; filename=下发异常记录-".date('ymdHis').'.xlsx',
  59. ]);
  60. }else{
  61. if ($request->checkAllSign){
  62. $params = $request->input();
  63. unset($params['checkAllSign']);
  64. $sql = app('weighExceptedService')->getCreateExceptionSql($params);
  65. }else $sql=app('weighExceptedService')->getCreateExceptionSql(['id'=>$request->data]);
  66. $post = Http::post(config('go.export.url'),['type'=>'packageCreateException','sql'=>$sql]);
  67. if ($post->status() == 500){
  68. throw new Exception($post->header("Msg"));
  69. }
  70. return response($post,200, [
  71. "Content-type"=>"application/octet-stream",
  72. "Content-Disposition"=>"attachment; filename=录入异常记录-".date('ymdHis').'.xlsx',
  73. ]);
  74. }
  75. }
  76. }