subDays(15); if ($request->input('logistic_number')){ $packages=$packages->where('logistic_number','like','%'.$request->input('logistic_number').'%')->where('created_at','>',$today->format('Y-m-d')); } if ($request->input('delivery_number')){ $packages=$packages->where('delivery_number','like','%'.$request->input('delivery_number').'%')->where('created_at','>',$today->format('Y-m-d')); } if ($request->input('created_at_start')){ $packages=$packages->where('created_at','>=',$request->input('created_at_start')); } if ($request->input('created_at_end')){ $packages=$packages->where('created_at','<=',$request->input('created_at_end')); } if ($request->input('owner_id')){ $packages=$packages->where('owner_id',$request->input('owner_id')); } if ($request->input('batch_number')){ $packages=$packages->where('batch_number','like','%'.$request->input('batch_number').'%')->where('created_at','>',$today->format('Y-m-d')); } return $packages; } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index(Request $request) { if(!Gate::allows('称重管理-查询')){ return redirect(url('/')); } if ($request->input()){ $packages=Package::orderBy('id','DESC'); $packages=$this->conditionQuery($request,$packages); $packages=$packages->paginate($request->input('paginate')?$request->input('paginate'):50); $owners=Owner::select('id','name')->get(); return view('weight.package.index',['packages'=>$packages,'owners'=>$owners]); } $packages=Package::orderBy('id','DESC')->paginate(50); $owners=Owner::select('id','name')->get(); return view('weight.package.index',['packages'=>$packages,'owners'=>$owners]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { if(!Gate::allows('称重管理-录入')){ return redirect(url('/')); } $paperBoxes=PaperBox::select('id','model')->get(); return view('weight.package.create',['paperBoxes'=>$paperBoxes]); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if(!Gate::allows('称重管理-录入')){ return redirect(url('/')); } $this->validator($request)->validate(); $logistic_number=$request->input('logistic_number'); $weight=$request->input('weight'); $batch_number=$request->input('batch_number'); $paper_box_id=$request->input('paper_box_id'); $package=null; if($batch_number)$package=Package::where('batch_number',$batch_number)->first(); if($logistic_number)$package=Package::where('logistic_number',$logistic_number)->first(); if (!$package && !$logistic_number)return redirect('package/create')->with('successError','录入失败!系统内没有对应波次的包裹!'); if ($package){ $accomplishToWMS=new \App\Http\Controllers\Api\thirdPart\flux\PackageController(); if ($package->batch_rule&&strstr($package->batch_rule,'组合')){ $this->syncBatch($package->batch_number,$weight,null,null,null,Carbon::now(),$paper_box_id); }else{ $package->weight=$weight; $package->paper_box_id=$paper_box_id; $package->batch_number=$batch_number; $result=$accomplishToWMS->accomplishToWMS($package); if ($result['result']=='success'){ if ($package->status=="记录异常")$package->status="已上传异常"; else $package->status="已上传"; }else{ $package->status="上传异常"; } } }else{ $package=new Package([ 'logistic_number'=>$logistic_number, 'weight'=>$weight, 'paper_box_id'=>$paper_box_id, 'batch_number'=>$batch_number ]); } $package->save(); event(new WeighedEvent($package)); return redirect('package/create')->with('successTip','操作成功'); } /** * Display the specified resource. * * @param \App\Package $packages * @return \Illuminate\Http\Response */ public function show(Package $packages) { // } /** * Show the form for editing the specified resource. * * @param \App\Package $packages * @return \Illuminate\Http\Response */ public function edit(Package $packages) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Package $packages * @return \Illuminate\Http\Response */ public function update(Request $request, Package $packages) { // } /** * Remove the specified resource from storage. * * @param \App\Package $packages * @return \Illuminate\Http\Response */ public function destroy(Package $packages) { // } public function export($id,Request $request){ if(!Gate::allows('称重管理-查询')){ return '没有权限'; } if ($id==-1){ $id=[]; ini_set('max_execution_time',2500); ini_set('memory_limit','1526M'); $packages=Package::select('id'); $packages=$this->conditionQuery($request,$packages); $packages=$packages->get(); foreach ($packages as $package){ array_push($id,$package->id); } }else $id = explode( ',',$id); if (!$id)return ; $row=[[ 'id'=>'ID', 'owner_name'=>'货主', 'logistic_number'=>'快递单号', 'delivery_number'=>'发货单号', 'batch_number'=>'波次号', 'batch_rule'=>'波次规则', 'created_at'=>'操作时间', 'recipient'=>'收件人', 'recipient_mobile'=>'收件人电话', 'logistic_name'=>'承运商', 'measuringMachine_name'=>'设备', 'weight'=>'重量(KG)', 'length'=>'长(CM)', 'width'=>'宽(CM)', 'height'=>'高(CM)', 'bulk'=>'体积(CM³)', 'paperBox_name'=>'纸箱', 'status'=>'状态', ]]; $list=[]; for ($i=0; $iisset($package->id)?$package->id:'', 'owner_name'=>isset($package->owner_name)?$package->owner_name:'', 'logistic_number'=>isset($package->logistic_number)?$package->logistic_number:'', 'delivery_number'=>isset($package->delivery_number)?$package->delivery_number:'', 'batch_number'=>isset($package->batch_number)?$package->batch_number:'', 'batch_rule'=>isset($package->batch_rule)?$package->batch_rule:'', 'created_at'=>isset($package->created_at)?$package->created_at:'', 'recipient'=>isset($package->recipient)?$package->recipient:'', 'recipient_mobile'=>isset($package->recipient_mobile)?$package->recipient_mobile:'', 'logistic_name'=>isset($package->logistic_name)?$package->logistic_name:'', 'measuringMachine_name'=>isset($package->measuringMachine_name)?$package->measuringMachine_name:'', 'weight'=>isset($package->weight)?$package->weight:'', 'length'=>isset($package->length)?$package->length:'', 'width'=>isset($package->width)?$package->width:'', 'height'=>isset($package->height)?$package->height:'', 'bulk'=>isset($package->bulk)?$package->bulk:'', 'paperBox_name'=>isset($package->paperBox_name)?$package->paperBox_name:'', 'status'=>isset($package->status)?$package->status:'' ]; $list[$i]=$w; } return Excel::download(new WaybillExport($row,$list),date('YmdHis', time()).'-称重记录单.xls'); } protected function validator(Request $request){ $validator=Validator::make($request->input(),[ 'logistic_number'=>['nullable','max:50'], 'weight'=>'required|min:0|max:999999|numeric', 'paper_box_id'=>'nullable|integer', 'batch_number'=>'required_without:logistic_number' ],[ 'required'=>':attribute 为必填项', 'max'=>':attribute 字符过多或输入值过大', 'integer'=>':attribute 选择有误', 'min'=>':attribute 不得为负', 'numeric'=>':attribute 应为数字', 'unique'=>':attribute 已存在', 'required_without'=>':attribute 与快递单号至少填一项' ],[ 'logistic_number'=>'快递单号', 'weight'=>'重量', 'paper_box_id'=>'纸箱', 'batch_number'=>'波次号', ]); return $validator; } public function syncBatch($batch_number,$weight,$max,$centre,$min,$date,$paperBox_id){ $accomplishToWMS=new \App\Http\Controllers\Api\thirdPart\flux\PackageController(); $packagesBatch=Package::where('batch_number',$batch_number)->get(); foreach ($packagesBatch as $packageBatch){ $packageBatch->weight=$weight; if($max)$packageBatch->length=$max; if($centre)$packageBatch->width=$centre; if($min)$packageBatch->height=$min; $packageBatch->bulk=$max*$centre*$min; $packageBatch->weighed_at=$date; if ($paperBox_id)$packageBatch->paper_box_id=$paperBox_id; $packageBatch->status="未上传"; $result=$accomplishToWMS->accomplishToWMS($packageBatch); if ($result['result']=='success'){ if ($packageBatch->status=="记录异常")$packageBatch->status="已上传异常"; else $packageBatch->status="已上传"; }else{ $packageBatch->status="上传异常"; } $packageBatch->save(); } } }