diff --git a/app/common.php b/app/common.php index 9c961d93..4174957d 100755 --- a/app/common.php +++ b/app/common.php @@ -8,6 +8,7 @@ // +---------------------------------------------------------------------- // 应用公共文件 use think\facade\Session; +use app\model\Member; define("SENTCMS_VERSION", '4.x'); @@ -82,6 +83,21 @@ function get_client_ip($type = 0, $adv = false) { return $ip[$type]; } +/** + * 根据用户ID获取用户名 + * @param integer $uid 用户ID + * @return string 用户名 + */ +function get_username($uid = 0) { + static $list; + if (!($uid && is_numeric($uid))) { + //获取当前登录用户名 + return session('userInfo.username'); + } + $name = Member::where('uid', $uid)->value('username'); + return $name; +} + function avatar($uid, $size = 'middle') { return request()->root(true) . '/static/common/images/default_avatar_' . $size . '.jpg'; } diff --git a/app/controller/admin/Addons.php b/app/controller/admin/Addons.php index ba16942c..2f3ae6cc 100644 --- a/app/controller/admin/Addons.php +++ b/app/controller/admin/Addons.php @@ -17,6 +17,11 @@ use app\model\Hooks; */ class Addons extends Base { + public function initialize() { + parent::initialize(); + $this->getAddonsMenu(); + } + /** * @title 插件列表 */ diff --git a/app/controller/admin/Base.php b/app/controller/admin/Base.php index 5205dad0..5db9f8ab 100644 --- a/app/controller/admin/Base.php +++ b/app/controller/admin/Base.php @@ -11,6 +11,7 @@ namespace app\controller\admin; use app\model\Menu; use app\model\Model; use app\model\AuthGroup; +use app\model\Addons; use think\facade\View; use \app\model\Form; use \app\controller\Base as BaseC; @@ -217,25 +218,22 @@ class Base extends BaseC { } protected function getAddonsMenu() { - $model = db('Addons'); $list = array(); - $map = array( - 'isinstall' => array('gt', 0), - 'status' => array('gt', 0), - ); - $list = $model->field("name,id,title,'' as 'style'")->where($map)->select(); + $map[] = ['isinstall', '>', 0]; + $map[] = ['status', '>', 0]; + $list = Addons::where($map)->field("name,id,title,'' as 'style'")->select(); $menu = array(); foreach ($list as $key => $value) { $class = "\\addons\\" . strtolower($value['name']) . "\\controller\\Admin"; - if (is_file(ROOT_PATH . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) { + if (is_file($this->app->getRootPath() . '/addons/' . strtolower($value['name']) . "/controller/Admin.php")) { $action = get_class_methods($class); - $value['url'] = "admin/addons/execute?mc=" . strtolower($value['name']) . "&ac=" . $action[0]; + $value['url'] = "/addons/".$value['name']."/admin/" . $action[0]; $menu[$key] = $value; } } if (!empty($menu)) { - $this->assign('extend_menu', array('管理插件' => $menu)); + View::assign('extend_menu', array('管理插件' => $menu)); } } diff --git a/app/controller/admin/Client.php b/app/controller/admin/Client.php index 16824bc4..9eb52abe 100644 --- a/app/controller/admin/Client.php +++ b/app/controller/admin/Client.php @@ -101,4 +101,63 @@ class Client extends Base { return $this->error('删除失败!'); } } + + public function api(){ + $list = []; + $path = app()->getAppPath() . 'controller/api'; + + $classname = $this->scanFile($path); + foreach ($classname as $value) { + if($value == 'Base'){ + continue; + } + $class = "app\\controller\\api\\" . $value; + if (class_exists($class)) { + $reflection = new \ReflectionClass($class); + $group_doc = $this->Parser($reflection->getDocComment()); + $method = $reflection->getMethods(\ReflectionMethod::IS_FINAL | \ReflectionMethod::IS_PUBLIC); + $group_doc['name'] = $value; + foreach ($method as $key => $v) { + if (!in_array($v->name, ['__construct'])) { + $title_doc = $this->Parser($v->getDocComment()); + if (isset($title_doc['title']) && $title_doc['title']) { + $list[] = array( + 'url' => 'api/' . strtolower($value) . '/' . strtolower($v->name), + 'name' => 'api/' . strtolower($value) . '/' . strtolower($v->name), + 'method' => isset($title_doc['method']) ? strtoupper($title_doc['method']) : 'GET', + 'title' => trim($title_doc['title']), + 'group' => $group_doc['title'], + 'status' => 1, + ); + } + } + } + } + } + + $this->data = [ + 'list' => $list + ]; + return $this->fetch(); + } + + protected function scanFile($path) { + $result = array(); + $files = scandir($path); + foreach ($files as $file) { + if ($file != '.' && $file != '..') { + if (is_dir($path . '/' . $file)) { + $this->scanFile($path . '/' . $file); + } else { + $result[] = substr(basename($file), 0, -4); + } + } + } + return $result; + } + + protected function Parser($text) { + $doc = new \doc\Doc(); + return $doc->parse($text); + } } \ No newline at end of file diff --git a/app/controller/api/Content.php b/app/controller/api/Content.php new file mode 100644 index 00000000..06080fcc --- /dev/null +++ b/app/controller/api/Content.php @@ -0,0 +1,63 @@ + +// +---------------------------------------------------------------------- +namespace app\controller\api; + +use app\model\Category; + +/** + * @title 内容管理 + */ +class Content extends Base { + + /** + * @title 内容列表 + * @method GET + * @param Category $category [description] + * @return [json] + */ + public function lists(Category $category){ + + } + + /** + * @title 内容详情 + * @method GET + * @return [json] + */ + public function detail(){ + + } + + /** + * @title 添加内容 + * @method POST + * @return [json] + */ + public function add(){ + + } + + /** + * @title 修改内容 + * @method POST + * @return [json] + */ + public function edit(){ + + } + + /** + * @title 删除内容 + * @method POST + * @return [json] + */ + public function delete(){ + + } +} \ No newline at end of file diff --git a/app/http/form/template/attach.html b/app/http/form/template/attach.html new file mode 100644 index 00000000..e69de29b diff --git a/app/http/form/template/tags.html b/app/http/form/template/tags.html new file mode 100644 index 00000000..e69de29b diff --git a/app/model/Attribute.php b/app/model/Attribute.php index 428f4371..50878df6 100644 --- a/app/model/Attribute.php +++ b/app/model/Attribute.php @@ -77,7 +77,7 @@ class Attribute extends \think\Model { } protected function getTypeTextAttr($value, $data) { - $config_type_list = Config::get('config.config_type_list'); + $config_type_list = Config::get('config.config_type_list') ?? []; $type = []; foreach ($config_type_list as $key => $value) { $type[$value['key']] = $value['label']; @@ -111,6 +111,9 @@ class Attribute extends \think\Model { $map[] = ['model_id', '=', $data['model_id']]; } $row = Db::name($extra[0])->where($map)->select()->toArray(); + if(empty($row)){ + return []; + } if ($extra[1] == 'tree') { $row = (new Tree())->toFormatTree($row); foreach ($row as $val) { @@ -146,7 +149,7 @@ class Attribute extends \think\Model { $map[] = ['is_show', 'IN', [1, 3]]; } - $row = self::where($map) + $row = self::where($map)->order('sort asc, id desc') ->select() ->append(['option']) ->toArray(); diff --git a/route/app.php b/route/app.php index 4cbc1a10..fef2ea3e 100755 --- a/route/app.php +++ b/route/app.php @@ -14,19 +14,19 @@ use app\model\Model; $model = Model::where('status', '>', 0)->field(['id', 'name'])->select()->toArray(); foreach ($model as $value) { - Route::rule('/admin/' . $value['name'] . '/:function', 'Admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); - Route::rule('/front/' . $value['name'] . '/:function', 'Front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); - Route::rule('/user/' . $value['name'] . '/:function', 'User.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); + Route::rule('/admin/' . $value['name'] . '/:function', 'admin.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); + Route::rule('/front/' . $value['name'] . '/:function', 'front.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); + Route::rule('/user/' . $value['name'] . '/:function', 'user.content/:function')->append(['name'=>$value['name'], 'model_id' => $value['id']]); } -Route::rule('/', 'Front.Index/index'); -Route::rule('search', 'Front.Content/search'); -Route::rule('lists', 'Front.Content/lists'); -Route::rule('detail-:id', 'Front.Content/detail'); -Route::rule('category', 'Front.Content/category'); -Route::rule('topic-:id', 'Front.Content/topic'); -Route::rule('form/:id/:name', 'Front.Form/index'); -Route::rule('front/:controller/:function', 'Front.:controller/:function'); +Route::rule('/', 'front.Index/index'); +Route::rule('search', 'front.Content/search'); +Route::rule('lists', 'front.Content/lists'); +Route::rule('detail-:id', 'front.Content/detail'); +Route::rule('category', 'front.Content/category'); +Route::rule('topic-:id', 'front.Content/topic'); +Route::rule('form/:id/:name', 'front.Form/index'); +Route::rule('front/:controller/:function', 'front.:controller/:function'); Route::group('admin', function () { Route::rule('/', 'admin.Index/index'); @@ -37,12 +37,12 @@ Route::group('admin', function () { }); Route::group('user', function () { - Route::rule('/', 'User.Index/index'); - Route::rule('login', 'User.Index/login'); - Route::rule('logout', 'User.Index/logout'); - Route::rule('register', 'User.Index/register'); + Route::rule('/', 'user.Index/index'); + Route::rule('login', 'user.Index/login'); + Route::rule('logout', 'user.Index/logout'); + Route::rule('register', 'user.Index/register'); Route::rule('upload/:function', 'Upload/:function'); - Route::rule(':controller/:function', 'User.:controller/:function'); + Route::rule(':controller/:function', 'user.:controller/:function'); }); Route::group('api', function () { diff --git a/view/admin/channel/index.html b/view/admin/channel/index.html index 606d0405..de33ef86 100644 --- a/view/admin/channel/index.html +++ b/view/admin/channel/index.html @@ -45,7 +45,7 @@ {$list['id']} - {$list['level_show']} + {$list['level_show']|raw} {$list['title']} diff --git a/view/admin/client/api.html b/view/admin/client/api.html new file mode 100644 index 00000000..38209998 --- /dev/null +++ b/view/admin/client/api.html @@ -0,0 +1,42 @@ +{extend name="admin/public/base"/} +{block name="body"} +
+
+
+

{$meta_title}

+
+
+ 新 增 + +
+
+
+
+ + + + + + + + + + + + + {volist name="list" id="item"} + + + + + + + + + {/volist} + +
ID分组名称接口地址方法类型状态
{$key}{$item['group']}{$item['title']}{$item['url']}{$item['method']}{$item['status']}
+
+
+
+{/block} \ No newline at end of file