优化扩展功能

This commit is contained in:
2020-04-04 21:53:38 +08:00
parent 98419ca360
commit a8619c61fb
11 changed files with 214 additions and 28 deletions

View File

@@ -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';
}

View File

@@ -17,6 +17,11 @@ use app\model\Hooks;
*/
class Addons extends Base {
public function initialize() {
parent::initialize();
$this->getAddonsMenu();
}
/**
* @title 插件列表
*/

View File

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,63 @@
<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
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(){
}
}

View File

View File

View File

@@ -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();