WeighExceptedController.php 6.8 KB

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