WeighExceptedController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. $paginate=$request->input('paginate');
  19. if ($paginate){
  20. $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
  21. where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate($paginate);
  22. }else{
  23. $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
  24. where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate(50);
  25. };
  26. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
  27. }
  28. public function indexIssued(Request $request)
  29. {
  30. $paginate=$request->input('paginate');
  31. if ($paginate){
  32. $weightExcepteds=Package::select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
  33. where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC')->paginate($paginate);
  34. }else{
  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(50);
  37. };
  38. return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
  39. }
  40. public function export($id){
  41. if ($id==-1){
  42. $id=[];
  43. $packages=Package::where('status','上传异常')->orWhere('status','测量异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orWhere('status','下发异常')->select('id')->get();
  44. foreach ($packages as $package){
  45. array_push($id,$package->id);
  46. }
  47. }else $id = explode( ',',$id);
  48. if (!$id)return ;
  49. $weighExcepted=Package::find($id[0]);
  50. if (!$weighExcepted->status=="下发异常"){
  51. $row=[[
  52. 'id'=>'ID',
  53. 'logistic_number'=>'快递单号',
  54. 'logistic_name'=>'承运商',
  55. 'measuringMachine_name'=>'设备',
  56. 'weigh_time'=>'称重时间',
  57. 'weight'=>'重(KG)',
  58. 'length'=>'长(CM)',
  59. 'width'=>'宽(CM)',
  60. 'height'=>'高(CM)',
  61. 'bulk'=>'体积(CM³)',
  62. 'paperBox_name'=>'纸箱',
  63. 'genre'=>'异常类型',
  64. 'created_at'=>'称重时间',
  65. 'status'=>'异常类型',
  66. ]];
  67. $list=[];
  68. for ($i=0; $i<count($id);$i++){
  69. $weighExcepted=Package::find($id[$i]);
  70. $w=[
  71. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  72. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  73. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  74. 'measuringMachine_name'=>isset($weighExcepted->measuringMachine_name)?$weighExcepted->measuringMachine_name:'',
  75. 'weigh_time'=>isset($weighExcepted->weigh_time)?$weighExcepted->weigh_time:'',
  76. 'weight'=>isset($weighExcepted->weight)?$weighExcepted->weight:'',
  77. 'length'=>isset($weighExcepted->length)?$weighExcepted->length:'',
  78. 'width'=>isset($weighExcepted->width)?$weighExcepted->width:'',
  79. 'bulk'=>isset($weighExcepted->bulk)?$weighExcepted->bulk:'',
  80. 'height'=>isset($weighExcepted->height)?$weighExcepted->height:'',
  81. 'paperBox_name'=>isset($weighExcepted->paperBox_name)?$weighExcepted->paperBox_name:'',
  82. 'genre'=>isset($weighExcepted->genre)?$weighExcepted->genre:'',
  83. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  84. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:''
  85. ];
  86. $list[$i]=$w;
  87. }
  88. }else{
  89. $row=[[
  90. 'id'=>'ID',
  91. 'logistic_number'=>'快递单号',
  92. 'created_at'=>'下发时间',
  93. 'delivery_number'=>'发货单号',
  94. 'batch_number'=>'波次号',
  95. 'batch_rule'=>'波次规则',
  96. 'recipient'=>'收件人',
  97. 'recipient_mobile'=>'收件人电话',
  98. 'logistic_name'=>'承运商',
  99. 'status'=>'异常类型',
  100. ]];
  101. $list=[];
  102. for ($i=0; $i<count($id);$i++){
  103. $weighExcepted=Package::find($id[$i]);
  104. $w=[
  105. 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
  106. 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
  107. 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
  108. 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
  109. 'delivery_number'=>isset($weighExcepted->delivery_number)?$weighExcepted->delivery_number:'',
  110. 'batch_number'=>isset($weighExcepted->batch_number)?$weighExcepted->batch_number:'',
  111. 'batch_rule'=>isset($weighExcepted->batch_rule)?$weighExcepted->batch_rule:'',
  112. 'recipient'=>isset($weighExcepted->recipient)?$weighExcepted->recipient:'',
  113. 'recipient_mobile'=>isset($weighExcepted->recipient_mobile)?$weighExcepted->recipient_mobile:'',
  114. 'status'=>isset($weighExcepted->status)?$weighExcepted->status:'',
  115. ];
  116. $list[$i]=$w;
  117. }
  118. }
  119. return Excel::download(new WaybillExport($row,$list), date('YmdHis', time()). '称重异常单.xls');
  120. }
  121. }