input()); $totalNum = $query->sum('sale');//总产量 $list = $query->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50)); $list->load(['createdBy']); return $this->json([ 'total' => $totalNum, 'list' => CropFlowResource::collection($list), ]); } public function store(CropFlowRequest $request) { $flows = $request->input('flows'); CropFlow::insert(array_map(function($item) use ($request){ return array_merge($item, [ 'time_year' => $request->input('time_year'), 'crop_id' => $request->input('crop_id'), 'created_by' => auth('api')->user()?->id ?? 0, 'updated_by' => auth('api')->user()?->id ?? 0, 'created_at' => now(), 'updated_at' => now(), ]); }, $flows)); return $this->success('添加成功'); } public function show(CropFlow $cropFlow) { $cropFlow->load(['crop', 'user']); return $this->json(CropFlowResource::make($cropFlow)); } public function update(CropFlow $cropFlow, CropFlowUpdateRequest $request) { $cropFlow->update(array_merge($request->input(), ['updated_by'=>auth('api')->user()?->id ?? 0,] )); return $this->success('修改成功'); } public function destroy(CropFlow $cropFlow) { $cropFlow->delete(); return $this->success('删除成功'); } }