更新
This commit is contained in:
@@ -63,4 +63,19 @@ function get_client_ip($type = 0, $adv = false) {
|
||||
|
||||
function avatar($uid, $size = 'middle') {
|
||||
return request()->root(true) . '/static/common/images/default_avatar_' . $size . '.jpg';
|
||||
}
|
||||
|
||||
// 分析枚举类型配置值 格式 a:名称1,b:名称2
|
||||
function parse_config_attr($string) {
|
||||
$array = preg_split('/[,;\r\n]+/', trim($string, ",;\r\n"));
|
||||
if (strpos($string, ':')) {
|
||||
$value = array();
|
||||
foreach ($array as $val) {
|
||||
list($k, $v) = explode(':', $val);
|
||||
$value[$k] = $v;
|
||||
}
|
||||
} else {
|
||||
$value = $array;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\Menu;
|
||||
use think\facade\View;
|
||||
|
||||
/**
|
||||
* @title 后端公共模块
|
||||
@@ -73,9 +74,8 @@ class Admin extends Base {
|
||||
}
|
||||
//菜单设置
|
||||
$this->getMenu();
|
||||
// $this->setMeta();
|
||||
// $this->data['__menu__'] = ['main' => [], 'child' => []];
|
||||
$this->data['meta_title'] = $this->getCurrentTitle();
|
||||
|
||||
View::assign('meta_title', $this->getCurrentTitle());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ class Admin extends Base {
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->data['__menu__'] = $menu;
|
||||
View::assign('__menu__', $menu);
|
||||
}
|
||||
|
||||
protected function getContentMenu() {
|
||||
|
||||
@@ -11,7 +11,9 @@ namespace app\controller;
|
||||
use think\App;
|
||||
use think\exception\ValidateException;
|
||||
use think\facade\View;
|
||||
use think\facade\Cache;
|
||||
use think\Validate;
|
||||
use app\model\Config;
|
||||
|
||||
class Base {
|
||||
|
||||
@@ -62,6 +64,12 @@ class Base {
|
||||
$this->app = $app;
|
||||
$this->request = $this->app->request;
|
||||
|
||||
$config = Cache::get('system_config_data');
|
||||
if (!$config) {
|
||||
$config = Config::getConfigList($this->request);
|
||||
Cache::set('system_config_data', $config);
|
||||
}
|
||||
View::assign('config', $config);
|
||||
// 控制器初始化
|
||||
$this->initialize();
|
||||
}
|
||||
|
||||
@@ -7,11 +7,15 @@
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller;
|
||||
use app\common\controller\Admin;
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\Category as CategoryM;
|
||||
use app\model\Attribute;
|
||||
use app\model\Module;
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
* @title 分类管理
|
||||
* @title 栏目管理
|
||||
* @description 分类管理
|
||||
*/
|
||||
class Category extends Admin {
|
||||
@@ -22,26 +26,34 @@ class Category extends Admin {
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 分类列表
|
||||
* @title 栏目列表
|
||||
*/
|
||||
public function index($model_id = '') {
|
||||
$map = array('status' => array('gt', -1));
|
||||
if ($model_id) {
|
||||
$map['model_id'] = $model_id;
|
||||
public function index(CategoryM $category, Attribute $attr, Module $medule) {
|
||||
$param = $this->request->param();
|
||||
$map = [];
|
||||
|
||||
$map[] = ['status', '>', -1];
|
||||
if (isset($param['model_id']) && $param['model_id']) {
|
||||
$map[] = ['model_id', '=', $model_id];
|
||||
}
|
||||
$list = db('Category')->where($map)->order('sort asc,id asc')->column('*', 'id');
|
||||
$list = $category->where($map)->order('sort asc,id asc')->select();
|
||||
|
||||
if (!empty($list)) {
|
||||
$tree = new \com\Tree();
|
||||
$list = $tree->toFormatTree($list);
|
||||
$tree = new \sent\tree\Tree();
|
||||
$list = $tree->toFormatTree($list->toArray());
|
||||
}
|
||||
$subsql = db('Attribute')->where('name', 'category_id')->fetchSql(true)->column('model_id');
|
||||
$model_list = model('Model')->where('id IN ('. $subsql.')')->select();
|
||||
// $subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id');
|
||||
// $model_list = $medule->where('id IN ('. $subsql.')')->select();
|
||||
|
||||
$this->assign('tree', $list);
|
||||
$this->assign('model_list', $model_list);
|
||||
$this->assign('model_id', $model_id);
|
||||
$this->setMeta('栏目列表');
|
||||
$this->data = [
|
||||
'tree' => $list,
|
||||
'module_id' => isset($param['module_id']) ? $param['module_id'] : 0,
|
||||
'model_list' => []
|
||||
];
|
||||
// $this->assign('tree', $list);
|
||||
// $this->assign('model_list', $model_list);
|
||||
// $this->assign('model_id', $model_id);
|
||||
// $this->setMeta('栏目列表');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,10 @@ class Config extends Admin {
|
||||
* @title 配置管理
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function index() {
|
||||
public function index(ConfigM $config) {
|
||||
$param = $this->request->param();
|
||||
|
||||
|
||||
$group = input('group', 0, 'trim');
|
||||
$name = input('name', '', 'trim');
|
||||
/* 查询条件初始化 */
|
||||
@@ -38,13 +41,13 @@ class Config extends Admin {
|
||||
$map['name'] = array('like', '%' . $name . '%');
|
||||
}
|
||||
|
||||
$list = $this->model->where($map)->order('id desc')->paginate(25, false, array(
|
||||
$list = $config->where($map)->order('id desc')->paginate(25, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
// 记录当前列表页的cookie
|
||||
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'group' => config('config_group_list'),
|
||||
'config_type' => config('config_config_list'),
|
||||
'page' => $list->render(),
|
||||
@@ -52,32 +55,28 @@ class Config extends Admin {
|
||||
'list' => $list,
|
||||
);
|
||||
|
||||
$this->assign($data);
|
||||
$this->setMeta('配置管理');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 信息配置
|
||||
*/
|
||||
public function group($id = 1) {
|
||||
public function group(ConfigM $config, $id = 1) {
|
||||
if ($this->request->isPost()) {
|
||||
$config = $this->request->post('config/a');
|
||||
$model = model('Config');
|
||||
foreach ($config as $key => $value) {
|
||||
$model->where(array('name' => $key))->setField('value', $value);
|
||||
$data = $this->request->post();
|
||||
|
||||
foreach ($data['config'] as $key => $value) {
|
||||
ConfigM::update(['value' => $value], ['name' => $key]);
|
||||
}
|
||||
//清除db_config_data缓存
|
||||
cache('db_config_data', null);
|
||||
cache('system_config_data', null);
|
||||
return $this->success("更新成功!");
|
||||
} else {
|
||||
$type = config('config_group_list');
|
||||
$list = (new ConfigM())->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
|
||||
$list = $config->where(array('status' => 1, 'group' => $id))->field('id,name,title,extra,value,remark,type')->order('sort')->select();
|
||||
if ($list) {
|
||||
$this->data['list'] = $list;
|
||||
}
|
||||
// $this->assign('id', $id);
|
||||
// $this->setMeta($type[$id] . '设置');
|
||||
$this->data['id'] = $id;
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
@@ -86,17 +85,14 @@ class Config extends Admin {
|
||||
* @title 新增配置
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function add() {
|
||||
public function add(ConfigM $config) {
|
||||
if ($this->request->isPost()) {
|
||||
$config = model('Config');
|
||||
$data = $this->request->post();
|
||||
if ($data) {
|
||||
$id = $config->validate(true)->save($data);
|
||||
$id = $config->save($data);
|
||||
if ($id) {
|
||||
cache('db_config_data', null);
|
||||
//记录行为
|
||||
action_log('update_config', 'config', $id, session('user_auth.uid'));
|
||||
return $this->success('新增成功', url('index'));
|
||||
cache('system_config_data', null);
|
||||
return $this->success('新增成功', url('/admin/config/index'));
|
||||
} else {
|
||||
return $this->error('新增失败');
|
||||
}
|
||||
@@ -104,8 +100,7 @@ class Config extends Admin {
|
||||
return $this->error($config->getError());
|
||||
}
|
||||
} else {
|
||||
$this->setMeta('新增配置');
|
||||
$this->assign('info', null);
|
||||
$this->data['info'] = [];
|
||||
return $this->fetch('edit');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use sent\tree\Tree;
|
||||
use app\controller\Admin;
|
||||
use app\model\Menu as MenuM;
|
||||
|
||||
/**
|
||||
* @title 菜单管理
|
||||
@@ -22,21 +24,19 @@ class Menu extends Admin {
|
||||
/**
|
||||
* @title 菜单列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index(MenuM $menu) {
|
||||
$map = array();
|
||||
$title = trim(input('get.title'));
|
||||
$list = db("Menu")->where($map)->field(true)->order('sort asc,id asc')->column('*', 'id');
|
||||
int_to_string($list, array('hide' => array(1 => '是', 0 => '否'), 'is_dev' => array(1 => '是', 0 => '否')));
|
||||
$list = $menu->where($map)->field(true)->order('sort asc,id asc')->select();
|
||||
// int_to_string($list, array('hide' => array(1 => '是', 0 => '否'), 'is_dev' => array(1 => '是', 0 => '否')));
|
||||
|
||||
if (!empty($list)) {
|
||||
$tree = new \com\Tree();
|
||||
$list = $tree->toFormatTree($list);
|
||||
$list = (new Tree())->toFormatTree($list->append(['is_dev_text', 'hide_text'])->toArray());
|
||||
}
|
||||
// 记录当前列表页的cookie
|
||||
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
// Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
|
||||
$this->setMeta('菜单列表');
|
||||
$this->assign('list', $list);
|
||||
$this->data['list'] = $list;
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -21,20 +21,7 @@ class User extends Admin {
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function index(Member $member) {
|
||||
$param = $this->request->param();
|
||||
$map[] = ['status', '>=', 0];
|
||||
if (isset($param['nickname']) && $param['nickname']) {
|
||||
$map['nickname'] = array('like', '%' . $param['nickname'] . '%');
|
||||
}
|
||||
if (isset($param['username']) && $param['username']) {
|
||||
$map['username'] = array('like', '%' . (string) $param['nickname'] . '%');
|
||||
}
|
||||
|
||||
$order = "uid desc";
|
||||
$list = $member->where($map)->order($order)
|
||||
->paginate(15, false, array(
|
||||
'param' => $param,
|
||||
));
|
||||
$list = $member->getUserList($this->request);
|
||||
|
||||
$this->data['list'] = $list;
|
||||
$this->data['page'] = $list->render();
|
||||
@@ -46,24 +33,18 @@ class User extends Admin {
|
||||
* @title 添加用户
|
||||
* @author colin <molong@tensent.cn>
|
||||
*/
|
||||
public function add() {
|
||||
$model = \think\Loader::model('Member');
|
||||
public function add(Member $member) {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->param();
|
||||
//创建注册用户
|
||||
$result = $model->register($data['username'], $data['password'], $data['repassword'], $data['email'], false);
|
||||
$result = $member->register($data['username'], $data['password'], $data['repassword'], $data['email'], false);
|
||||
if ($result) {
|
||||
return $this->success('用户添加成功!', url('admin/user/index'));
|
||||
} else {
|
||||
return $this->error($model->getError());
|
||||
}
|
||||
} else {
|
||||
$data = array(
|
||||
'keyList' => $model->addfield,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("添加用户");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace app\model;
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Category {
|
||||
class Category extends \think\Model{
|
||||
|
||||
protected $name = "Category";
|
||||
protected $auto = array('update_time', 'status' => 1);
|
||||
|
||||
@@ -149,8 +149,8 @@ class Member extends Model {
|
||||
}];
|
||||
}
|
||||
|
||||
$list = self::with(['depart', 'role'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig);
|
||||
return $list->append(['avatar', 'status_text'])->toArray();
|
||||
$list = self::with(['role'])->field('uid,username,nickname,status,email,mobile,department,reg_time')->where($map)->order($order)->paginate($request->pageConfig);
|
||||
return $list->append(['avatar', 'status_text']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,9 +19,19 @@ class Menu extends \think\Model {
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected function getIsDevTextAttr($value, $data){
|
||||
$is_dev = [0 => '否', 1 => '是'];
|
||||
return isset($is_dev[$data['is_dev']]) ? $is_dev[$data['is_dev']] : '是';
|
||||
}
|
||||
|
||||
protected function getHideTextAttr($value, $data){
|
||||
$is_dev = [0 => '否', 1 => '是'];
|
||||
return isset($is_dev[$data['is_dev']]) ? $is_dev[$data['is_dev']] : '是';
|
||||
}
|
||||
|
||||
public function getAuthNodes($type = 'admin') {
|
||||
$map['type'] = $type;
|
||||
$rows = $this->db()->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
$rows = $this->field('id,pid,group,title,url')->where($map)->order('id asc')->select();
|
||||
foreach ($rows as $key => $value) {
|
||||
$data[$value['id']] = $value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user