WeighExceptedController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\WaybillExport;
  4. use App\Package;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\Auth;
  7. use Illuminate\Support\Facades\Gate;
  8. use Maatwebsite\Excel\Facades\Excel;
  9. class WeighExceptedController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. *
  14. * @return \Illuminate\Http\Response
  15. */
  16. public function indexCreate(Request $request)
  17. {
  18. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  19. $paginate=$request->input('paginate');
  20. if ($paginate){
  21. $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
  22. where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate($paginate);
  23. }else{
  24. $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
  25. where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate(50);
  26. };
  27. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
  28. }
  29. public function indexIssued(Request $request)
  30. {
  31. if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
  32. $paginate=$request->input('paginate');
  33. if ($paginate){
  34. $weightExcepteds=Package::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')->paginate($paginate);
  36. }else{
  37. $weightExcepteds=Package::select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
  38. where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC')->paginate(50);
  39. };
  40. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
  41. }
  42. public function export($id){
  43. if(!Gate::allows('称重信息-查看异常')){ return redirect(url('/')); }
  44. if ($id==-1){
  45. $id=[];
  46. ini_set('max_execution_time',2500);
  47. ini_set('memory_limit','1526M');
  48. $packages=Package::select('id')->get();
  49. foreach ($packages as $package){
  50. array_push($id,$package->id);
  51. }
  52. }else $id = explode( ',',$id);
  53. if (!$id)return ;
  54. $weighExcepted=Package::find($id[0]);
  55. if (!$weighExcepted->status=="下发异常"){
  56. $row=[[
  57. 'id'=>'ID',
  58. 'logistic_number'=>'快递单号',
  59. 'logistic_name'=>'承运商',
  60. 'measuringMachine_name'=>'设备',
  61. 'weigh_time'=>'称重时间',
  62. 'weight'=>'重(KG)',
  63. 'length'=>'长(CM)',
  64. 'width'=>'宽(CM)',
  65. 'height'=>'高(CM)',
  66. 'bulk'=>'体积(CM³)',
  67. 'paperBox_name'=>'纸箱',
  68. 'genre'=>'异常类型',
  69. 'created_at'=>'称重时间',
  70. 'status'=>'异常类型',
  71. ]];
  72. $list=[];
  73. for ($i=0; $i<count($id);$i++){
  74. $weighExcepted=Package::find($id[$i]);
  75. $w=[
  76. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  77. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  78. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  79. 'measuringMachine_name'=>isset($weighExcepted->measuringMachine_name)?$weighExcepted->measuringMachine_name:'',
  80. 'weigh_time'=>isset($weighExcepted->weigh_time)?$weighExcepted->weigh_time:'',
  81. 'weight'=>isset($weighExcepted->weight)?$weighExcepted->weight:'',
  82. 'length'=>isset($weighExcepted->length)?$weighExcepted->length:'',
  83. 'width'=>isset($weighExcepted->width)?$weighExcepted->width:'',
  84. 'bulk'=>isset($weighExcepted->bulk)?$weighExcepted->bulk:'',
  85. 'height'=>isset($weighExcepted->height)?$weighExcepted->height:'',
  86. 'paperBox_name'=>isset($weighExcepted->paperBox_name)?$weighExcepted->paperBox_name:'',
  87. 'genre'=>isset($weighExcepted->genre)?$weighExcepted->genre:'',
  88. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  89. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:''
  90. ];
  91. $list[$i]=$w;
  92. }
  93. }else{
  94. $row=[[
  95. 'id'=>'ID',
  96. 'logistic_number'=>'快递单号',
  97. 'created_at'=>'下发时间',
  98. 'delivery_number'=>'发货单号',
  99. 'batch_number'=>'波次号',
  100. 'batch_rule'=>'波次规则',
  101. 'recipient'=>'收件人',
  102. 'recipient_mobile'=>'收件人电话',
  103. 'logistic_name'=>'承运商',
  104. 'status'=>'异常类型',
  105. ]];
  106. $list=[];
  107. for ($i=0; $i<count($id);$i++){
  108. $weighExcepted=Package::find($id[$i]);
  109. $w=[
  110. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  111. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  112. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  113. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  114. 'delivery_number'=>isset($weighExcepted->delivery_number)?$weighExcepted->delivery_number:'',
  115. 'batch_number'=>isset($weighExcepted->batch_number)?$weighExcepted->batch_number:'',
  116. 'batch_rule'=>isset($weighExcepted->batch_rule)?$weighExcepted->batch_rule:'',
  117. 'recipient'=>isset($weighExcepted->recipient)?$weighExcepted->recipient:'',
  118. 'recipient_mobile'=>isset($weighExcepted->recipient_mobile)?$weighExcepted->recipient_mobile:'',
  119. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:'',
  120. ];
  121. $list[$i]=$w;
  122. }
  123. }
  124. return Excel::download(new WaybillExport($row,$list), date('YmdHis', time()). '称重异常单.xls');
  125. }
  126. }