| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\WaybillExport;
- use App\Package;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Maatwebsite\Excel\Facades\Excel;
- class WeighExceptedController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function indexCreate(Request $request)
- {
- if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
- $paginate=$request->input('paginate');
- if ($paginate){
- $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
- where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate($paginate);
- }else{
- $weightExcepteds=Package::select('id','status','logistic_number','logistic_id','measuring_machine_id','created_at','weight','length','width','height','bulk','paper_box_id')->
- where('status','上传异常')->orWhere('status','测量异常')->orderBy('created_at','DESC')->paginate(50);
- };
- return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexCreate']);
- }
- public function indexIssued(Request $request)
- {
- if(!Gate::allows('称重管理-查看异常')){ return redirect(url('/')); }
- $paginate=$request->input('paginate');
- if ($paginate){
- $weightExcepteds=Package::select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
- where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC')->paginate($paginate);
- }else{
- $weightExcepteds=Package::select('id','owner_id','logistic_number','created_at','delivery_number','batch_number','batch_rule','recipient','recipient_mobile','logistic_id')->
- where('status','下发异常')->orWhere('status','记录异常')->orWhere('status','已上传异常')->orderBy('created_at','DESC')->paginate(50);
- };
- return view('weight.weightExcepted.index',['weightExcepteds'=>$weightExcepteds,'view'=>'indexIssued']);
- }
- public function export($id){
- if(!Gate::allows('称重信息-查看异常')){ return redirect(url('/')); }
- if ($id==-1){
- $id=[];
- ini_set('max_execution_time',2500);
- ini_set('memory_limit','1526M');
- $packages=Package::select('id')->get();
- foreach ($packages as $package){
- array_push($id,$package->id);
- }
- }else $id = explode( ',',$id);
- if (!$id)return ;
- $weighExcepted=Package::find($id[0]);
- if (!$weighExcepted->status=="下发异常"){
- $row=[[
- 'id'=>'ID',
- 'logistic_number'=>'快递单号',
- 'logistic_name'=>'承运商',
- 'measuringMachine_name'=>'设备',
- 'weigh_time'=>'称重时间',
- 'weight'=>'重(KG)',
- 'length'=>'长(CM)',
- 'width'=>'宽(CM)',
- 'height'=>'高(CM)',
- 'bulk'=>'体积(CM³)',
- 'paperBox_name'=>'纸箱',
- 'genre'=>'异常类型',
- 'created_at'=>'称重时间',
- 'status'=>'异常类型',
- ]];
- $list=[];
- for ($i=0; $i<count($id);$i++){
- $weighExcepted=Package::find($id[$i]);
- $w=[
- 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
- 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
- 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
- 'measuringMachine_name'=>isset($weighExcepted->measuringMachine_name)?$weighExcepted->measuringMachine_name:'',
- 'weigh_time'=>isset($weighExcepted->weigh_time)?$weighExcepted->weigh_time:'',
- 'weight'=>isset($weighExcepted->weight)?$weighExcepted->weight:'',
- 'length'=>isset($weighExcepted->length)?$weighExcepted->length:'',
- 'width'=>isset($weighExcepted->width)?$weighExcepted->width:'',
- 'bulk'=>isset($weighExcepted->bulk)?$weighExcepted->bulk:'',
- 'height'=>isset($weighExcepted->height)?$weighExcepted->height:'',
- 'paperBox_name'=>isset($weighExcepted->paperBox_name)?$weighExcepted->paperBox_name:'',
- 'genre'=>isset($weighExcepted->genre)?$weighExcepted->genre:'',
- 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
- 'status'=>isset($weighExcepted->status)?$weighExcepted->status:''
- ];
- $list[$i]=$w;
- }
- }else{
- $row=[[
- 'id'=>'ID',
- 'logistic_number'=>'快递单号',
- 'created_at'=>'下发时间',
- 'delivery_number'=>'发货单号',
- 'batch_number'=>'波次号',
- 'batch_rule'=>'波次规则',
- 'recipient'=>'收件人',
- 'recipient_mobile'=>'收件人电话',
- 'logistic_name'=>'承运商',
- 'status'=>'异常类型',
- ]];
- $list=[];
- for ($i=0; $i<count($id);$i++){
- $weighExcepted=Package::find($id[$i]);
- $w=[
- 'id'=>isset($weighExcepted->id)?$weighExcepted->id:'',
- 'logistic_number'=>isset($weighExcepted->logistic_number)?$weighExcepted->logistic_number:'',
- 'logistic_name'=>isset($weighExcepted->logistic_name)?$weighExcepted->logistic_name:'',
- 'created_at'=>isset($weighExcepted->created_at)?$weighExcepted->created_at:'',
- 'delivery_number'=>isset($weighExcepted->delivery_number)?$weighExcepted->delivery_number:'',
- 'batch_number'=>isset($weighExcepted->batch_number)?$weighExcepted->batch_number:'',
- 'batch_rule'=>isset($weighExcepted->batch_rule)?$weighExcepted->batch_rule:'',
- 'recipient'=>isset($weighExcepted->recipient)?$weighExcepted->recipient:'',
- 'recipient_mobile'=>isset($weighExcepted->recipient_mobile)?$weighExcepted->recipient_mobile:'',
- 'status'=>isset($weighExcepted->status)?$weighExcepted->status:'',
- ];
- $list[$i]=$w;
- }
- }
- return Excel::download(new WaybillExport($row,$list), date('YmdHis', time()). '称重异常单.xls');
- }
- }
|