WeighExceptedController.php 3.4 KB

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