From d14659aa75ff0300118c20531e505f24a54da679 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 15 Dec 2025 17:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ConfigController.php | 65 ++++++++++++++++ app/common/controller/ConfigController.php | 90 ++++++++++++++++++++++ app/common/logic/ConfigLogic.php | 17 ++++ app/common/model/Config.php | 49 ++++++++++++ app/common/service/ConfigService.php | 78 +++++++++++++++++++ config/route.php | 15 ++++ 6 files changed, 314 insertions(+) create mode 100644 app/admin/controller/ConfigController.php create mode 100644 app/common/controller/ConfigController.php create mode 100644 app/common/logic/ConfigLogic.php create mode 100644 app/common/model/Config.php create mode 100644 app/common/service/ConfigService.php diff --git a/app/admin/controller/ConfigController.php b/app/admin/controller/ConfigController.php new file mode 100644 index 0000000..ff0e4cc --- /dev/null +++ b/app/admin/controller/ConfigController.php @@ -0,0 +1,65 @@ +service = new ConfigService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (!empty($data['value'])){ + $value = explode(',', $data['value']); + $ossservice = new OssService(); + foreach ($value as $k => $v){ + $value[$k] = $ossservice->generatePrivateUrl($v); + } + $data['value_pull'] = implode(',', $value); + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (!empty($data['value'])){ + $value = explode(',', $data['value']); + $ossservice = new OssService(); + foreach ($value as $k => $v){ + $value[$k] = $ossservice->generatePrivateUrl($v); + } + $data['value_pull'] = implode(',', $value); + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/common/controller/ConfigController.php b/app/common/controller/ConfigController.php new file mode 100644 index 0000000..b492031 --- /dev/null +++ b/app/common/controller/ConfigController.php @@ -0,0 +1,90 @@ +service = new ConfigService(); + } + + /** + * 获取详情 + * + * @param Request $request 请求对象 + * @param int|string $id 资源 ID + * @return mixed 返回资源详情数据 + */ + public function find(Request $request) + { + try { + $raw = $this->service->serviceFind($request); + $data = $this->transformData($raw, method_exists($this, 'showFormat') + ? [$this, 'showFormat'] + : null); + return $this->success($data); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (!empty($data['value'])){ + $value = explode(',', $data['value']); + $ossservice = new OssService(); + foreach ($value as $k => $v){ + $value[$k] = $ossservice->generatePrivateUrl($v); + } + $data['value_pull'] = implode(',', $value); + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (!empty($data['value'])){ + $value = explode(',', $data['value']); + $ossservice = new OssService(); + foreach ($value as $k => $v){ + $value[$k] = $ossservice->generatePrivateUrl($v); + } + $data['value_pull'] = implode(',', $value); + } + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + return $data; + } +} \ No newline at end of file diff --git a/app/common/logic/ConfigLogic.php b/app/common/logic/ConfigLogic.php new file mode 100644 index 0000000..13a67fb --- /dev/null +++ b/app/common/logic/ConfigLogic.php @@ -0,0 +1,17 @@ +validator; + } + /** + * 构造 CrudUtil 查询配置 + */ + protected function buildQueryConfig(Request $request, string $scene = 'default'): array + { + $p = $request->all(); + + $config = []; + $config['model'] = $this->modelClass; + switch ($scene) { + case 'default': + $config['where']['status'] = 1; + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'index': + $config['order']['sort'] = 'desc'; + $config['order']['id'] = 'desc'; + break; + case 'show': + $config['where']['id'] = $p['id']; + $config['where']['status'] = 1; + break; + case 'find': + $config['where']['code'] = $p['code']; + break; + case 'store': + break; + case 'update': + $config['where']['id'] = $p['id']; + break; + case 'destroy': + $config['where']['id'] = $p['id']; + break; + } + + return $config; + } + + /** 查看单条 */ + public function serviceFind(Request $request, string $scene = 'find') + { + $config = $this->buildQueryConfig($request, $scene); + $item = $this->logicShow($config); + return $this->postProcess(ucfirst($scene), $item); + } +} \ No newline at end of file diff --git a/config/route.php b/config/route.php index 169e8cb..27f717d 100644 --- a/config/route.php +++ b/config/route.php @@ -112,6 +112,12 @@ Route::group('/common', function () { Route::any('/list', [app\common\controller\BarrageController::class, 'index']); Route::any('/store', [app\common\controller\BarrageController::class, 'store']); }); + + // 设置 + Route::group('/config', function () { + Route::any('/show', [app\common\controller\ConfigController::class, 'show']); + Route::any('/find', [app\common\controller\ConfigController::class, 'find']); + }); }); @@ -254,6 +260,15 @@ Route::group('/admin', function () { Route::any('/update', [app\admin\controller\BarrageController::class, 'update']); Route::any('/destroy', [app\admin\controller\BarrageController::class, 'destroy']); }); + + // 设置 + Route::group('/config', function () { + Route::any('/list', [app\admin\controller\ConfigController::class, 'index']); + Route::any('/show', [app\admin\controller\ConfigController::class, 'show']); + Route::any('/store', [app\admin\controller\ConfigController::class, 'store']); + Route::any('/update', [app\admin\controller\ConfigController::class, 'update']); + Route::any('/destroy', [app\admin\controller\ConfigController::class, 'destroy']); + }); });