paginate(35); return view('maintenance.logistic.index',['logistics'=>$logistics]); } public function create() { if(!Gate::allows('承运商-录入')){ return view("exception.authority"); } return view('maintenance.logistic.create'); } public function store(Request $request) { if(!Gate::allows('承运商-录入')){ return view("exception.authority"); } $this->validatorCreate($request->all())->validate(); $request->offsetSet("is_bunched",$request->input("is_bunched") ? 'Y' : 'N'); $logistic=new Logistic($request->all()); $logistic->save(); app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); return redirect('maintenance/logistic/create')->with('successTip',"成功录入承运商“{$request->input('name')}”"); } protected function validatorCreate(array $data) { return Validator::make($data, [ 'type' => ["required"], 'name' => ['required', 'string', 'max:50', 'unique:logistics'], 'code' => ['nullable', 'string', 'max:50', 'unique:logistics,code'], 'delivery_fee' => ['nullable', 'numeric', 'min:0'], ]); } protected function validatorUpdate(array $data,$id) { return Validator::make($data, [ 'type' => ["required"], 'name' => ['required', 'string', 'max:50',"unique:logistics,name,$id"], 'code' => ['nullable', 'string', 'max:50',"unique:logistics,code,$id"], 'delivery_fee' => ['nullable', 'numeric', 'min:0'], ]); } public function edit(Logistic $logistic) { if(!Gate::allows('承运商-编辑')){ return view("exception.authority"); } $logistic = $logistic->toArray(); if ($logistic["tag"]){ $tag = explode(",",$logistic["tag"]); $map = array_flip(Logistic::TAGS); foreach ($tag as &$t)$t = $map[$t]; $logistic["tag"] = implode(",",$tag); } $key = 'LogisticAll_'.implode("",["id","name","tag"]).Str::studly("物流"); Cache::pull($key); return view('maintenance.logistic.edit',['logistic'=>$logistic]); } public function update(Request $request, Logistic $logistic) { if(!Gate::allows('承运商-编辑')){ return redirect(url('/')); } $this->validatorUpdate($request->all(),$logistic->id)->validate(); $request->offsetSet("is_bunched",$request->input("is_bunched") ? 'Y' : 'N'); $logistic->fill($request->all()); $logistic->update(); app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']); return redirect('maintenance/logistic/')->with('successTip',"成功修改承运商“{$logistic['name']}”!"); } public function destroy(Logistic $logistic) { if(!Gate::allows('承运商-删除')){ return view("exception.authority"); } app('LogService')->log(__METHOD__,__FUNCTION__,$logistic->toJson(),Auth::user()['id']); $re=$logistic->delete(); return ['success'=>$re]; } public function get() { $type = \request("type"); $column = ['id','name']; if (!$type)$column[] = "type"; $logistics = app("LogisticService")->getSelection($column,$type); return ["success"=>true,"data"=>$logistics]; } }