From 9a5e7010b1e586e4bfea4dd9db82f2460c28559e Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Fri, 4 Sep 2020 16:21:18 +0800 Subject: [PATCH] update --- catch/system/controller/DataDictionary.php | 2 +- catch/system/model/Config.php | 44 ++++++++++++++++++++++ catch/system/route.php | 4 +- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/catch/system/controller/DataDictionary.php b/catch/system/controller/DataDictionary.php index 0006229..ca2b463 100644 --- a/catch/system/controller/DataDictionary.php +++ b/catch/system/controller/DataDictionary.php @@ -42,7 +42,7 @@ class DataDictionary extends CatchController $tables = $tables->where('engine', $engine)->values(); } - return CatchResponse::paginate(Paginator::make($tables->toArray(), $request->get('limit') ?? 10, $request->get('page') ?? 1, $tables->count(), false, [])); + return CatchResponse::paginate(Paginator::make(array_slice($tables->toArray(), ($request->get('page') ?? 1) - 1,$request->get('limit') ?? 10), $request->get('limit') ?? 10, $request->get('page') ?? 1, $tables->count(), false, [])); } /** diff --git a/catch/system/model/Config.php b/catch/system/model/Config.php index 07135c9..9489066 100644 --- a/catch/system/model/Config.php +++ b/catch/system/model/Config.php @@ -2,6 +2,7 @@ namespace catchAdmin\system\model; use catcher\base\CatchModel; +use catcher\exceptions\FailedException; use thans\jwt\exception\UserNotDefinedException; use think\Model; @@ -55,6 +56,47 @@ class Config extends CatchModel return true; } + $parent = $data['parent'] ?? false; + if (!$parent) { + throw new FailedException('父配置丢失'); + } + unset($data['parent']); + + $parentConfig = $this->where('key', $parent)->find(); + $config = []; + foreach ($data as $key => $item) { + foreach ($item as $k => $value) { + if ($value) { + $config[$key . '.' .$k] = [ + 'pid' => $parentConfig['id'], + 'key' => $key . '.' . $k, + 'value' => $value, + 'created_at' => time(), + 'updated_at' => time(), + ]; + } + } + } + + $this->where('pid', $parentConfig->id) + ->select() + ->each(function ($item) use (&$config){ + if (isset($config[$item['key']])) { + if ($config[$item['key']]['value'] != $item->value) { + $item['value'] = $config[$item['key']]['value']; + $item->save(); + } + unset($config[$item['key']]); + } + }); + + if (count($config)) { + return $this->insertAll($config); + } + + return true; + + // 子配置 if ($data['pid'] ?? false) { $config = \json_decode($data['config'], true); @@ -67,6 +109,7 @@ class Config extends CatchModel 'k' => 'v' ]*/ + /** foreach ($config as $key => $value) { if (empty($value)) { continue; @@ -136,6 +179,7 @@ class Config extends CatchModel } } } +*/ return true; } diff --git a/catch/system/route.php b/catch/system/route.php index 3d8ef00..3c71b86 100644 --- a/catch/system/route.php +++ b/catch/system/route.php @@ -5,8 +5,8 @@ $router->group(function () use ($router) { $router->delete('loginLog/empty', '\catchAdmin\system\controller\LoginLog@empty'); // 操作日志 $router->get('log/operate', '\catchAdmin\system\controller\OperateLog@list'); - $router->delete('operateLog/empty', '\catchAdmin\system\controller\OperateLog@empty'); - $router->delete('operateLog/delete', '\catchAdmin\system\controller\OperateLog@delete'); + // $router->delete('empty/log/operate', '\catchAdmin\system\controller\OperateLog@empty'); + $router->delete('log/operate/', '\catchAdmin\system\controller\OperateLog@delete'); // 数据字典 $router->get('tables', '\catchAdmin\system\controller\DataDictionary@tables');