WeighExceptedController.php 6.1 KB

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