id; $box = BoxBinding::query()->filter($filter)->orderByDesc('id'); if (!Admin::isAdministrator()) { return $this->error('暂无权限'); } $box = $request->get('all') ? $box->get() : $box->paginate(); return $this->ok(BoxBindingResource::collection($box)); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * store 添加中控 * * @param Request $request * @param BoxBinding $box * @return \Illuminate\Http\JsonResponse * @author Fx * */ public function store(BoxBindingRequest $request, BoxBinding $box) { $inputs = $request->validated(); // $box->create($inputs); return $this->ok(BoxBindingResource::make($box)); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * update 更新中控 * * @param Request $request * @param $id * @return void * @author Fx * */ public function update(Request $request, $id) { // } public function updateRemark(RemarkRequest $request, $id) { // $box = BoxBinding::find($id); $inputs = $request->validated(); // Log::info($id); $box->update($inputs); return $this->ok(BoxBindingResource::make($box)); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } /** * import 导入excle * * @param Request $request * @return \Illuminate\Http\JsonResponse * @author Fx * */ public function import(Request $request) { try { Excel::import(new BoxBindingImport, $request->file('boxs')); return $this->ok('导入成功'); } catch (\Exception $e) { Log::error($e->getMessage()); return $this->error('导入失败'); } } /** * download 下载模板 * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse * @author Fx * */ public function download() { return response()->download(public_path('example_box.xlsx')); } /** * unbindBox 解绑 * * @param $id * @return \Illuminate\Http\JsonResponse * @author Fx * */ public function unbindBox($id) { $box = BoxBinding::find($id); if (empty($box)) return $this->error('找不到该中控信息'); $box_no = $box->box_no; $bike = Bike::query()->where('box_no', $box_no)->first(); try { DB::beginTransaction(); // 更新绑定表 $box->is_binding = BoxBinding::BINDING_NO; $box->save(); // 更新车辆信息 if (!empty($bike)) { $bike->box_no = ''; $bike->blu_key = ''; $bike->blu_ase_key = ''; $bike->save(); } DB::commit(); return $this->ok('解绑成功'); } catch (\Exception $e) { DB::rollBack(); Log::error($e->getMessage()); return $this->error('解绑失败,请联系管理员'); } } }