filter($request->all()) ->latest('id') ->paginate(20); return RiceShrimpFlowResource::collection($riceShrimpFlows); } /** * 创建稻虾流向 * * @param \App\Http\Requestes\RiceShrimpFlowStoreRequest $request * @return \App\Http\Resources\RiceShrimpFlowResource * * @throws \App\Exceptions\BizException */ public function store(RiceShrimpFlowStoreRequest $request): RiceShrimpFlowResource { $user = $request->user(); $riceShrimpFlow = new RiceShrimpFlow( $request->only([ 'year', 'quarter', 'area', 'sales', 'unit', ]) ); $riceShrimpFlow->created_by = $user->id; $riceShrimpFlow->updated_by = $user->id; $riceShrimpFlow->save(); (new OperationLogService())->inLog(OperationType::Create, '', $riceShrimpFlow, $request->input()); return RiceShrimpFlowResource::make( $riceShrimpFlow->setRelations([ 'createdBy' => $user, 'updatedBy' => $user, ]) ); } /** * 修改稻虾流向 * * @param int $id * @param \App\Http\Requestes\RiceShrimpFlowUpdateRequest $request * @return \App\Http\Resources\RiceShrimpIndustryResource */ public function update($id, RiceShrimpFlowUpdateRequest $request): RiceShrimpFlowResource { $riceShrimpFlow = RiceShrimpFlow::findOrFail($id); foreach ([ 'year', 'quarter', 'area', 'sales', 'unit', ] as $key) { if ($request->filled($key)) { $riceShrimpFlow->{$key} = $request->input($key); } } if ($riceShrimpFlow->isDirty()) { $riceShrimpFlow->updated_by = $request->user()->id; } $riceShrimpFlow->save(); (new OperationLogService())->inLog(OperationType::Update, '', $riceShrimpFlow, $request->input()); return RiceShrimpFlowResource::make( $riceShrimpFlow->loadMissing(['createdBy', 'updatedBy']) ); } /** * 删除稻虾流向 * * @param int $id * @return \Illuminate\Http\JsonResponse */ public function destroy($id): JsonResponse { $riceShrimpFlow = RiceShrimpFlow::findOrFail($id); $riceShrimpFlow->delete(); (new OperationLogService())->inLog(OperationType::Delete, '', $riceShrimpFlow); return response()->json(null); } }