作者 王晓刚

安装完毕

要显示太多修改。

为保证性能只显示 24 of 24+ 个文件。

<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\annotation;
use mindplay\annotations\Annotation;
/**
* Specifies validation of a string, requiring a minimum and/or maximum length.
*
* @usage('method'=>true, 'inherited'=>true, 'multiple'=>false)
*/
class AdminMenuAnnotation extends Annotation
{
public $remark = '';
public $icon = '';
public $name = '';
public $param = '';
public $parent = '';
public $display = false;
public $order = 10000;
public $hasView = true;
/**
* Initialize the annotation.
* @param array $properties
*/
public function initAnnotation(array $properties)
{
parent::initAnnotation($properties);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\annotation;
use mindplay\annotations\AnnotationException;
use mindplay\annotations\Annotation;
/**
* Specifies validation of a string, requiring a minimum and/or maximum length.
*
* @usage('class'=>true, 'inherited'=>true, 'multiple'=>true)
*/
class AdminMenuRootAnnotation extends Annotation
{
/**
* @var int|null Minimum string length (or null, if no minimum)
*/
public $remark = '';
/**
* @var int|null Maximum string length (or null, if no maximum)
*/
public $icon = '';
/**
* @var int|null Minimum string length (or null, if no minimum)
*/
public $name = '';
public $action = '';
public $param = '';
public $parent = '';
public $display = false;
public $order = 10000;
/**
* Initialize the annotation.
* @param array $properties
*/
public function initAnnotation(array $properties)
{
parent::initAnnotation($properties);
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\api;
use app\admin\model\NavModel;
class NavApi
{
// 分类列表 用于模板设计
public function index($param = [])
{
$navModel = new NavModel();
$where = [];
if (!empty($param['keyword'])) {
$where['name'] = ['like', "%{$param['keyword']}%"];
}
return $navModel->where($where)->select();
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\api;
use app\admin\model\NavMenuModel;
class NavMenuApi
{
// 分类列表 用于模板设计
public function index($param = [])
{
$navMenuModel = new NavMenuModel();
$where = [];
if (!empty($param['keyword'])) {
$where['name'] = ['like', "%{$param['keyword']}%"];
}
if (!empty($param['id'])) {
$where['nav_id'] = $param['id'];
}
return $navMenuModel->where($where)->select();
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\api;
use app\admin\model\SlideModel;
class SlideApi
{
/**
* 幻灯片列表 用于模板设计
* @param array $param
* @return false|\PDOStatement|string|\think\Collection
*/
public function index($param = [])
{
$slideModel = new SlideModel();
$where = [];
if (!empty($param['keyword'])) {
$where['name'] = ['like', "%{$param['keyword']}%"];
}
//返回的数据必须是数据集或数组,item里必须包括id,name,如果想表示层级关系请加上 parent_id
return $slideModel->where($where)->select();
}
}
\ No newline at end of file
... ...
<?php
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
class BakController extends AdminBaseController {
public function index(){
$type = $this->request->param('tp');
$name = $this->request->param('name');
$sql=new \org\Baksql(config('database'));
switch ($type)
{
case "backup": //备份
$ret=$sql->backup();
if($ret['code']=1){
$this->success($ret['msg']);
}else{
$this->error($ret['msg']);
}
break;
case "dowonload": //下载
$sql->downloadFile($name);
break;
case "restore": //还原
$ret= $sql->restore($name);
if($ret['code']=1){
$this->success($ret['msg']);
}else{
$this->error($ret['msg']);
}
break;
case "del": //删除
$ret= $sql->delfilename($name);
if($ret['code']=1){
$this->success($ret['msg']);
}else{
$this->error($ret['msg']);
}
break;
default: //获取备份文件列表
return $this->fetch("index",["list"=>$sql->get_filelist()]);
}
}
}
?>
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class DialogController extends AdminBaseController
{
public function _initialize()
{
}
public function map()
{
$location = $this->request->param('location');
$location = explode(',', $location);
$lng = empty($location[0]) ? 116.424966 : $location[0];
$lat = empty($location[1]) ? 39.907851 : $location[1];
$this->assign(['lng' => $lng, 'lat' => $lat]);
return $this->fetch();
}
public function map2()
{
$location = $this->request->param('location');
$location = explode(',', $location);
$lng = empty($location[0]) ? 116.424966 : $location[0];
$lat = empty($location[1]) ? 39.907851 : $location[1];
$this->assign(['lng' => $lng, 'lat' => $lat]);
return $this->fetch();
}
public function getShopHtml(){
$data = $this->request->param();
$where=[];
if (!empty($data['category_id'])) {
$where['category_id']=$data['category_id'];
}
$list=Db::name('shop')->where($where)->select()->toArray();
if(!empty($list)){
$this->success('','',$list);
}else{
$this->error('该分类下没有店铺');
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\admin\model\HookModel;
use app\admin\model\PluginModel;
use app\admin\model\HookPluginModel;
use think\Db;
/**
* Class HookController 钩子管理控制器
* @package app\admin\controller
*/
class HookController extends AdminBaseController
{
/**
* 钩子管理
* @adminMenu(
* 'name' => '钩子管理',
* 'parent' => 'admin/Plugin/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '钩子管理',
* 'param' => ''
* )
*/
public function index()
{
$hookModel = new HookModel();
$hooks = $hookModel->select();
$this->assign('hooks', $hooks);
return $this->fetch();
}
/**
* 钩子插件管理
* @adminMenu(
* 'name' => '钩子插件管理',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '钩子插件管理',
* 'param' => ''
* )
*/
public function plugins()
{
$hook = $this->request->param('hook');
$pluginModel = new PluginModel();
$plugins = $pluginModel->field('a.*,b.hook,b.plugin,b.list_order,b.status as hook_plugin_status,b.id as hook_plugin_id')->alias('a')->join('__HOOK_PLUGIN__ b', 'a.name = b.plugin')->where('b.hook', $hook)->select();
$this->assign('plugins', $plugins);
return $this->fetch();
}
/**
* 钩子插件排序
* @adminMenu(
* 'name' => '钩子插件排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '钩子插件排序',
* 'param' => ''
* )
*/
public function pluginListOrder()
{
$hookPluginModel = new HookPluginModel();
parent::listOrders($hookPluginModel);
$this->success("排序更新成功!");
}
/**
* 同步钩子
* @adminMenu(
* 'name' => '同步钩子',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '同步钩子',
* 'param' => ''
* )
*/
public function sync()
{
$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
foreach ($apps as $app) {
$hookConfigFile = APP_PATH . $app . '/hooks.php';
if (file_exists($hookConfigFile)) {
$hooksInFile = include $hookConfigFile;
foreach ($hooksInFile as $hookName => $hook) {
$hook['type'] = empty($hook['type']) ? 2 : $hook['type'];
if (!in_array($hook['type'], [2, 3, 4])) {
$hook['type'] = 2;
}
$findHook = Db::name('hook')->where(['hook' => $hookName])->count();
$hook['app'] = $app;
if ($findHook > 0) {
Db::name('hook')->where(['hook' => $hookName])->strict(false)->field(true)->update($hook);
} else {
$hook['hook'] = $hookName;
Db::name('hook')->insert($hook);
}
}
}
}
return $this->fetch();
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\AdminMenuModel;
class IndexController extends AdminBaseController
{
public function _initialize()
{
$adminSettings = cmf_get_option('admin_settings');
if (empty($adminSettings['admin_password']) || $this->request->path() == $adminSettings['admin_password']) {
$adminId = cmf_get_current_admin_id();
if (empty($adminId)) {
session("__LOGIN_BY_CMF_ADMIN_PW__", 1);//设置后台登录加密码
}
}
parent::_initialize();
}
/**
* 后台首页
*/
public function index()
{
$adminMenuModel = new AdminMenuModel();
$menus = $adminMenuModel->menuTree();
$this->assign("menus", $menus);
$admin = Db::name("user")->where('id', cmf_get_current_admin_id())->find();
$this->assign('admin', $admin);
return $this->fetch();
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\admin\model\LinkModel;
class LinkController extends AdminBaseController
{
protected $targets = ["_blank" => "新标签页打开", "_self" => "本窗口打开"];
/**
* 友情链接管理
* @adminMenu(
* 'name' => '友情链接',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 50,
* 'icon' => '',
* 'remark' => '友情链接管理',
* 'param' => ''
* )
*/
public function index()
{
$linkModel = new LinkModel();
$links = $linkModel->select();
$this->assign('links', $links);
return $this->fetch();
}
/**
* 添加友情链接
* @adminMenu(
* 'name' => '添加友情链接',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加友情链接',
* 'param' => ''
* )
*/
public function add()
{
$this->assign('targets', $this->targets);
return $this->fetch();
}
/**
* 添加友情链接提交保存
* @adminMenu(
* 'name' => '添加友情链接提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加友情链接提交保存',
* 'param' => ''
* )
*/
public function addPost()
{
$data = $this->request->param();
$linkModel = new LinkModel();
$result = $linkModel->validate(true)->allowField(true)->save($data);
if ($result === false) {
$this->error($linkModel->getError());
}
$this->success("添加成功!", url("link/index"));
}
/**
* 编辑友情链接
* @adminMenu(
* 'name' => '编辑友情链接',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑友情链接',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param('id', 0, 'intval');
$linkModel = LinkModel::get($id);
$this->assign('targets', $this->targets);
$this->assign('link', $linkModel);
return $this->fetch();
}
/**
* 编辑友情链接提交保存
* @adminMenu(
* 'name' => '编辑友情链接提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑友情链接提交保存',
* 'param' => ''
* )
*/
public function editPost()
{
$data = $this->request->param();
$linkModel = new LinkModel();
$result = $linkModel->validate(true)->allowField(true)->isUpdate(true)->save($data);
if ($result === false) {
$this->error($linkModel->getError());
}
$this->success("保存成功!", url("link/index"));
}
/**
* 删除友情链接
* @adminMenu(
* 'name' => '删除友情链接',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除友情链接',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id', 0, 'intval');
LinkModel::destroy($id);
$this->success("删除成功!", url("link/index"));
}
/**
* 友情链接排序
* @adminMenu(
* 'name' => '友情链接排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '友情链接排序',
* 'param' => ''
* )
*/
public function listOrder()
{
$linkModel = new LinkModel();
parent::listOrders($linkModel);
$this->success("排序更新成功!");
}
/**
* 友情链接显示隐藏
* @adminMenu(
* 'name' => '友情链接显示隐藏',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '友情链接显示隐藏',
* 'param' => ''
* )
*/
public function toggle()
{
$data = $this->request->param();
$linkModel = new LinkModel();
if (isset($data['ids']) && !empty($data["display"])) {
$ids = $this->request->param('ids/a');
$linkModel->where(['id' => ['in', $ids]])->update(['status' => 1]);
$this->success("更新成功!");
}
if (isset($data['ids']) && !empty($data["hide"])) {
$ids = $this->request->param('ids/a');
$linkModel->where(['id' => ['in', $ids]])->update(['status' => 0]);
$this->success("更新成功!");
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Validate;
class MailerController extends AdminBaseController
{
/**
* 邮箱配置
* @adminMenu(
* 'name' => '邮箱配置',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10,
* 'icon' => '',
* 'remark' => '邮箱配置',
* 'param' => ''
* )
*/
public function index()
{
$emailSetting = cmf_get_option('smtp_setting');
$this->assign($emailSetting);
return $this->fetch();
}
/**
* 邮箱配置
* @adminMenu(
* 'name' => '邮箱配置提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '邮箱配置提交保存',
* 'param' => ''
* )
*/
public function indexPost()
{
$post = array_map('trim', $this->request->param());
if (in_array('', $post) && !empty($post['smtpsecure'])) {
$this->error("不能留空!");
}
cmf_set_option('smtp_setting', $post);
$this->success("保存成功!");
}
/**
* 邮件模板
* @adminMenu(
* 'name' => '邮件模板',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '邮件模板',
* 'param' => ''
* )
*/
public function template()
{
$allowedTemplateKeys = ['verification_code'];
$templateKey = $this->request->param('template_key');
if (empty($templateKey) || !in_array($templateKey, $allowedTemplateKeys)) {
$this->error('非法请求!');
}
$template = cmf_get_option('email_template_' . $templateKey);
$this->assign($template);
return $this->fetch('template_verification_code');
}
/**
* 邮件模板提交
* @adminMenu(
* 'name' => '邮件模板提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '邮件模板提交',
* 'param' => ''
* )
*/
public function templatePost()
{
$allowedTemplateKeys = ['verification_code'];
$templateKey = $this->request->param('template_key');
if (empty($templateKey) || !in_array($templateKey, $allowedTemplateKeys)) {
$this->error('非法请求!');
}
$data = $this->request->param();
unset($data['template_key']);
cmf_set_option('email_template_' . $templateKey, $data);
$this->success("保存成功!");
}
/**
* 邮件发送测试
* @adminMenu(
* 'name' => '邮件发送测试',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '邮件发送测试',
* 'param' => ''
* )
*/
public function test()
{
if ($this->request->isPost()) {
$validate = new Validate([
'to' => 'require|email',
'subject' => 'require',
'content' => 'require',
]);
$validate->message([
'to.require' => '收件箱不能为空!',
'to.email' => '收件箱格式不正确!',
'subject.require' => '标题不能为空!',
'content.require' => '内容不能为空!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$result = cmf_send_email($data['to'], $data['subject'], $data['content']);
if ($result && empty($result['error'])) {
$this->success('发送成功!');
} else {
$this->error('发送失败:' . $result['message']);
}
} else {
return $this->fetch();
}
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use app\admin\model\Menu;
class MainController extends AdminBaseController
{
public function _initialize()
{
parent::_initialize();
}
/**
* 后台欢迎页
*/
public function index()
{
$dashboardWidgets = [];
$widgets = cmf_get_option('admin_dashboard_widgets');
$defaultDashboardWidgets = [
'_SystemCmfHub' => ['name' => 'CmfHub', 'is_system' => 1],
'_SystemMainContributors' => ['name' => 'MainContributors', 'is_system' => 1],
'_SystemContributors' => ['name' => 'Contributors', 'is_system' => 1],
'_SystemCustom1' => ['name' => 'Custom1', 'is_system' => 1],
'_SystemCustom2' => ['name' => 'Custom2', 'is_system' => 1],
'_SystemCustom3' => ['name' => 'Custom3', 'is_system' => 1],
'_SystemCustom4' => ['name' => 'Custom4', 'is_system' => 1],
'_SystemCustom5' => ['name' => 'Custom5', 'is_system' => 1],
];
if (empty($widgets)) {
$dashboardWidgets = $defaultDashboardWidgets;
} else {
foreach ($widgets as $widget) {
if ($widget['is_system']) {
$dashboardWidgets['_System' . $widget['name']] = ['name' => $widget['name'], 'is_system' => 1];
} else {
$dashboardWidgets[$widget['name']] = ['name' => $widget['name'], 'is_system' => 0];
}
}
foreach ($defaultDashboardWidgets as $widgetName => $widget) {
$dashboardWidgets[$widgetName] = $widget;
}
}
$dashboardWidgetPlugins = [];
$hookResults = hook('admin_dashboard');
if (!empty($hookResults)) {
foreach ($hookResults as $hookResult) {
if (isset($hookResult['width']) && isset($hookResult['view']) && isset($hookResult['plugin'])) { //验证插件返回合法性
$dashboardWidgetPlugins[$hookResult['plugin']] = $hookResult;
if (!isset($dashboardWidgets[$hookResult['plugin']])) {
$dashboardWidgets[$hookResult['plugin']] = ['name' => $hookResult['plugin'], 'is_system' => 0];
}
}
}
}
$smtpSetting = cmf_get_option('smtp_setting');
$this->assign('dashboard_widgets', $dashboardWidgets);
$this->assign('dashboard_widget_plugins', $dashboardWidgetPlugins);
$this->assign('has_smtp_setting', empty($smtpSetting) ? false : true);
return $this->fetch();
}
public function dashboardWidget()
{
$dashboardWidgets = [];
$widgets = $this->request->param('widgets/a');
if (!empty($widgets)) {
foreach ($widgets as $widget) {
if ($widget['is_system']) {
array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 1]);
} else {
array_push($dashboardWidgets, ['name' => $widget['name'], 'is_system' => 0]);
}
}
}
cmf_set_option('admin_dashboard_widgets', $dashboardWidgets, true);
$this->success('更新成功!');
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\AdminMenuModel;
use cmf\controller\AdminBaseController;
use think\Db;
use tree\Tree;
use mindplay\annotations\Annotations;
class MenuController extends AdminBaseController
{
/**
* 后台菜单管理
* @adminMenu(
* 'name' => '后台菜单',
* 'parent' => 'admin/Setting/default',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单管理',
* 'param' => ''
* )
*/
public function index()
{
session('admin_menu_index', 'Menu/index');
$result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select()->toArray();
$tree = new Tree();
$tree->icon = ['&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ '];
$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
$newMenus = [];
foreach ($result as $m) {
$newMenus[$m['id']] = $m;
}
foreach ($result as $key => $value) {
$result[$key]['parent_id_node'] = ($value['parent_id']) ? ' class="child-of-node-' . $value['parent_id'] . '"' : '';
$result[$key]['style'] = empty($value['parent_id']) ? '' : 'display:none;';
$result[$key]['str_manage'] = '<a href="' . url("Menu/add", ["parent_id" => $value['id'], "menu_id" => $this->request->param("menu_id")])
. '">' . lang('ADD_SUB_MENU') . '</a> <a href="' . url("Menu/edit", ["id" => $value['id'], "menu_id" => $this->request->param("menu_id")])
. '">' . lang('EDIT') . '</a> <a class="js-ajax-delete" href="' . url("Menu/delete", ["id" => $value['id'], "menu_id" => $this->request->param("menu_id")]) . '">' . lang('DELETE') . '</a> ';
$result[$key]['status'] = $value['status'] ? lang('DISPLAY') : lang('HIDDEN');
if (APP_DEBUG) {
$result[$key]['app'] = $value['app'] . "/" . $value['controller'] . "/" . $value['action'];
}
}
$tree->init($result);
$str = "<tr id='node-\$id' \$parent_id_node style='\$style'>
<td style='padding-left:20px;'><input name='list_orders[\$id]' type='text' size='3' value='\$list_order' class='input input-order'></td>
<td>\$id</td>
<td>\$spacer\$name</td>
<td>\$app</td>
<td>\$status</td>
<td>\$str_manage</td>
</tr>";
$category = $tree->getTree(0, $str);
$this->assign("category", $category);
return $this->fetch();
}
/**
* 后台所有菜单列表
* @adminMenu(
* 'name' => '所有菜单',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台所有菜单列表',
* 'param' => ''
* )
*/
public function lists()
{
session('admin_menu_index', 'Menu/lists');
$result = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select();
$this->assign("menus", $result);
return $this->fetch();
}
/**
* 后台菜单添加
* @adminMenu(
* 'name' => '后台菜单添加',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单添加',
* 'param' => ''
* )
*/
public function add()
{
$tree = new Tree();
$parentId = $this->request->param("parent_id", 0, 'intval');
$result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select();
$array = [];
foreach ($result as $r) {
$r['selected'] = $r['id'] == $parentId ? 'selected' : '';
$array[] = $r;
}
$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
$tree->init($array);
$selectCategory = $tree->getTree(0, $str);
$this->assign("select_category", $selectCategory);
return $this->fetch();
}
/**
* 后台菜单添加提交保存
* @adminMenu(
* 'name' => '后台菜单添加提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单添加提交保存',
* 'param' => ''
* )
*/
public function addPost()
{
if ($this->request->isPost()) {
$result = $this->validate($this->request->param(), 'AdminMenu');
if ($result !== true) {
$this->error($result);
} else {
$data = $this->request->param();
Db::name('AdminMenu')->strict(false)->field(true)->insert($data);
$app = $this->request->param("app");
$controller = $this->request->param("controller");
$action = $this->request->param("action");
$param = $this->request->param("param");
$authRuleName = "$app/$controller/$action";
$menuName = $this->request->param("name");
$findAuthRuleCount = Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url'
])->count();
if (empty($findAuthRuleCount)) {
Db::name('AuthRule')->insert([
"name" => $authRuleName,
"app" => $app,
"type" => "admin_url", //type 1-admin rule;2-user rule
"title" => $menuName,
'param' => $param,
]);
}
$sessionAdminMenuIndex = session('admin_menu_index');
$to = empty($sessionAdminMenuIndex) ? "Menu/index" : $sessionAdminMenuIndex;
$this->_exportAppMenuDefaultLang();
$this->success("添加成功!", url($to));
}
}
}
/**
* 后台菜单编辑
* @adminMenu(
* 'name' => '后台菜单编辑',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单编辑',
* 'param' => ''
* )
*/
public function edit()
{
$tree = new Tree();
$id = $this->request->param("id", 0, 'intval');
$rs = Db::name('AdminMenu')->where(["id" => $id])->find();
$result = Db::name('AdminMenu')->order(["list_order" => "ASC"])->select();
$array = [];
foreach ($result as $r) {
$r['selected'] = $r['id'] == $rs['parent_id'] ? 'selected' : '';
$array[] = $r;
}
$str = "<option value='\$id' \$selected>\$spacer \$name</option>";
$tree->init($array);
$selectCategory = $tree->getTree(0, $str);
$this->assign("data", $rs);
$this->assign("select_category", $selectCategory);
return $this->fetch();
}
/**
* 后台菜单编辑提交保存
* @adminMenu(
* 'name' => '后台菜单编辑提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单编辑提交保存',
* 'param' => ''
* )
*/
public function editPost()
{
if ($this->request->isPost()) {
$id = $this->request->param('id', 0, 'intval');
$oldMenu = Db::name('AdminMenu')->where(['id' => $id])->find();
$result = $this->validate($this->request->param(), 'AdminMenu.edit');
if ($result !== true) {
$this->error($result);
} else {
Db::name('AdminMenu')->strict(false)->field(true)->update($this->request->param());
$app = $this->request->param("app");
$controller = $this->request->param("controller");
$action = $this->request->param("action");
$param = $this->request->param("param");
$authRuleName = "$app/$controller/$action";
$menuName = $this->request->param("name");
$findAuthRuleCount = Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url'
])->count();
if (empty($findAuthRuleCount)) {
$oldApp = $oldMenu['app'];
$oldController = $oldMenu['controller'];
$oldAction = $oldMenu['action'];
$oldName = "$oldApp/$oldController/$oldAction";
$findOldRuleId = Db::name('AuthRule')->where(["name" => $oldName])->value('id');
if (empty($findOldRuleId)) {
Db::name('AuthRule')->insert([
"name" => $authRuleName,
"app" => $app,
"type" => "admin_url",
"title" => $menuName,
"param" => $param
]);//type 1-admin rule;2-user rule
} else {
Db::name('AuthRule')->where(['id' => $findOldRuleId])->update([
"name" => $authRuleName,
"app" => $app,
"type" => "admin_url",
"title" => $menuName,
"param" => $param]);//type 1-admin rule;2-user rule
}
} else {
Db::name('AuthRule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url'
])->update(["title" => $menuName, 'param' => $param]);//type 1-admin rule;2-user rule
}
$this->_exportAppMenuDefaultLang();
$this->success("保存成功!");
}
}
}
/**
* 后台菜单删除
* @adminMenu(
* 'name' => '后台菜单删除',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单删除',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param("id", 0, 'intval');
$count = Db::name('AdminMenu')->where(["parent_id" => $id])->count();
if ($count > 0) {
$this->error("该菜单下还有子菜单,无法删除!");
}
if (Db::name('AdminMenu')->delete($id) !== false) {
$this->success("删除菜单成功!");
} else {
$this->error("删除失败!");
}
}
/**
* 后台菜单排序
* @adminMenu(
* 'name' => '后台菜单排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '后台菜单排序',
* 'param' => ''
* )
*/
public function listOrder()
{
$adminMenuModel = new AdminMenuModel();
parent::listOrders($adminMenuModel);
$this->success("排序更新成功!");
}
/**
* 导入新后台菜单
* @adminMenu(
* 'name' => '导入新后台菜单',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '导入新后台菜单',
* 'param' => ''
* )
*/
public function getActions()
{
Annotations::$config['cache'] = false;
$annotationManager = Annotations::getManager();
$annotationManager->registry['adminMenu'] = 'app\admin\annotation\AdminMenuAnnotation';
$annotationManager->registry['adminMenuRoot'] = 'app\admin\annotation\AdminMenuRootAnnotation';
$newMenus = [];
$apps = cmf_scan_dir(APP_PATH . '*', GLOB_ONLYDIR);
$app = $this->request->param('app', '');
if (empty($app)) {
$app = $apps[0];
}
if (!in_array($app, $apps)) {
$this->error('应用' . $app . '不存在!');
}
if ($app == 'admin') {
$filePatten = APP_PATH . $app . '/controller/*Controller.php';
} else {
$filePatten = APP_PATH . $app . '/controller/Admin*Controller.php';
}
$controllers = cmf_scan_dir($filePatten);
if (!empty($controllers)) {
foreach ($controllers as $controller) {
$controller = preg_replace('/\.php$/', '', $controller);
$controllerName = preg_replace('/\Controller$/', '', $controller);
$controllerClass = "app\\$app\\controller\\$controller";
$menuAnnotations = Annotations::ofClass($controllerClass, '@adminMenuRoot');
if (!empty($menuAnnotations)) {
foreach ($menuAnnotations as $menuAnnotation) {
$name = $menuAnnotation->name;
$icon = $menuAnnotation->icon;
$type = 0;//1:有界面可访问菜单,2:无界面可访问菜单,0:只作为菜单
$action = $menuAnnotation->action;
$status = empty($menuAnnotation->display) ? 0 : 1;
$listOrder = floatval($menuAnnotation->order);
$param = $menuAnnotation->param;
$remark = $menuAnnotation->remark;
if (empty($menuAnnotation->parent)) {
$parentId = 0;
} else {
$parent = explode('/', $menuAnnotation->parent);
$countParent = count($parent);
if ($countParent > 3) {
throw new \Exception($controllerClass . ':' . $action . ' @adminMenuRoot parent格式不正确!');
}
$parentApp = $app;
$parentController = $controllerName;
$parentAction = '';
switch ($countParent) {
case 1:
$parentAction = $parent[0];
break;
case 2:
$parentController = $parent[0];
$parentAction = $parent[1];
break;
case 3:
$parentApp = $parent[0];
$parentController = $parent[1];
$parentAction = $parent[2];
break;
}
$findParentAdminMenu = Db::name('admin_menu')->where([
'app' => $parentApp,
'controller' => $parentController,
'action' => $parentAction
])->find();
if (empty($findParentAdminMenu)) {
$parentId = Db::name('admin_menu')->insertGetId([
'app' => $parentApp,
'controller' => $parentController,
'action' => $parentAction,
'name' => '--new--'
]);
} else {
$parentId = $findParentAdminMenu['id'];
}
}
$findAdminMenu = Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->find();
if (empty($findAdminMenu)) {
Db::name('admin_menu')->insert([
'parent_id' => $parentId,
'type' => $type,
'status' => $status,
'list_order' => $listOrder,
'app' => $app,
'controller' => $controllerName,
'action' => $action,
'param' => $param,
'name' => $name,
'icon' => $icon,
'remark' => $remark
]);
$menuName = $name;
array_push($newMenus, "$app/$controllerName/$action 已导入");
} else {
if ($findAdminMenu['name'] == '--new--') {
Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->update([
'parent_id' => $parentId,
'type' => $type,
'status' => $status,
'list_order' => $listOrder,
'param' => $param,
'name' => $name,
'icon' => $icon,
'remark' => $remark
]);
$menuName = $name;
} else {
// 只关注菜单层级关系,是否有视图
Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->update([
'parent_id' => $parentId,
'type' => $type,
]);
$menuName = $findAdminMenu['name'];
}
array_push($newMenus, "$app/$controllerName/$action 层级关系已更新");
}
$authRuleName = "{$app}/{$controllerName}/{$action}";
$findAuthRuleCount = Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url'
])->count();
if ($findAuthRuleCount == 0) {
Db::name('auth_rule')->insert([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url',
'param' => $param,
'title' => $menuName
]);
} else {
Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url',
])->update([
'param' => $param,
'title' => $menuName
]);
}
}
}
$reflect = new \ReflectionClass($controllerClass);
$methods = $reflect->getMethods(\ReflectionMethod::IS_PUBLIC);
if (!empty($methods)) {
foreach ($methods as $method) {
if ($method->class == $controllerClass && strpos($method->name, '_') !== 0) {
$menuAnnotations = Annotations::ofMethod($controllerClass, $method->name, '@adminMenu');
if (!empty($menuAnnotations)) {
$menuAnnotation = $menuAnnotations[0];
$name = $menuAnnotation->name;
$icon = $menuAnnotation->icon;
$type = $menuAnnotation->hasView ? 1 : 2;//1:有界面可访问菜单,2:无界面可访问菜单,0:只作为菜单
$action = $method->name;
$status = empty($menuAnnotation->display) ? 0 : 1;
$listOrder = floatval($menuAnnotation->order);
$param = $menuAnnotation->param;
$remark = $menuAnnotation->remark;
if (empty($menuAnnotation->parent)) {
$parentId = 0;
} else {
$parent = explode('/', $menuAnnotation->parent);
$countParent = count($parent);
if ($countParent > 3) {
throw new \Exception($controllerClass . ':' . $action . ' @menuRoot parent格式不正确!');
}
$parentApp = $app;
$parentController = $controllerName;
$parentAction = '';
switch ($countParent) {
case 1:
$parentAction = $parent[0];
break;
case 2:
$parentController = $parent[0];
$parentAction = $parent[1];
break;
case 3:
$parentApp = $parent[0];
$parentController = $parent[1];
$parentAction = $parent[2];
break;
}
$findParentAdminMenu = Db::name('admin_menu')->where([
'app' => $parentApp,
'controller' => $parentController,
'action' => $parentAction
])->find();
if (empty($findParentAdminMenu)) {
$parentId = Db::name('admin_menu')->insertGetId([
'app' => $parentApp,
'controller' => $parentController,
'action' => $parentAction,
'name' => '--new--'
]);
} else {
$parentId = $findParentAdminMenu['id'];
}
}
$findAdminMenu = Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->find();
if (empty($findAdminMenu)) {
Db::name('admin_menu')->insert([
'parent_id' => $parentId,
'type' => $type,
'status' => $status,
'list_order' => $listOrder,
'app' => $app,
'controller' => $controllerName,
'action' => $action,
'param' => $param,
'name' => $name,
'icon' => $icon,
'remark' => $remark
]);
$menuName = $name;
array_push($newMenus, "$app/$controllerName/$action 已导入");
} else {
if ($findAdminMenu['name'] == '--new--') {
Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->update([
'parent_id' => $parentId,
'type' => $type,
'status' => $status,
'list_order' => $listOrder,
'param' => $param,
'name' => $name,
'icon' => $icon,
'remark' => $remark
]);
$menuName = $name;
} else {
// 只关注菜单层级关系,是否有视图
Db::name('admin_menu')->where([
'app' => $app,
'controller' => $controllerName,
'action' => $action
])->update([
'parent_id' => $parentId,
'type' => $type,
]);
$menuName = $findAdminMenu['name'];
}
array_push($newMenus, "$app/$controllerName/$action 已更新");
}
$authRuleName = "{$app}/{$controllerName}/{$action}";
$findAuthRuleCount = Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url'
])->count();
if ($findAuthRuleCount == 0) {
Db::name('auth_rule')->insert([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url',
'param' => $param,
'title' => $menuName
]);
} else {
Db::name('auth_rule')->where([
'app' => $app,
'name' => $authRuleName,
'type' => 'admin_url',
])->update([
'param' => $param,
'title' => $menuName
]);
}
}
}
}
}
}
}
$index = array_search($app, $apps);
$nextIndex = $index + 1;
$nextIndex = $nextIndex >= count($apps) ? 0 : $nextIndex;
if ($nextIndex) {
$this->assign("next_app", $apps[$nextIndex]);
}
$this->assign("app", $app);
$this->assign("new_menus", $newMenus);
return $this->fetch();
}
/**
* 导出后台菜单语言包
*/
private function _exportAppMenuDefaultLang()
{
$menus = Db::name('AdminMenu')->order(["app" => "ASC", "controller" => "ASC", "action" => "ASC"])->select();
$langDir = config('DEFAULT_LANG');
$adminMenuLang = CMF_ROOT . "data/lang/" . $langDir . "/admin_menu.php";
if (!empty($adminMenuLang) && !file_exists_case($adminMenuLang)) {
mkdir(dirname($adminMenuLang), 0777, true);
}
$lang = [];
foreach ($menus as $menu) {
$lang_key = strtoupper($menu['app'] . '_' . $menu['controller'] . '_' . $menu['action']);
$lang[$lang_key] = $menu['name'];
}
$langStr = var_export($lang, true);
$langStr = preg_replace("/\s+\d+\s=>\s(\n|\r)/", "\n", $langStr);
if (!empty($adminMenuLang)) {
file_put_contents($adminMenuLang, "<?php\nreturn $langStr;");
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: kane <chengjin005@163.com> 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\admin\model\NavModel;
use think\Db;
/**
* Class NavController 导航类别管理控制器
* @package app\admin\controller
*/
class NavController extends AdminBaseController
{
/**
* 导航管理
* @adminMenu(
* 'name' => '导航管理',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 30,
* 'icon' => '',
* 'remark' => '导航管理',
* 'param' => ''
* )
*/
public function index()
{
$navModel = new NavModel();
$navs = $navModel->select();
$this->assign('navs', $navs);
return $this->fetch();
}
/**
* 添加导航
* @adminMenu(
* 'name' => '添加导航',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加导航',
* 'param' => ''
* )
*/
public function add()
{
return $this->fetch();
}
/**
* 添加导航提交保存
* @adminMenu(
* 'name' => '添加导航提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加导航提交保存',
* 'param' => ''
* )
*/
public function addPost()
{
$navModel = new NavModel();
$arrData = $this->request->post();
if (empty($arrData["is_main"])) {
$arrData["is_main"] = 0;
} else {
$navModel->where("is_main", 1)->update(["is_main" => 0]);
}
$navModel->allowField(true)->insert($arrData);
$this->success(lang("EDIT_SUCCESS"), url("nav/index"));
}
/**
* 编辑导航
* @adminMenu(
* 'name' => '编辑导航',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑导航',
* 'param' => ''
* )
*/
public function edit()
{
$navModel = new NavModel();
$intId = $this->request->param("id", 0, 'intval');
$objNavCat = $navModel->where(["id" => $intId])->find();
$arrNavCat = $objNavCat ? $objNavCat->toArray() : [];
$this->assign($arrNavCat);
return $this->fetch();
}
/**
* 编辑导航提交保存
* @adminMenu(
* 'name' => '编辑导航提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑导航提交保存',
* 'param' => ''
* )
*/
public function editPost()
{
$navModel = new NavModel();
$arrData = $this->request->post();
if (empty($arrData["is_main"])) {
$arrData["is_main"] = 0;
} else {
$navModel->where("is_main", 1)->update(["is_main" => 0]);
}
$navModel->allowField(true)->where(["id" => $arrData["id"]])->update($arrData);
$this->success(lang("EDIT_SUCCESS"), url("nav/index"));
}
/**
* 删除导航
* @adminMenu(
* 'name' => '删除导航',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除导航',
* 'param' => ''
* )
*/
public function delete()
{
$navModel = new NavModel();
$intId = $this->request->param("id", 0, "intval");
if (empty($intId)) {
$this->error(lang("NO_ID"));
}
$navModel->where(["id" => $intId])->delete();
$this->success(lang("DELETE_SUCCESS"), url("nav/index"));
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: kane <chengjin005@163.com> 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\NavMenuModel;
use cmf\controller\AdminBaseController;
use tree\Tree;
/**
* Class NavMenuController 前台菜单管理控制器
* @package app\admin\controller
*/
class NavMenuController extends AdminBaseController
{
/**
* 导航菜单
* @adminMenu(
* 'name' => '导航菜单',
* 'parent' => 'admin/Nav/index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '导航菜单',
* 'param' => ''
* )
*/
public function index()
{
$intNavId = $this->request->param("nav_id");
$navMenuModel = new NavMenuModel();
if (empty($intNavId)) {
$this->error("请指定导航!");
}
$objResult = $navMenuModel->where("nav_id", $intNavId)->order(["list_order" => "ASC"])->select();
$arrResult = $objResult ? $objResult->toArray() : [];
$tree = new Tree();
$tree->icon = ['&nbsp;&nbsp;&nbsp;│ ', '&nbsp;&nbsp;&nbsp;├─ ', '&nbsp;&nbsp;&nbsp;└─ '];
$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
$array = [];
foreach ($arrResult as $r) {
$r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id'], "nav_id" => $r['nav_id']]) . '">添加子菜单</a> <a href="'
. url("NavMenu/edit", ["id" => $r['id'], "parent_id" => $r['parent_id'], "nav_id" => $r['nav_id']]) . '">编辑</a> <a class="js-ajax-delete" href="' . url("NavMenu/delete", ["id" => $r['id'], 'nav_id' => $r['nav_id']]) . '">删除</a> ';
$r['status'] = $r['status'] ? "显示" : "隐藏";
$array[] = $r;
}
$tree->init($array);
$str = "<tr>
<td><input name='list_orders[\$id]' type='text' size='3' value='\$list_order' class='input input-order'></td>
<td>\$id</td>
<td >\$spacer\$name</td>
<td>\$status</td>
<td>\$str_manage</td>
</tr>";
$categories = $tree->getTree(0, $str);
$this->assign("categories", $categories);
$this->assign('nav_id', $intNavId);
return $this->fetch();
}
/**
* 添加导航菜单
* @adminMenu(
* 'name' => '添加导航菜单',
* 'parent' => 'index',
* 'display'=> false,
* 'order' => 10000,
* 'hasView'=> true,
* 'icon' => '',
* 'remark' => '添加导航菜单',
* 'param' => ''
* )
*/
public function add()
{
$navMenuModel = new NavMenuModel();
$intNavId = $this->request->param("nav_id");
$intParentId = $this->request->param("parent_id");
$objResult = $navMenuModel->where("nav_id", $intNavId)->order(["list_order" => "ASC"])->select();
$arrResult = $objResult ? $objResult->toArray() : [];
$tree = new Tree();
$tree->icon = ['&nbsp;│ ', '&nbsp;├─ ', '&nbsp;└─ '];
$tree->nbsp = '&nbsp;';
$array = [];
foreach ($arrResult as $r) {
$r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id']]) . '">添加子菜单</a> | <a href="'
. url("NavMenu/edit", ["id" => $r['id']]) . '">编辑</a> | <a class="J_ajax_del" href="'
. url("NavMenu/delete", ["id" => $r['id']]) . '">删除</a> ';
$r['status'] = $r['status'] ? "显示" : "隐藏";
$r['selected'] = $r['id'] == $intParentId ? "selected" : "";
$array[] = $r;
}
$tree->init($array);
$str = "<option value='\$id' \$selected>\$spacer\$name</option>";
$navTrees = $tree->getTree(0, $str);
$this->assign("nav_trees", $navTrees);
$navs = $navMenuModel->selectNavs();
$this->assign('navs', $navs);
$this->assign("nav_id", $intNavId);
return $this->fetch();
}
/**
* 添加导航菜单提交保存
* @adminMenu(
* 'name' => '添加导航菜单提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加导航菜单提交保存',
* 'param' => ''
* )
*/
public function addPost()
{
$navMenuModel = new NavMenuModel();
$arrData = $this->request->post();
if (isset($arrData['external_href'])) {
$arrData['href'] = htmlspecialchars_decode($arrData['external_href']);
} else {
$arrData['href'] = htmlspecialchars_decode($arrData['href']);
$arrData['href'] = base64_decode($arrData['href']);
}
$navMenuModel->allowField(true)->isUpdate(false)->save($arrData);
$this->success(lang("EDIT_SUCCESS"), url("NavMenu/index", ['nav_id' => $arrData['nav_id']]));
}
/**
* 编辑导航菜单
* @adminMenu(
* 'name' => '编辑导航菜单',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑导航菜单',
* 'param' => ''
* )
*/
public function edit()
{
$navMenuModel = new NavMenuModel();
$intNavId = $this->request->param("nav_id");
$intId = $this->request->param("id");
$intParentId = $this->request->param("parent_id");
$objResult = $navMenuModel->where(["nav_id" => $intNavId, "id" => ["neq", $intId]])->order(["list_order" => "ASC"])->select();
$arrResult = $objResult ? $objResult->toArray() : [];
$tree = new Tree();
$tree->icon = ['&nbsp;│ ', '&nbsp;├─ ', '&nbsp;└─ '];
$tree->nbsp = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
$array = [];
foreach ($arrResult as $r) {
$r['str_manage'] = '<a href="' . url("NavMenu/add", ["parent_id" => $r['id'], "nav_id" => $intNavId]) . '">添加子菜单</a> | <a href="'
. url("NavMenu/edit", ["id" => $r['id'], "nav_id" => $intNavId]) . '">编辑</a> | <a class="js-ajax-delete" href="'
. url("NavMenu/delete", ["id" => $r['id'], "nav_id" => $intNavId]) . '">删除</a> ';
$r['status'] = $r['status'] ? "显示" : "隐藏";
$r['selected'] = $r['id'] == $intParentId ? "selected" : "";
$array[] = $r;
}
$tree->init($array);
$str = "<option value='\$id' \$selected>\$spacer\$name</option>";
$nav_trees = $tree->getTree(0, $str);
$this->assign("nav_trees", $nav_trees);
$objNav = $navMenuModel->where("id", $intId)->find();
$arrNav = $objNav ? $objNav->toArray() : [];
$arrNav['href_old'] = $arrNav['href'];
if (strpos($arrNav['href'], "{") === 0 || $arrNav['href'] == 'home') {
$arrNav['href'] = base64_encode($arrNav['href']);
}
$this->assign($arrNav);
$navs = $navMenuModel->selectNavs();
$this->assign('navs', $navs);
$this->assign("nav_id", $intNavId);
$this->assign("parent_id", $intParentId);
return $this->fetch();
}
/**
* 编辑导航菜单提交保存
* @adminMenu(
* 'name' => '编辑导航菜单提交保存',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑导航菜单提交保存',
* 'param' => ''
* )
*/
public function editPost()
{
$navMenuModel = new NavMenuModel();
$intId = $this->request->param('id', 0, 'intval');
$arrData = $this->request->post();
if (isset($arrData['external_href'])) {
$arrData['href'] = htmlspecialchars_decode($arrData['external_href']);
} else {
$arrData['href'] = htmlspecialchars_decode($arrData['href']);
$arrData['href'] = base64_decode($arrData['href']);
}
$navMenuModel->update($arrData, ["id" => $intId], true);
$this->success(lang("EDIT_SUCCESS"), url("NavMenu/index", ['nav_id' => $arrData['nav_id']]));
}
/**
* 删除导航菜单
* @adminMenu(
* 'name' => '删除导航菜单',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除导航菜单',
* 'param' => ''
* )
*/
public function delete()
{
$navMenuModel = new NavMenuModel();
$intId = $this->request->param("id", 0, "intval");
$intNavId = $this->request->param("nav_id", 0, "intval");
if (empty($intId)) {
$this->error(lang("NO_ID"));
}
$count = $navMenuModel->where(["parent_id" => $intId])->count();
if ($count > 0) {
$this->error("该菜单下还有子菜单,无法删除!");
}
$navMenuModel->where(["id" => $intId])->delete();
$this->success(lang("DELETE_SUCCESS"), url("NavMenu/index", ['nav_id' => $intNavId]));
}
/**
* 导航菜单排序
* @adminMenu(
* 'name' => '导航菜单排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '导航菜单排序',
* 'param' => ''
* )
*/
public function listOrder()
{
$navMenuModel = new NavMenuModel();
$status = parent::listOrders($navMenuModel);
if ($status) {
$this->success("排序更新成功!");
} else {
$this->error("排序更新失败!");
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use app\admin\model\PluginModel;
use app\admin\model\HookPluginModel;
use think\Db;
use think\Validate;
/**
* Class PluginController
* @package app\admin\controller
* @adminMenuRoot(
* 'name' =>'插件管理',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 20,
* 'icon' =>'cloud',
* 'remark' =>'插件管理'
* )
*/
class PluginController extends AdminBaseController
{
protected $pluginModel;
public function _initialize()
{
parent::_initialize();
}
/**
* 插件列表
* @adminMenu(
* 'name' => '插件列表',
* 'parent' => 'admin/Plugin/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件列表',
* 'param' => ''
* )
*/
public function index()
{
$pluginModel = new PluginModel();
$plugins = $pluginModel->getList();
$this->assign("plugins", $plugins);
return $this->fetch();
}
/**
* 插件启用/禁用
* @adminMenu(
* 'name' => '插件启用禁用',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件启用禁用',
* 'param' => ''
* )
*/
public function toggle()
{
$id = $this->request->param('id', 0, 'intval');
$pluginModel = PluginModel::get($id);
if (empty($pluginModel)) {
$this->error('插件不存在!');
}
$status = 1;
$successMessage = "启用成功!";
if ($this->request->param('disable')) {
$status = 0;
$successMessage = "禁用成功!";
}
$pluginModel->startTrans();
try {
$pluginModel->save(['status' => $status], ['id' => $id]);
$hookPluginModel = new HookPluginModel();
$hookPluginModel->save(['status' => $status], ['plugin' => $pluginModel->name]);
$pluginModel->commit();
} catch (\Exception $e) {
$pluginModel->rollback();
$this->error('操作失败!');
}
$this->success($successMessage);
}
/**
* 插件设置
* @adminMenu(
* 'name' => '插件设置',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件设置',
* 'param' => ''
* )
*/
public function setting()
{
$id = $this->request->param('id', 0, 'intval');
$pluginModel = new PluginModel();
$plugin = $pluginModel->find($id);
if (empty($plugin)) {
$this->error('插件未安装!');
}
$plugin = $plugin->toArray();
$pluginClass = cmf_get_plugin_class($plugin['name']);
if (!class_exists($pluginClass)) {
$this->error('插件不存在!');
}
$pluginObj = new $pluginClass;
//$plugin['plugin_path'] = $pluginObj->plugin_path;
//$plugin['custom_config'] = $pluginObj->custom_config;
$pluginConfigInDb = $plugin['config'];
$plugin['config'] = include $pluginObj->getConfigFilePath();
if ($pluginConfigInDb) {
$pluginConfigInDb = json_decode($pluginConfigInDb, true);
foreach ($plugin['config'] as $key => $value) {
if ($value['type'] != 'group') {
if (isset($pluginConfigInDb[$key])) {
$plugin['config'][$key]['value'] = $pluginConfigInDb[$key];
}
} else {
foreach ($value['options'] as $group => $options) {
foreach ($options['options'] as $gkey => $value) {
if (isset($pluginConfigInDb[$gkey])) {
$plugin['config'][$key]['options'][$group]['options'][$gkey]['value'] = $pluginConfigInDb[$gkey];
}
}
}
}
}
}
$this->assign('data', $plugin);
// if ($plugin['custom_config']) {
// $this->assign('custom_config', $this->fetch($plugin['plugin_path'] . $plugin['custom_config']));
// }
$this->assign('id', $id);
return $this->fetch();
}
/**
* 插件设置提交
* @adminMenu(
* 'name' => '插件设置提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件设置提交',
* 'param' => ''
* )
*/
public function settingPost()
{
if ($this->request->isPost()) {
$id = $this->request->param('id', 0, 'intval');
$pluginModel = new PluginModel();
$plugin = $pluginModel->find($id)->toArray();
if (!$plugin) {
$this->error('插件未安装!');
}
$pluginClass = cmf_get_plugin_class($plugin['name']);
if (!class_exists($pluginClass)) {
$this->error('插件不存在!');
}
$pluginObj = new $pluginClass;
//$plugin['plugin_path'] = $pluginObj->plugin_path;
//$plugin['custom_config'] = $pluginObj->custom_config;
$pluginConfigInDb = $plugin['config'];
$plugin['config'] = include $pluginObj->getConfigFilePath();
$rules = [];
$messages = [];
foreach ($plugin['config'] as $key => $value) {
if ($value['type'] != 'group') {
if (isset($value['rule'])) {
$rules[$key] = $this->_parseRules($value['rule']);
}
if (isset($value['message'])) {
foreach ($value['message'] as $rule => $msg) {
$messages[$key . '.' . $rule] = $msg;
}
}
} else {
foreach ($value['options'] as $group => $options) {
foreach ($options['options'] as $gkey => $value) {
if (isset($value['rule'])) {
$rules[$gkey] = $this->_parseRules($value['rule']);
}
if (isset($value['message'])) {
foreach ($value['message'] as $rule => $msg) {
$messages[$gkey . '.' . $rule] = $msg;
}
}
}
}
}
}
$config = $this->request->param('config/a');
$validate = new Validate($rules, $messages);
$result = $validate->check($config);
if ($result !== true) {
$this->error($validate->getError());
}
$pluginModel = new PluginModel();
$pluginModel->save(['config' => json_encode($config)], ['id' => $id]);
$this->success('保存成功', '');
}
}
/**
* 解析插件配置验证规则
* @param $rules
* @return array
*/
private function _parseRules($rules)
{
$newRules = [];
$simpleRules = [
'require', 'number',
'integer', 'float', 'boolean', 'email',
'array', 'accepted', 'date', 'alpha',
'alphaNum', 'alphaDash', 'activeUrl',
'url', 'ip'];
foreach ($rules as $key => $rule) {
if (in_array($key, $simpleRules) && $rule) {
array_push($newRules, $key);
}
}
return $newRules;
}
/**
* 插件安装
* @adminMenu(
* 'name' => '插件安装',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件安装',
* 'param' => ''
* )
*/
public function install()
{
$pluginName = $this->request->param('name', '', 'trim');
$class = cmf_get_plugin_class($pluginName);
if (!class_exists($class)) {
$this->error('插件不存在!');
}
$pluginModel = new PluginModel();
$pluginCount = $pluginModel->where('name', $pluginName)->count();
if ($pluginCount > 0) {
$this->error('插件已安装!');
}
$plugin = new $class;
$info = $plugin->info;
if (!$info || !$plugin->checkInfo()) {//检测信息的正确性
$this->error('插件信息缺失!');
}
$installSuccess = $plugin->install();
if (!$installSuccess) {
$this->error('插件预安装失败!');
}
$methods = get_class_methods($plugin);
foreach ($methods as $methodKey => $method) {
$methods[$methodKey] = cmf_parse_name($method);
}
$systemHooks = $pluginModel->getHooks(true);
$pluginHooks = array_intersect($systemHooks, $methods);
//$info['hooks'] = implode(",", $pluginHooks);
if (!empty($plugin->hasAdmin)) {
$info['has_admin'] = 1;
} else {
$info['has_admin'] = 0;
}
$info['config'] = json_encode($plugin->getConfig());
$pluginModel->data($info)->allowField(true)->save();
$hookPluginModel = new HookPluginModel();
foreach ($pluginHooks as $pluginHook) {
$hookPluginModel->data(['hook' => $pluginHook, 'plugin' => $pluginName, 'status' => 1])->isUpdate(false)->save();
}
$this->success('安装成功!');
}
/**
* 插件更新
* @adminMenu(
* 'name' => '插件更新',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '插件更新',
* 'param' => ''
* )
*/
public function update()
{
$pluginName = $this->request->param('name', '', 'trim');
$class = cmf_get_plugin_class($pluginName);
if (!class_exists($class)) {
$this->error('插件不存在!');
}
$plugin = new $class;
$info = $plugin->info;
if (!$info || !$plugin->checkInfo()) {//检测信息的正确性
$this->error('插件信息缺失!');
}
$methods = get_class_methods($plugin);
foreach ($methods as $methodKey => $method) {
$methods[$methodKey] = cmf_parse_name($method);
}
$pluginModel = new PluginModel();
$systemHooks = $pluginModel->getHooks(true);
$pluginHooks = array_intersect($systemHooks, $methods);
if (!empty($plugin->hasAdmin)) {
$info['has_admin'] = 1;
} else {
$info['has_admin'] = 0;
}
$config = $plugin->getConfig();
$defaultConfig = $plugin->getDefaultConfig();
$pluginModel = new PluginModel();
$config = array_merge($defaultConfig, $config);
$info['config'] = json_encode($config);
$pluginModel->allowField(true)->save($info, ['name' => $pluginName]);
$hookPluginModel = new HookPluginModel();
$pluginHooksInDb = $hookPluginModel->where('plugin', $pluginName)->column('hook');
$samePluginHooks = array_intersect($pluginHooks, $pluginHooksInDb);
$shouldDeleteHooks = array_diff($samePluginHooks, $pluginHooksInDb);
$newHooks = array_diff($pluginHooks, $samePluginHooks);
if (count($shouldDeleteHooks) > 0) {
$hookPluginModel->where('hook', 'in', $shouldDeleteHooks)->delete();
}
foreach ($newHooks as $pluginHook) {
$hookPluginModel->data(['hook' => $pluginHook, 'plugin' => $pluginName])->isUpdate(false)->save();
}
$this->success('更新成功!');
}
/**
* 卸载插件
* @adminMenu(
* 'name' => '卸载插件',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '卸载插件',
* 'param' => ''
* )
*/
public function uninstall()
{
$pluginModel = new PluginModel();
$id = $this->request->param('id', 0, 'intval');
$result = $pluginModel->uninstall($id);
if ($result !== true) {
$this->error('卸载失败!');
}
$this->success('卸载成功!');
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class PublicController extends AdminBaseController
{
public function _initialize()
{
$siteInfo = cmf_get_site_info();
$this->assign('site_info', $siteInfo);
}
/**
* 后台登陆界面
*/
public function login()
{
$loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
if (empty($loginAllowed)) {
$this->error('非法登录!', cmf_get_root() . '/');
}
$admin_id = session('ADMIN_ID');
if (!empty($admin_id)) {//已经登录
redirect(url("admin/Index/index"));
} else {
$site_admin_url_password = config("cmf_SITE_ADMIN_URL_PASSWORD");
$upw = session("__CMF_UPW__");
if (!empty($site_admin_url_password) && $upw != $site_admin_url_password) {
redirect(ROOT_PATH . "/");
} else {
session("__SP_ADMIN_LOGIN_PAGE_SHOWED_SUCCESS__", true);
$result = hook_one('admin_login');
if (!empty($result)) {
return $result;
}
return $this->fetch(":login");
}
}
}
/**
* 登录验证
*/
public function doLogin()
{
$loginAllowed = session("__LOGIN_BY_CMF_ADMIN_PW__");
if (empty($loginAllowed)) {
$this->error('非法登录!', cmf_get_root() . '/');
}
$captcha = $this->request->param('captcha');
if (empty($captcha)) {
$this->error(lang('CAPTCHA_REQUIRED'));
}
//验证码
if (!cmf_captcha_check($captcha)) {
$this->error(lang('CAPTCHA_NOT_RIGHT'));
}
$name = $this->request->param("username");
if (empty($name)) {
$this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
}
$pass = $this->request->param("password");
if (empty($pass)) {
$this->error(lang('PASSWORD_REQUIRED'));
}
if (strpos($name, "@") > 0) {//邮箱登陆
$where['user_email'] = $name;
} else {
$where['user_login'] = $name;
}
$result = Db::name('user')->where($where)->find();
if (!empty($result) && $result['user_type'] == 1) {
if (cmf_compare_password($pass, $result['user_pass'])) {
$groups = Db::name('RoleUser')
->alias("a")
->join('__ROLE__ b', 'a.role_id =b.id')
->where(["user_id" => $result["id"], "status" => 1])
->value("role_id");
if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
$this->error(lang('USE_DISABLED'));
}
//登入成功页面跳转
session('ADMIN_ID', $result["id"]);
session('name', $result["user_login"]);
$result['last_login_ip'] = get_client_ip(0, true);
$result['last_login_time'] = time();
$token = cmf_generate_user_token($result["id"], 'web');
if (!empty($token)) {
session('token', $token);
}
Db::name('user')->update($result);
cookie("admin_username", $name, 3600 * 24 * 30);
session("__LOGIN_BY_CMF_ADMIN_PW__", null);
$this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
} else {
$this->error(lang('PASSWORD_NOT_RIGHT'));
}
} else {
$this->error(lang('USERNAME_NOT_EXIST'));
}
}
/**
* 后台管理员退出
*/
public function logout()
{
session('ADMIN_ID', null);
return redirect(url('/', [], false, true));
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
use tree\Tree;
use app\admin\model\AdminMenuModel;
class RbacController extends AdminBaseController
{
/**
* 角色管理列表
* @adminMenu(
* 'name' => '角色管理',
* 'parent' => 'admin/User/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '角色管理',
* 'param' => ''
* )
*/
public function index()
{
$data = Db::name('role')->order(["list_order" => "ASC", "id" => "DESC"])->select();
$this->assign("roles", $data);
return $this->fetch();
}
/**
* 添加角色
* @adminMenu(
* 'name' => '添加角色',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加角色',
* 'param' => ''
* )
*/
public function roleAdd()
{
return $this->fetch();
}
/**
* 添加角色提交
* @adminMenu(
* 'name' => '添加角色提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加角色提交',
* 'param' => ''
* )
*/
public function roleAddPost()
{
if ($this->request->isPost()) {
$data = $this->request->param();
$result = $this->validate($data, 'role');
if ($result !== true) {
// 验证失败 输出错误信息
$this->error($result);
} else {
$result = Db::name('role')->insert($data);
if ($result) {
$this->success("添加角色成功", url("rbac/index"));
} else {
$this->error("添加角色失败");
}
}
}
}
/**
* 编辑角色
* @adminMenu(
* 'name' => '编辑角色',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑角色',
* 'param' => ''
* )
*/
public function roleEdit()
{
$id = $this->request->param("id", 0, 'intval');
if ($id == 1) {
$this->error("超级管理员角色不能被修改!");
}
$data = Db::name('role')->where(["id" => $id])->find();
if (!$data) {
$this->error("该角色不存在!");
}
$this->assign("data", $data);
return $this->fetch();
}
/**
* 编辑角色提交
* @adminMenu(
* 'name' => '编辑角色提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑角色提交',
* 'param' => ''
* )
*/
public function roleEditPost()
{
$id = $this->request->param("id", 0, 'intval');
if ($id == 1) {
$this->error("超级管理员角色不能被修改!");
}
if ($this->request->isPost()) {
$data = $this->request->param();
$result = $this->validate($data, 'role');
if ($result !== true) {
// 验证失败 输出错误信息
$this->error($result);
} else {
if (Db::name('role')->update($data) !== false) {
$this->success("保存成功!", url('rbac/index'));
} else {
$this->error("保存失败!");
}
}
}
}
/**
* 删除角色
* @adminMenu(
* 'name' => '删除角色',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除角色',
* 'param' => ''
* )
*/
public function roleDelete()
{
$id = $this->request->param("id", 0, 'intval');
if ($id == 1) {
$this->error("超级管理员角色不能被删除!");
}
$count = Db::name('RoleUser')->where(['role_id' => $id])->count();
if ($count > 0) {
$this->error("该角色已经有用户!");
} else {
$status = Db::name('role')->delete($id);
if (!empty($status)) {
$this->success("删除成功!", url('rbac/index'));
} else {
$this->error("删除失败!");
}
}
}
/**
* 设置角色权限
* @adminMenu(
* 'name' => '设置角色权限',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '设置角色权限',
* 'param' => ''
* )
*/
public function authorize()
{
$AuthAccess = Db::name("AuthAccess");
$adminMenuModel = new AdminMenuModel();
//角色ID
$roleId = $this->request->param("id", 0, 'intval');
if (empty($roleId)) {
$this->error("参数错误!");
}
$tree = new Tree();
$tree->icon = ['│ ', '├─ ', '└─ '];
$tree->nbsp = '&nbsp;&nbsp;&nbsp;';
$result = $adminMenuModel->menuCache();
$newMenus = [];
$privilegeData = $AuthAccess->where(["role_id" => $roleId])->column("rule_name");//获取权限表数据
foreach ($result as $m) {
$newMenus[$m['id']] = $m;
}
foreach ($result as $n => $t) {
$result[$n]['checked'] = ($this->_isChecked($t, $privilegeData)) ? ' checked' : '';
$result[$n]['level'] = $this->_getLevel($t['id'], $newMenus);
$result[$n]['style'] = empty($t['parent_id']) ? '' : 'display:none;';
$result[$n]['parentIdNode'] = ($t['parent_id']) ? ' class="child-of-node-' . $t['parent_id'] . '"' : '';
}
$str = "<tr id='node-\$id'\$parentIdNode style='\$style'>
<td style='padding-left:30px;'>\$spacer<input type='checkbox' name='menuId[]' value='\$id' level='\$level' \$checked onclick='javascript:checknode(this);'> \$name</td>
</tr>";
$tree->init($result);
$category = $tree->getTree(0, $str);
$this->assign("category", $category);
$this->assign("roleId", $roleId);
return $this->fetch();
}
/**
* 角色授权提交
* @adminMenu(
* 'name' => '角色授权提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '角色授权提交',
* 'param' => ''
* )
*/
public function authorizePost()
{
if ($this->request->isPost()) {
$roleId = $this->request->param("roleId", 0, 'intval');
if (!$roleId) {
$this->error("需要授权的角色不存在!");
}
if (is_array($this->request->param('menuId/a')) && count($this->request->param('menuId/a')) > 0) {
Db::name("authAccess")->where(["role_id" => $roleId, 'type' => 'admin_url'])->delete();
foreach ($_POST['menuId'] as $menuId) {
$menu = Db::name("adminMenu")->where(["id" => $menuId])->field("app,controller,action")->find();
if ($menu) {
$app = $menu['app'];
$model = $menu['controller'];
$action = $menu['action'];
$name = strtolower("$app/$model/$action");
Db::name("authAccess")->insert(["role_id" => $roleId, "rule_name" => $name, 'type' => 'admin_url']);
}
}
$this->success("授权成功!");
} else {
//当没有数据时,清除当前角色授权
Db::name("authAccess")->where(["role_id" => $roleId])->delete();
$this->error("没有接收到数据,执行清除授权成功!");
}
}
}
/**
* 检查指定菜单是否有权限
* @param array $menu menu表中数组
* @param $privData
* @return bool
*/
private function _isChecked($menu, $privData)
{
$app = $menu['app'];
$model = $menu['controller'];
$action = $menu['action'];
$name = strtolower("$app/$model/$action");
if ($privData) {
if (in_array($name, $privData)) {
return true;
} else {
return false;
}
} else {
return false;
}
}
/**
* 获取菜单深度
* @param $id
* @param array $array
* @param int $i
* @return int
*/
protected function _getLevel($id, $array = [], $i = 0)
{
if ($array[$id]['parent_id'] == 0 || empty($array[$array[$id]['parent_id']]) || $array[$id]['parent_id'] == $id) {
return $i;
} else {
$i++;
return $this->_getLevel($array[$id]['parent_id'], $array, $i);
}
}
//角色成员管理
public function member()
{
//TODO 添加角色成员管理
}
}
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class RecycleBinController extends AdminBaseController
{
/**
* 回收站
* @adminMenu(
* 'name' => '回收站',
* 'parent' => '',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站',
* 'param' => ''
* )
*/
function index()
{
$list = Db::name('recycleBin')->order('create_time desc')->paginate(10);
// 获取分页显示
$page = $list->render();
$this->assign('page', $page);
$this->assign('list', $list);
return $this->fetch();
}
/**
* 回收站还原
* @adminMenu(
* 'name' => '回收站还原',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站还原',
* 'param' => ''
* )
*/
function restore()
{
$id = $this->request->param('id');
$result = Db::name('recycleBin')->where(['id' => $id])->find();
$tableName = explode('#', $result['table_name']);
$tableName = $tableName[0];
//还原资源
if ($result) {
$res = Db::name($tableName)
->where(['id' => $result['object_id']])
->update(['delete_time' => '0']);
if ($tableName =='portal_post'){
Db::name('portal_category_post')->where('post_id',$result['object_id'])->update(['status'=>1]);
Db::name('portal_tag_post')->where('post_id',$result['object_id'])->update(['status'=>1]);
}
if ($res) {
$re = Db::name('recycleBin')->where('id', $id)->delete();
if ($re) {
$this->success("还原成功!");
}
}
}
}
/**
* 回收站彻底删除
* @adminMenu(
* 'name' => '回收站彻底删除',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '回收站彻底删除',
* 'param' => ''
* )
*/
function delete()
{
$id = $this->request->param('id');
$result = Db::name('recycleBin')->where(['id' => $id])->find();
//删除资源
if ($result) {
//页面没有单独的表.
if($result['table_name'] === 'portal_post#page'){
$re = Db::name('portal_post')->where('id', $result['object_id'])->delete();
//消除路由
$routeModel = new RouteModel();
$routeModel->setRoute('', 'portal/Page/index', ['id' => $result['object_id']], 2, 5000);
$routeModel->getRoutes(true);
}else{
$re = Db::name($result['table_name'])->where('id', $result['object_id'])->delete();
}
if ($re) {
$res = Db::name('recycleBin')->where('id', $id)->delete();
if($result['table_name'] === 'portal_post'){
Db::name('portal_category_post')->where('post_id',$result['object_id'])->delete();
Db::name('portal_tag_post')->where('post_id',$result['object_id'])->delete();
}
if ($res) {
$this->success("删除成功!");
}
}
}
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class RouteController extends AdminBaseController
{
public function _initialize()
{
parent::_initialize();
}
/**
* 路由规则列表
* @adminMenu(
* 'name' => 'URL美化',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => 'URL规则管理',
* 'param' => ''
* )
*/
public function index()
{
$routeModel = new RouteModel();
$routes = Db::name('route')->order("list_order asc")->select();
$routeModel->getRoutes(true);
$this->assign("routes", $routes);
return $this->fetch();
}
/**
* 添加路由规则
* @adminMenu(
* 'name' => '添加路由规则',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加路由规则',
* 'param' => ''
* )
*/
public function add()
{
return $this->fetch();
}
/**
* 添加路由规则提交
* @adminMenu(
* 'name' => '添加路由规则提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加路由规则提交',
* 'param' => ''
* )
*/
public function addPost()
{
$data = $this->request->param();
$routeModel = new RouteModel();
$result = $routeModel->validate(true)->allowField(true)->save($data);
if ($result === false) {
$this->error($routeModel->getError());
}
$this->success("添加成功!", url("Route/index", ['id' => $routeModel->id]));
}
/**
* 路由规则编辑
* @adminMenu(
* 'name' => '路由规则编辑',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则编辑',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param("id", 0, 'intval');
$route = Db::name('route')->where(['id' => $id])->find();
$this->assign($route);
return $this->fetch();
}
/**
* 路由规则编辑提交
* @adminMenu(
* 'name' => '路由规则编辑提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则编辑提交',
* 'param' => ''
* )
*/
public function editPost()
{
$data = $this->request->param();
$routeModel = new RouteModel();
$result = $routeModel->validate(true)->allowField(true)->isUpdate(true)->save($data);
if ($result === false) {
$this->error($routeModel->getError());
}
$this->success("保存成功!", url("Route/index"));
}
/**
* 路由规则删除
* @adminMenu(
* 'name' => '路由规则删除',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则删除',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id', 0, 'intval');
RouteModel::destroy($id);
$this->success("删除成功!");
}
/**
* 路由规则禁用
* @adminMenu(
* 'name' => '路由规则禁用',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则禁用',
* 'param' => ''
* )
*/
public function ban()
{
$id = $this->request->param("id", 0, 'intval');
$data = [];
$data['status'] = 0;
$data['id'] = $id;
$routeModel = new RouteModel();
$routeModel->isUpdate(true)->save($data);
$this->success("禁用成功!");
}
/**
* 路由规则启用
* @adminMenu(
* 'name' => '路由规则启用',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则启用',
* 'param' => ''
* )
*/
public function open()
{
$id = $this->request->param("id", 0, 'intval');
$data = [];
$data['status'] = 1;
$data['id'] = $id;
$routeModel = new RouteModel();
$routeModel->isUpdate(true)->save($data);
$this->success("启用成功!");
}
/**
* 路由规则排序
* @adminMenu(
* 'name' => '路由规则排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '路由规则排序',
* 'param' => ''
* )
*/
public function listOrder()
{
$routeModel = new RouteModel();
parent::listOrders($routeModel);
$this->success("排序更新成功!");
}
/**
* 选择 URL
* @adminMenu(
* 'name' => '选择URL',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '选择URL',
* 'param' => ''
* )
*/
public function select()
{
$routeModel = new RouteModel();
$urls = $routeModel->getAppUrls();
$this->assign('urls', $urls);
return $this->fetch();
}
function _suggest_url($action, $url)
{
$actionArr = explode('/', $action);
$params = array_keys($url['vars']);
$urlDepr1Params = [];
$urlDepr2Params = [];
if (!empty($params)) {
foreach ($params as $param) {
if(empty($url['vars'][$param]['require'])){
array_push($urlDepr1Params, "[:$param]");
}else{
array_push($urlDepr1Params, ":$param");
}
array_push($urlDepr2Params, htmlspecialchars('<') . $param . htmlspecialchars('>'));
}
}
if ($actionArr[2] == 'index') {
$actionArr[1] = cmf_parse_name($actionArr[1]);
return empty($params) ? $actionArr[1].'$' : ($actionArr[1] . '/' . implode('/', $urlDepr1Params) /*. '或' . $actionArr[1] . '-' . implode('-', $urlDepr2Params)*/);
} else {
$actionArr[2] = cmf_parse_name($actionArr[2]);
return empty($params) ? $actionArr[2].'$' : ($actionArr[2] . '/' . implode('/', $urlDepr1Params) /*. '或' . $actionArr[2] . '-' . implode('-', $urlDepr2Params)*/);
}
}
function _url_vars($url)
{
if (!empty($url['vars'])) {
return implode(',', array_keys($url['vars']));
}
return '';
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
/**
* Class SettingController
* @package app\admin\controller
* @adminMenuRoot(
* 'name' =>'设置',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 0,
* 'icon' =>'cogs',
* 'remark' =>'系统设置入口'
* )
*/
class SettingController extends AdminBaseController
{
/**
* 网站信息
* @adminMenu(
* 'name' => '网站信息',
* 'parent' => 'default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 0,
* 'icon' => '',
* 'remark' => '网站信息',
* 'param' => ''
* )
*/
public function site()
{
$noNeedDirs = [".", "..", ".svn", 'fonts'];
$adminThemesDir = config('cmf_admin_theme_path') . config('cmf_admin_default_theme') . '/public/assets/themes/';
$adminStyles = cmf_scan_dir($adminThemesDir . '*', GLOB_ONLYDIR);
$adminStyles = array_diff($adminStyles, $noNeedDirs);
$cdnSettings = cmf_get_option('cdn_settings');
$cmfSettings = cmf_get_option('cmf_settings');
$adminSettings = cmf_get_option('admin_settings');
$this->assign(cmf_get_option('site_info'));
$this->assign("admin_styles", $adminStyles);
$this->assign("templates", []);
$this->assign("cdn_settings", $cdnSettings);
$this->assign("admin_settings", $adminSettings);
$this->assign("cmf_settings", $cmfSettings);
return $this->fetch();
}
/**
* 网站信息设置提交
* @adminMenu(
* 'name' => '网站信息设置提交',
* 'parent' => 'site',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '网站信息设置提交',
* 'param' => ''
* )
*/
public function sitePost()
{
if ($this->request->isPost()) {
$result = $this->validate($this->request->param(), 'SettingSite');
if ($result !== true) {
$this->error($result);
}
$options = $this->request->param('options/a');
cmf_set_option('site_info', $options);
$cmfSettings = $this->request->param('cmf_settings/a');
$bannedUsernames = preg_replace("/[^0-9A-Za-z_\\x{4e00}-\\x{9fa5}-]/u", ",", $cmfSettings['banned_usernames']);
$cmfSettings['banned_usernames'] = $bannedUsernames;
cmf_set_option('cmf_settings', $cmfSettings);
$cdnSettings = $this->request->param('cdn_settings/a');
cmf_set_option('cdn_settings', $cdnSettings);
$adminSettings = $this->request->param('admin_settings/a');
$routeModel = new RouteModel();
if (!empty($adminSettings['admin_password'])) {
$routeModel->setRoute($adminSettings['admin_password'].'$', 'admin/Index/index', [], 2, 5000);
} else {
$routeModel->deleteRoute('admin/Index/index', []);
}
$routeModel->getRoutes(true);
cmf_set_option('admin_settings', $adminSettings);
$this->success("保存成功!", '');
}
}
/**
* 密码修改
* @adminMenu(
* 'name' => '密码修改',
* 'parent' => 'default',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '密码修改',
* 'param' => ''
* )
*/
public function password()
{
return $this->fetch();
}
/**
* 密码修改提交
* @adminMenu(
* 'name' => '密码修改提交',
* 'parent' => 'password',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '密码修改提交',
* 'param' => ''
* )
*/
public function passwordPost()
{
if ($this->request->isPost()) {
$data = $this->request->param();
if (empty($data['old_password'])) {
$this->error("原始密码不能为空!");
}
if (empty($data['password'])) {
$this->error("新密码不能为空!");
}
$userId = cmf_get_current_admin_id();
$admin = Db::name('user')->where(["id" => $userId])->find();
$oldPassword = $data['old_password'];
$password = $data['password'];
$rePassword = $data['re_password'];
if (cmf_compare_password($oldPassword, $admin['user_pass'])) {
if ($password == $rePassword) {
if (cmf_compare_password($password, $admin['user_pass'])) {
$this->error("新密码不能和原始密码相同!");
} else {
Db::name('user')->where('id', $userId)->update(['user_pass' => cmf_password($password)]);
$this->success("密码修改成功!");
}
} else {
$this->error("密码输入不一致!");
}
} else {
$this->error("原始密码不正确!");
}
}
}
/**
* 上传限制设置界面
* @adminMenu(
* 'name' => '上传设置',
* 'parent' => 'default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '上传设置',
* 'param' => ''
* )
*/
public function upload()
{
$uploadSetting = cmf_get_upload_setting();
$this->assign($uploadSetting);
return $this->fetch();
}
/**
* 上传限制设置界面提交
* @adminMenu(
* 'name' => '上传设置提交',
* 'parent' => 'upload',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '上传设置提交',
* 'param' => ''
* )
*/
public function uploadPost()
{
if ($this->request->isPost()) {
//TODO 非空验证
$uploadSetting = $this->request->post();
cmf_set_option('upload_setting', $uploadSetting);
$this->success('保存成功!');
}
}
/**
* 清除缓存
* @adminMenu(
* 'name' => '清除缓存',
* 'parent' => 'default',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '清除缓存',
* 'param' => ''
* )
*/
public function clearCache()
{
cmf_clear_cache();
return $this->fetch();
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\admin\model\SlideModel;
use cmf\controller\AdminBaseController;
use think\Db;
class SlideController extends AdminBaseController
{
/**
* 幻灯片列表
* @adminMenu(
* 'name' => '幻灯片管理',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 40,
* 'icon' => '',
* 'remark' => '幻灯片管理',
* 'param' => ''
* )
*/
public function index()
{
$slidePostModel = new SlideModel();
$slides = $slidePostModel->where(['delete_time' => ['eq', 0]])->select();
$this->assign('slides', $slides);
return $this->fetch();
}
/**
* 添加幻灯片
* @adminMenu(
* 'name' => '添加幻灯片',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加幻灯片',
* 'param' => ''
* )
*/
public function add()
{
return $this->fetch();
}
/**
* 添加幻灯片提交
* @adminMenu(
* 'name' => '添加幻灯片提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '添加幻灯片提交',
* 'param' => ''
* )
*/
public function addPost()
{
$data = $this->request->param();
$slidePostModel = new SlideModel();
$result = $slidePostModel->validate(true)->save($data);
if ($result === false) {
$this->error($slidePostModel->getError());
}
$this->success("添加成功!", url("slide/index"));
}
/**
* 编辑幻灯片
* @adminMenu(
* 'name' => '编辑幻灯片',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑幻灯片',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param('id');
$slidePostModel = new SlideModel();
$result = $slidePostModel->where('id', $id)->find();
$this->assign('result', $result);
return $this->fetch();
}
/**
* 编辑幻灯片提交
* @adminMenu(
* 'name' => '编辑幻灯片提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '编辑幻灯片提交',
* 'param' => ''
* )
*/
public function editPost()
{
$data = $this->request->param();
$slidePostModel = new SlideModel();
$result = $slidePostModel->validate(true)->save($data, ['id' => $data['id']]);
if ($result === false) {
$this->error($slidePostModel->getError());
}
$this->success("保存成功!", url("slide/index"));
}
/**
* 删除幻灯片
* @adminMenu(
* 'name' => '删除幻灯片',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除幻灯片',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id', 0, 'intval');
$slidePostModel = new SlideModel();
$result = $slidePostModel->where(['id' => $id])->find();
if (empty($result)){
$this->error('幻灯片不存在!');
}
//如果存在页面。则不能删除。
$slidePostCount = Db::name('slide_item')->where('slide_id', $id)->count();
if ($slidePostCount > 0) {
$this->error('此幻灯片有页面无法删除!');
}
$data = [
'object_id' => $id,
'create_time' => time(),
'table_name' => 'slide',
'name' => $result['name']
];
$resultSlide = $slidePostModel->save(['delete_time' => time()], ['id' => $id]);
if ($resultSlide) {
Db::name('recycleBin')->insert($data);
}
$this->success("删除成功!", url("slide/index"));
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Db;
use cmf\controller\AdminBaseController;
use app\admin\model\SlideItemModel;
class SlideItemController extends AdminBaseController
{
/**
* 幻灯片页面列表
* @adminMenu(
* 'name' => '幻灯片页面列表',
* 'parent' => 'admin/Slide/index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面列表',
* 'param' => ''
* )
*/
public function index()
{
$id = $this->request->param('slide_id');
$slideId = !empty($id) ? $id : 1;
$result = Db::name('slideItem')->where(['slide_id' => $slideId])->select()->toArray();
$this->assign('slide_id', $id);
$this->assign('result', $result);
return $this->fetch();
}
/**
* 幻灯片页面添加
* @adminMenu(
* 'name' => '幻灯片页面添加',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面添加',
* 'param' => ''
* )
*/
public function add()
{
$slideId = $this->request->param('slide_id');
$this->assign('slide_id', $slideId);
return $this->fetch();
}
/**
* 幻灯片页面添加提交
* @adminMenu(
* 'name' => '幻灯片页面添加提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面添加提交',
* 'param' => ''
* )
*/
public function addPost()
{
$data = $this->request->param();
Db::name('slideItem')->insert($data['post']);
$this->success("添加成功!", url("slideItem/index", ['slide_id' => $data['post']['slide_id']]));
}
/**
* 幻灯片页面编辑
* @adminMenu(
* 'name' => '幻灯片页面编辑',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面编辑',
* 'param' => ''
* )
*/
public function edit()
{
$id = $this->request->param('id');
$result = Db::name('slideItem')->where(['id' => $id])->find();
$this->assign('result', $result);
$this->assign('slide_id', $result['slide_id']);
return $this->fetch();
}
/**
* 幻灯片页面编辑
* @adminMenu(
* 'name' => '幻灯片页面编辑提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面编辑提交',
* 'param' => ''
* )
*/
public function editPost()
{
$data = $this->request->param();
$data['post']['image'] = cmf_asset_relative_url($data['post']['image']);
Db::name('slideItem')->update($data['post']);
$this->success("保存成功!", url("SlideItem/index", ['slide_id' => $data['post']['slide_id']]));
}
/**
* 幻灯片页面删除
* @adminMenu(
* 'name' => '幻灯片页面删除',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面删除',
* 'param' => ''
* )
*/
public function delete()
{
$id = $this->request->param('id', 0, 'intval');
$slideItem = Db::name('slideItem')->find($id);
$result = Db::name('slideItem')->delete($id);
if ($result) {
//删除图片。
// if (file_exists("./upload/".$slideItem['image'])){
// @unlink("./upload/".$slideItem['image']);
// }
$this->success("删除成功!", url("SlideItem/index",["slide_id"=>$slideItem['slide_id']]));
} else {
$this->error('删除失败!');
}
}
/**
* 幻灯片页面隐藏
* @adminMenu(
* 'name' => '幻灯片页面隐藏',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面隐藏',
* 'param' => ''
* )
*/
public function ban()
{
$id = $this->request->param('id', 0, 'intval');
if ($id) {
$rst = Db::name('slideItem')->where(['id' => $id])->update(['status' => 0]);
if ($rst) {
$this->success("幻灯片隐藏成功!");
} else {
$this->error('幻灯片隐藏失败!');
}
} else {
$this->error('数据传入失败!');
}
}
/**
* 幻灯片页面显示
* @adminMenu(
* 'name' => '幻灯片页面显示',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面显示',
* 'param' => ''
* )
*/
public function cancelBan()
{
$id = $this->request->param('id', 0, 'intval');
if ($id) {
$result = Db::name('slideItem')->where(['id' => $id])->update(['status' => 1]);
if ($result) {
$this->success("幻灯片启用成功!");
} else {
$this->error('幻灯片启用失败!');
}
} else {
$this->error('数据传入失败!');
}
}
/**
* 幻灯片页面排序
* @adminMenu(
* 'name' => '幻灯片页面排序',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '幻灯片页面排序',
* 'param' => ''
* )
*/
public function listOrder()
{
$slideItemModel = new SlideItemModel();
parent::listOrders($slideItemModel);
$this->success("排序更新成功!");
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
class StorageController extends AdminBaseController
{
public function _initialize()
{
parent::_initialize();
}
/**
* 文件存储
* @adminMenu(
* 'name' => '文件存储',
* 'parent' => 'admin/Setting/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '文件存储',
* 'param' => ''
* )
*/
public function index()
{
$storage = cmf_get_option('storage');
if (empty($storage)) {
$storage['type'] = 'Local';
$storage['storages'] = ['Local' => ['name' => '本地']];
} else {
if (empty($storage['type'])) {
$storage['type'] = 'Local';
}
if (empty($storage['storages']['Local'])) {
$storage['storages']['Local'] = ['name' => '本地'];
}
}
$this->assign($storage);
return $this->fetch();
}
/**
* 文件存储
* @adminMenu(
* 'name' => '文件存储设置提交',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '文件存储设置提交',
* 'param' => ''
* )
*/
public function settingPost()
{
$post = $this->request->post();
$storage = cmf_get_option('storage');
$storage['type'] = $post['type'];
cmf_set_option('storage', $storage);
$this->success("设置成功!", '');
}
}
\ No newline at end of file
... ...