WeighExceptedController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. $packages=Package::where('status','上传异常')->orWhere('status','测量异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orWhere('status','下发异常')->select('id')->get();
  47. foreach ($packages as $package){
  48. array_push($id,$package->id);
  49. }
  50. }else $id = explode( ',',$id);
  51. if (!$id)return ;
  52. $weighExcepted=Package::find($id[0]);
  53. if (!$weighExcepted->status=="下发异常"){
  54. $row=[[
  55. 'id'=>'ID',
  56. 'logistic_number'=>'快递单号',
  57. 'logistic_name'=>'承运商',
  58. 'measuringMachine_name'=>'设备',
  59. 'weigh_time'=>'称重时间',
  60. 'weight'=>'重(KG)',
  61. 'length'=>'长(CM)',
  62. 'width'=>'宽(CM)',
  63. 'height'=>'高(CM)',
  64. 'bulk'=>'体积(CM³)',
  65. 'paperBox_name'=>'纸箱',
  66. 'genre'=>'异常类型',
  67. 'created_at'=>'称重时间',
  68. 'status'=>'异常类型',
  69. ]];
  70. $list=[];
  71. for ($i=0; $i<count($id);$i++){
  72. $weighExcepted=Package::find($id[$i]);
  73. $w=[
  74. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  75. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  76. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  77. 'measuringMachine_name'=>isset($weighExcepted->measuringMachine_name)?$weighExcepted->measuringMachine_name:'',
  78. 'weigh_time'=>isset($weighExcepted->weigh_time)?$weighExcepted->weigh_time:'',
  79. 'weight'=>isset($weighExcepted->weight)?$weighExcepted->weight:'',
  80. 'length'=>isset($weighExcepted->length)?$weighExcepted->length:'',
  81. 'width'=>isset($weighExcepted->width)?$weighExcepted->width:'',
  82. 'bulk'=>isset($weighExcepted->bulk)?$weighExcepted->bulk:'',
  83. 'height'=>isset($weighExcepted->height)?$weighExcepted->height:'',
  84. 'paperBox_name'=>isset($weighExcepted->paperBox_name)?$weighExcepted->paperBox_name:'',
  85. 'genre'=>isset($weighExcepted->genre)?$weighExcepted->genre:'',
  86. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  87. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:''
  88. ];
  89. $list[$i]=$w;
  90. }
  91. }else{
  92. $row=[[
  93. 'id'=>'ID',
  94. 'logistic_number'=>'快递单号',
  95. 'created_at'=>'下发时间',
  96. 'delivery_number'=>'发货单号',
  97. 'batch_number'=>'波次号',
  98. 'batch_rule'=>'波次规则',
  99. 'recipient'=>'收件人',
  100. 'recipient_mobile'=>'收件人电话',
  101. 'logistic_name'=>'承运商',
  102. 'status'=>'异常类型',
  103. ]];
  104. $list=[];
  105. for ($i=0; $i<count($id);$i++){
  106. $weighExcepted=Package::find($id[$i]);
  107. $w=[
  108. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  109. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  110. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  111. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  112. 'delivery_number'=>isset($weighExcepted->delivery_number)?$weighExcepted->delivery_number:'',
  113. 'batch_number'=>isset($weighExcepted->batch_number)?$weighExcepted->batch_number:'',
  114. 'batch_rule'=>isset($weighExcepted->batch_rule)?$weighExcepted->batch_rule:'',
  115. 'recipient'=>isset($weighExcepted->recipient)?$weighExcepted->recipient:'',
  116. 'recipient_mobile'=>isset($weighExcepted->recipient_mobile)?$weighExcepted->recipient_mobile:'',
  117. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:'',
  118. ];
  119. $list[$i]=$w;
  120. }
  121. }
  122. return Excel::download(new WaybillExport($row,$list), date('YmdHis', time()). '称重异常单.xls');
  123. }
  124. }