settingRepository = $settingRepositoryEloquent; } /** * @param Request $request * * @return mixed * @throws \Prettus\Repository\Exceptions\RepositoryException */ public function handleList(Request $request) { $this->settingRepository->pushCriteria(new SettingCriteria($request)); $this->settingRepository->setPresenter(SettingPresenter::class); return $this->settingRepository->searchSettingsByPage(); } /** * @param $id * * @return \Illuminate\Database\Eloquent\Model */ public function handleProfile($id) { $this->settingRepository->setPresenter(SettingPresenter::class); return $this->settingRepository->searchSettingBy($id); } /** * @param array $data * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleStore($data) { $setting = $this->settingRepository->create($data); return $setting; } /** * @param array $data * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleUpdate($data) { $setting = $this->settingRepository->update($data, $data['id']); return $setting; } /** * @param Request $request * * @return mixed * @throws \Prettus\Validator\Exceptions\ValidatorException */ public function handleDelete($id) { return $this->settingRepository->delete($id); } /** * 获取配置参数 * @param $keys * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator|\Illuminate\Support\Collection|mixed */ public function handleConfigs($keys) { return $this->settingRepository->findWhere([['code', 'in', $keys]], ['code', 'value'])->pluck('value', 'code'); } /** * 获取规则 * @return mixed */ public function handleRules() { return $this->settingRepository->pluck('name', 'code')->toArray(); } /** * 保存配置 * @param $data * @return void */ public function handleSave($data) { DB::beginTransaction(); try { foreach ($data as $key => $d) { Setting::query()->where('code', $key)->update(['value' => $d]); } DB::commit(); } catch (\Exception $exception) { DB::rollBack(); exception($exception); } } }