guard()->user(); $list = EmployeeSignRepair::with(['workflow']) ->where('employee_id', $user->id) ->filter($request->all()) ->orderBy('id', 'desc') ->paginate($request->input('per_page')); return EmployeeSignRepairResource::collection($list); } public function store(Request $request, EmployeeSignRepairService $service) { $user = $this->guard()->user(); $data = $request->all(); $data['employee_id'] = $user->id; try { DB::beginTransaction(); if (!$service->store($data)) { throw new RuntimeException($result); } $model = $service->getCurrentModel(); $workflow = WorkFlowService::make(); if (!$workflow->apply($model->workflow, $user)) { throw new RuntimeException($workflow->getError()); } DB::commit(); return response('', Response::HTTP_OK); } catch (\Exception $e) { DB::rollBack(); throw new RuntimeException($e->getMessage()); } } public function show($id) { $info = EmployeeSignRepair::with(['workflow', 'employee', 'store'])->findOrFail($id); return EmployeeSignRepairResource::make($info); } public function update($id, Request $request, EmployeeSignRepairService $service) { $user = $this->guard()->user(); $model = EmployeeSignRepair::with(['workflow'])->where('employee_id', $user->id)->findOrFail($id); if (!$model->canUpdate()) { throw new RuntimeException('审核中, 无法修改'); } try { DB::beginTransaction(); if (!$service->update($id, $request->all())) { throw new RuntimeException($service->getError()); } $workflow = WorkFlowService::make(); if (!$workflow->apply($model->workflow, $user)) { throw new RuntimeException($workflow->getError()); } DB::commit(); return response('', Response::HTTP_OK); } catch (\Exception $e) { DB::rollBack(); throw new RuntimeException($e->getMessage()); } } public function destroy($id, EmployeeSignRepairService $service) { $user = $this->guard()->user(); $model = EmployeeSignRepair::with(['workflow'])->where('employee_id', $user->id)->findOrFail($id); if (!$model->canUpdate()) { throw new RuntimeException('审核中, 无法删除'); } try { DB::beginTransaction(); if (!$service->delete($id)) { throw new RuntimeException($service->getError()); } DB::commit(); return response('', Response::HTTP_OK); } catch (\Exception $e) { DB::rollBack(); throw new RuntimeException($e->getMessage()); } } }