@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\AttachmentModel;
|
||||
use app\common\model\AttachmentNavModel;
|
||||
|
||||
/**
|
||||
* 附件管理
|
||||
*
|
||||
* @icon fa fa-circle-o
|
||||
* @remark 主要用于管理上传到服务器或第三方存储的数据
|
||||
*/
|
||||
class Attachment extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\common\model\Attachment
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
protected $searchFields = 'id,filename,url';
|
||||
protected $noNeedRight = ['classify'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = model('Attachment');
|
||||
$this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
|
||||
$this->view->assign("categoryList", \app\common\model\Attachment::getCategoryList());
|
||||
$this->assignconfig("categoryList", \app\common\model\Attachment::getCategoryList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$mimetypeQuery = [];
|
||||
$filter = $this->request->request('filter');
|
||||
$filterArr = (array)json_decode($filter, true);
|
||||
if (isset($filterArr['category']) && $filterArr['category'] == 'unclassed') {
|
||||
$filterArr['category'] = ',unclassed';
|
||||
$this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['category' => '']))]);
|
||||
}
|
||||
if (isset($filterArr['mimetype']) && preg_match("/(\/|\,|\*)/", $filterArr['mimetype'])) {
|
||||
$mimetype = $filterArr['mimetype'];
|
||||
$filterArr = array_diff_key($filterArr, ['mimetype' => '']);
|
||||
$mimetypeQuery = function ($query) use ($mimetype) {
|
||||
$mimetypeArr = array_filter(explode(',', $mimetype));
|
||||
foreach ($mimetypeArr as $index => $item) {
|
||||
$query->whereOr('mimetype', 'like', '%' . str_replace("/*", "/", $item) . '%');
|
||||
}
|
||||
};
|
||||
}
|
||||
$this->request->get(['filter' => json_encode($filterArr)]);
|
||||
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->where($mimetypeQuery)
|
||||
->where($where)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
|
||||
foreach ($list as $k => &$v) {
|
||||
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
|
||||
}
|
||||
unset($v);
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择附件
|
||||
*/
|
||||
public function select_copy()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
return $this->index();
|
||||
}
|
||||
$mimetype = $this->request->get('mimetype', '');
|
||||
$mimetype = substr($mimetype, -1) === '/' ? $mimetype . '*' : $mimetype;
|
||||
$this->view->assign('mimetype', $mimetype);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索分类
|
||||
* @return \think\response\Json
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function searchNav()
|
||||
{
|
||||
$key = input('param.keyword');
|
||||
$attachmentNavModel = new AttachmentNavModel();
|
||||
$navList = $attachmentNavModel->searchNav($key);
|
||||
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'navList' => $navList
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件选择
|
||||
* @return mixed|\think\response\Json
|
||||
*/
|
||||
public function select()
|
||||
{
|
||||
$multiple = input('param.multiple');
|
||||
if (request()->isAjax()) {
|
||||
$attachmentNavModel = new AttachmentNavModel();
|
||||
$type = input('param.type', '');
|
||||
$key = input('param.keyword', '');
|
||||
|
||||
if ($type == 7 && !empty($key)) {
|
||||
$navList = $attachmentNavModel->searchNav($key);
|
||||
} else if ($type == 7 && empty($key)) {
|
||||
$navList = $attachmentNavModel->getNavList();
|
||||
} else {
|
||||
$navList = $attachmentNavModel->getNavList();
|
||||
}
|
||||
|
||||
$attachmentModel = new AttachmentModel();
|
||||
$page = input('param.page/d', 1);
|
||||
$rows = input('param.rows/d', 20);
|
||||
$nav = input('param.nav/a', '');
|
||||
$nid = input('param.nid/d', '');
|
||||
$category = input('param.category', '');
|
||||
$mimetype = input('param.mimetype', '');
|
||||
$startTime = input('param.start_time', '');
|
||||
$endTime = input('param.end_time', '');
|
||||
$order = input('param.order', '');
|
||||
$result = $attachmentModel->getLists([
|
||||
'keyword' => $key,
|
||||
'type' => $type,
|
||||
'nav' => $nav,
|
||||
'nid' => $nid,
|
||||
'category' => $category,
|
||||
'mimetype' => $mimetype,
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime,
|
||||
'order' => $order,
|
||||
], $rows, $page);
|
||||
|
||||
$result['navList'] = $navList;
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
$this->assign([
|
||||
'multiple' => $multiple
|
||||
]);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if ($this->request->isAjax()) {
|
||||
$this->error();
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除附件
|
||||
* @param array $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
|
||||
if ($ids) {
|
||||
\think\Hook::add('upload_delete', function ($params) {
|
||||
if ($params['storage'] == 'local') {
|
||||
$attachmentFile = ROOT_PATH . '/public' . $params['url'];
|
||||
if (is_file($attachmentFile)) {
|
||||
@unlink($attachmentFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
$attachmentlist = $this->model->where('id', 'in', $ids)->select();
|
||||
foreach ($attachmentlist as $attachment) {
|
||||
\think\Hook::listen("upload_delete", $attachment);
|
||||
$attachment->delete();
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 归类
|
||||
*/
|
||||
public function classify()
|
||||
{
|
||||
if (!$this->auth->check('general/attachment/edit')) {
|
||||
\think\Hook::listen('admin_nopermission', $this);
|
||||
$this->error(__('You have no permission'), '');
|
||||
}
|
||||
if (!$this->request->isPost()) {
|
||||
$this->error(__("Invalid parameters"));
|
||||
}
|
||||
$category = $this->request->post('category', '');
|
||||
$ids = $this->request->post('ids');
|
||||
if (!$ids) {
|
||||
$this->error(__('Parameter %s can not be empty', 'ids'));
|
||||
}
|
||||
$categoryList = \app\common\model\Attachment::getCategoryList();
|
||||
if ($category && !isset($categoryList[$category])) {
|
||||
$this->error(__('Category not found'));
|
||||
}
|
||||
$category = $category == 'unclassed' ? '' : $category;
|
||||
\app\common\model\Attachment::where('id', 'in', $ids)->update(['category' => $category]);
|
||||
$this->success();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\library\Email;
|
||||
use app\common\model\Config as ConfigModel;
|
||||
use think\Cache;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*
|
||||
* @icon fa fa-cogs
|
||||
* @remark 可以在此增改系统的变量和分组,也可以自定义分组和变量,如果需要删除请从数据库中删除
|
||||
*/
|
||||
class Config extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \app\common\model\Config
|
||||
*/
|
||||
protected $model = null;
|
||||
protected $noNeedRight = ['check', 'rulelist', 'selectpage', 'get_fields_list'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
// $this->model = model('Config');
|
||||
$this->model = new ConfigModel;
|
||||
ConfigModel::event('before_write', function ($row) {
|
||||
if (isset($row['name']) && $row['name'] == 'name' && preg_match("/fast" . "admin/i", $row['value'])) {
|
||||
throw new Exception(__("Site name incorrect"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$siteList = [];
|
||||
$groupList = ConfigModel::getGroupList();
|
||||
foreach ($groupList as $k => $v) {
|
||||
$siteList[$k]['name'] = $k;
|
||||
$siteList[$k]['title'] = $v;
|
||||
$siteList[$k]['list'] = [];
|
||||
}
|
||||
|
||||
foreach ($this->model->all() as $k => $v) {
|
||||
if (!isset($siteList[$v['group']])) {
|
||||
continue;
|
||||
}
|
||||
$value = $v->toArray();
|
||||
$value['title'] = __($value['title']);
|
||||
if (in_array($value['type'], ['select', 'selects', 'checkbox', 'radio'])) {
|
||||
$value['value'] = explode(',', $value['value']);
|
||||
}
|
||||
$value['content'] = json_decode($value['content'], true);
|
||||
if (in_array($value['name'], ['categorytype', 'configgroup', 'attachmentcategory'])) {
|
||||
$dictValue = (array)json_decode($value['value'], true);
|
||||
foreach ($dictValue as $index => &$item) {
|
||||
$item = __($item);
|
||||
}
|
||||
unset($item);
|
||||
$value['value'] = json_encode($dictValue, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
$value['tip'] = htmlspecialchars($value['tip']);
|
||||
if ($value['name'] == 'cdnurl') {
|
||||
//cdnurl不支持在线修改
|
||||
continue;
|
||||
}
|
||||
$siteList[$v['group']]['list'][] = $value;
|
||||
}
|
||||
$index = 0;
|
||||
foreach ($siteList as $k => &$v) {
|
||||
$v['active'] = !$index ? true : false;
|
||||
$index++;
|
||||
}
|
||||
$this->view->assign('siteList', $siteList);
|
||||
$this->view->assign('typeList', ConfigModel::getTypeList());
|
||||
$this->view->assign('ruleList', ConfigModel::getRegexList());
|
||||
$this->view->assign('groupList', ConfigModel::getGroupList());
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
if (!config('app_debug')) {
|
||||
$this->error(__('Only work at development environment'));
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a", [], 'trim');
|
||||
if ($params) {
|
||||
foreach ($params as $k => &$v) {
|
||||
$v = is_array($v) && $k !== 'setting' ? implode(',', $v) : $v;
|
||||
}
|
||||
if (in_array($params['type'], ['select', 'selects', 'checkbox', 'radio', 'array'])) {
|
||||
$params['content'] = json_encode(ConfigModel::decode($params['content']), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$params['content'] = '';
|
||||
}
|
||||
try {
|
||||
$result = $this->model->create($params);
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if ($result !== false) {
|
||||
try {
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($this->model->getError());
|
||||
}
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param null $ids
|
||||
*/
|
||||
public function edit($ids = null)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$row = $this->request->post("row/a", [], 'trim');
|
||||
if ($row) {
|
||||
$configList = [];
|
||||
foreach ($this->model->all() as $v) {
|
||||
if (isset($row[$v['name']])) {
|
||||
$value = $row[$v['name']];
|
||||
if (is_array($value) && isset($value['field'])) {
|
||||
$value = json_encode(ConfigModel::getArrayData($value), JSON_UNESCAPED_UNICODE);
|
||||
} else {
|
||||
$value = is_array($value) ? implode(',', $value) : $value;
|
||||
}
|
||||
$v['value'] = $value;
|
||||
$configList[] = $v->toArray();
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->model->allowField(true)->saveAll($configList);
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
try {
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
}
|
||||
$this->error(__('Parameter %s can not be empty', ''));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param string $ids
|
||||
*/
|
||||
public function del($ids = "")
|
||||
{
|
||||
if (!config('app_debug')) {
|
||||
$this->error(__('Only work at development environment'));
|
||||
}
|
||||
$name = $this->request->post('name');
|
||||
$config = ConfigModel::getByName($name);
|
||||
if ($name && $config) {
|
||||
try {
|
||||
$config->delete();
|
||||
ConfigModel::refreshFile();
|
||||
} catch (Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测配置项是否存在
|
||||
* @internal
|
||||
*/
|
||||
public function check()
|
||||
{
|
||||
$params = $this->request->post("row/a");
|
||||
if ($params) {
|
||||
$config = $this->model->get($params);
|
||||
if (!$config) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error(__('Name already exist'));
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 规则列表
|
||||
* @internal
|
||||
*/
|
||||
public function rulelist()
|
||||
{
|
||||
//主键
|
||||
$primarykey = $this->request->request("keyField");
|
||||
//主键值
|
||||
$keyValue = $this->request->request("keyValue", "");
|
||||
|
||||
$keyValueArr = array_filter(explode(',', $keyValue));
|
||||
$regexList = \app\common\model\Config::getRegexList();
|
||||
$list = [];
|
||||
foreach ($regexList as $k => $v) {
|
||||
if ($keyValueArr) {
|
||||
if (in_array($k, $keyValueArr)) {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
} else {
|
||||
$list[] = ['id' => $k, 'name' => $v];
|
||||
}
|
||||
}
|
||||
return json(['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送测试邮件
|
||||
* @internal
|
||||
*/
|
||||
public function emailtest()
|
||||
{
|
||||
$row = $this->request->post('row/a');
|
||||
$receiver = $this->request->post("receiver");
|
||||
if ($receiver) {
|
||||
if (!Validate::is($receiver, "email")) {
|
||||
$this->error(__('Please input correct email'));
|
||||
}
|
||||
\think\Config::set('site', array_merge(\think\Config::get('site'), $row));
|
||||
$email = new Email;
|
||||
$result = $email
|
||||
->to($receiver)
|
||||
->subject(__("This is a test mail", config('site.name')))
|
||||
->message('<div style="min-height:550px; padding: 100px 55px 200px;">' . __('This is a test mail content', config('site.name')) . '</div>')
|
||||
->send();
|
||||
if ($result) {
|
||||
$this->success();
|
||||
} else {
|
||||
$this->error($email->getError());
|
||||
}
|
||||
} else {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
}
|
||||
|
||||
public function selectpage()
|
||||
{
|
||||
$id = $this->request->get("id/d");
|
||||
$config = \app\common\model\Config::get($id);
|
||||
if (!$config) {
|
||||
$this->error(__('Invalid parameters'));
|
||||
}
|
||||
$setting = $config['setting'];
|
||||
//自定义条件
|
||||
$custom = isset($setting['conditions']) ? (array)json_decode($setting['conditions'], true) : [];
|
||||
$custom = array_filter($custom);
|
||||
|
||||
$this->request->request(['showField' => $setting['field'], 'keyField' => $setting['primarykey'], 'custom' => $custom, 'searchField' => [$setting['field'], $setting['primarykey']]]);
|
||||
$this->model = \think\Db::connect()->setTable($setting['table']);
|
||||
return parent::selectpage();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表列表
|
||||
* @internal
|
||||
*/
|
||||
public function get_table_list()
|
||||
{
|
||||
$tableList = [];
|
||||
$dbname = \think\Config::get('database.database');
|
||||
$tableList = \think\Db::query("SELECT `TABLE_NAME` AS `name`,`TABLE_COMMENT` AS `title` FROM `information_schema`.`TABLES` where `TABLE_SCHEMA` = '{$dbname}';");
|
||||
$this->success('', null, ['tableList' => $tableList]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表字段列表
|
||||
* @internal
|
||||
*/
|
||||
public function get_fields_list()
|
||||
{
|
||||
$table = $this->request->request('table');
|
||||
$dbname = \think\Config::get('database.database');
|
||||
//从数据库中获取表字段信息
|
||||
$sql = "SELECT `COLUMN_NAME` AS `name`,`COLUMN_COMMENT` AS `title`,`DATA_TYPE` AS `type` FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION";
|
||||
//加载主表的列
|
||||
$fieldList = Db::query($sql, [$dbname, $table]);
|
||||
$this->success("", null, ['fieldList' => $fieldList]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\AttachmentModel;
|
||||
use app\common\model\AttachmentNavModel;
|
||||
|
||||
/**
|
||||
* 文件管理
|
||||
* Class File
|
||||
* @package app\admin\controller\general
|
||||
*/
|
||||
class File extends Backend
|
||||
{
|
||||
/**
|
||||
* @var \app\common\model\AttachmentModel
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new AttachmentModel();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$multiple = input('param.multiple');
|
||||
$select = input('param.select');
|
||||
|
||||
if (request()->isAjax()) {
|
||||
$page = input('param.page/d', 1);
|
||||
$rows = input('param.rows/d', 50);
|
||||
$key = input('param.keyword', '');
|
||||
$type = input('param.type', 1);
|
||||
$nav = input('param.nav/d', '');
|
||||
$order = input('param.order/d', 2);
|
||||
$navData = getNavArrData($nav);
|
||||
$result = $this->model->getLists([
|
||||
'keyword' => $key,
|
||||
'type' => $type,
|
||||
'nav' => $navData,
|
||||
'is_del' => 0,
|
||||
'order' => $order
|
||||
], $rows, $page);
|
||||
|
||||
if (!empty($result['list'])) {
|
||||
foreach ($result['list'] as &$v) {
|
||||
$v['checked'] = false;
|
||||
$v['showTools'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
$attachmentNavModel = new AttachmentNavModel();
|
||||
$result['navList'] = $attachmentNavModel->getNavList();
|
||||
|
||||
// 追加一个全部图片
|
||||
array_unshift($result['navList'], [
|
||||
'value' => 0,
|
||||
'label' => '全部图片',
|
||||
'children' => []
|
||||
]);
|
||||
|
||||
$breadcrumb = [['id' => 0, 'name' => '全部图片']];
|
||||
|
||||
// 排序
|
||||
$sort = 'id DESC';
|
||||
switch ($order) {
|
||||
case 1 :
|
||||
$sort = 'id ASC';
|
||||
break;
|
||||
case 2 :
|
||||
$sort = 'id DESC';
|
||||
break;
|
||||
case 3 :
|
||||
$sort = 'letter ASC';
|
||||
break;
|
||||
case 4 :
|
||||
$sort = 'letter DESC';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!empty($navData)) {
|
||||
if (count($navData) == 1) {
|
||||
$condition = !empty($key) ? ['pid' => $navData[0], 'name' => ['LIKE', '%' . $key . '%']] : ['pid' => $navData[0]];
|
||||
$dirList = $attachmentNavModel
|
||||
->where($condition)
|
||||
->field(['id' => 'value', 'name' => 'label'])
|
||||
->order($sort)
|
||||
->select();
|
||||
$breadcrumb[] = $this->getNavData($navData[0], $attachmentNavModel);
|
||||
} else {
|
||||
$dirList = [];
|
||||
$breadcrumb[] = $this->getNavData($navData[0], $attachmentNavModel);
|
||||
$breadcrumb[] = $this->getNavData($navData[1], $attachmentNavModel);
|
||||
}
|
||||
} else {
|
||||
$condition = !empty($key) ? ['pid' => 0, 'name' => ['LIKE', '%' . $key . '%']] : ['pid' => 0];
|
||||
$dirList = $attachmentNavModel
|
||||
->where($condition)
|
||||
->field(['id' => 'value', 'name' => 'label'])
|
||||
->order($sort)
|
||||
->select();
|
||||
}
|
||||
|
||||
$result['dirList'] = $dirList;
|
||||
$result['breadcrumb'] = $breadcrumb;
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
$this->assign([
|
||||
'multiple' => $multiple,
|
||||
'select' => $select,
|
||||
]);
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 归类
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function nav()
|
||||
{
|
||||
$data = input('post.');
|
||||
if ($this->model->nav($data)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '归类成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '归类失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function dell($ids)
|
||||
{
|
||||
$ids = $ids ? $ids : $this->request->post("ids");
|
||||
$ids = explode(',', $ids);
|
||||
|
||||
$res = $this->model->transaction(function () use ($ids) {
|
||||
foreach ($ids as $v) {
|
||||
$this->model->update([
|
||||
'id' => $v,
|
||||
'is_del' => 1
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!empty($res)) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '删除成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '删除失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 回收站
|
||||
public function recycle()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$page = input('param.page/d', 1);
|
||||
$rows = input('param.rows/d', 20);
|
||||
$key = input('param.keyword', '');
|
||||
$type = input('param.type', '');
|
||||
$category = input('param.category', '');
|
||||
$mimetype = input('param.mimetype', '');
|
||||
$startTime = input('param.start_time', '');
|
||||
$endTime = input('param.end_time', '');
|
||||
$result = $this->model->getLists([
|
||||
'is_del' => 1,
|
||||
'keyword' => $key,
|
||||
'type' => $type,
|
||||
'category' => $category,
|
||||
'mimetype' => $mimetype,
|
||||
'start_time' => $startTime,
|
||||
'end_time' => $endTime,
|
||||
], $rows, $page);
|
||||
|
||||
$attachmentNavModel = new AttachmentNavModel();
|
||||
|
||||
if (!empty($result['list'])) {
|
||||
foreach ($result['list'] as &$v) {
|
||||
if (empty($v['one_id']) && empty($v['two_id'])) {
|
||||
$v['navName'] = '暂无分类';
|
||||
} else if (!empty($v['one_id']) && empty($v['two_id'])) {
|
||||
$v['navName'] = $this->getNavData($v['one_id'], $attachmentNavModel);
|
||||
} else {
|
||||
$v['navName'] = $this->getNavData($v['one_id'], $attachmentNavModel) . '/' . $this->getNavData($v['two_id'], $attachmentNavModel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return json($result);
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复
|
||||
* @param null $ids
|
||||
* @return \think\response\Json|void
|
||||
*/
|
||||
public function restoreData()
|
||||
{
|
||||
$ids = $this->request->post("ids");
|
||||
$ids = explode(',', $ids);
|
||||
|
||||
$res = $this->model->transaction(function () use ($ids) {
|
||||
foreach ($ids as $v) {
|
||||
$this->model->update([
|
||||
'id' => $v,
|
||||
'is_del' => 0
|
||||
]);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!empty($res)) {
|
||||
return json([
|
||||
'code' => 1,
|
||||
'msg' => '恢复成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '恢复失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getNavData($id, $attachmentNavModel)
|
||||
{
|
||||
return $attachmentNavModel
|
||||
->where(['id' => $id])
|
||||
->field(['id', 'name'])
|
||||
->find();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\common\controller\Backend;
|
||||
use app\common\model\AttachmentModel;
|
||||
use app\common\model\AttachmentNavModel;
|
||||
use think\Db;
|
||||
|
||||
/**
|
||||
* 附件分类管理控制器
|
||||
* Class Nav
|
||||
* @package app\admin\controller\general
|
||||
*/
|
||||
class Nav extends Backend
|
||||
{
|
||||
|
||||
/**
|
||||
* Attachment模型对象
|
||||
* @var \app\common\model\AttachmentNavModel
|
||||
*/
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new AttachmentNavModel();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
||||
* 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
||||
* 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
||||
*/
|
||||
|
||||
/**
|
||||
* 获取列表
|
||||
* @return mixed|string|\think\response\Json
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
if (request()->isAjax()) {
|
||||
$list = Db::name('attachment_nav')
|
||||
->where(['pid' => 0])
|
||||
->select();
|
||||
if (!empty($list)) {
|
||||
foreach ($list as &$v) {
|
||||
$v['children'] = Db::name('attachment_nav')
|
||||
->where(['pid' => $v['id']])
|
||||
->select();
|
||||
}
|
||||
}
|
||||
|
||||
return json([
|
||||
'list' => $list
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
// 添加/编辑
|
||||
public function add()
|
||||
{
|
||||
$data = input('post.');
|
||||
if (!empty($data)) {
|
||||
// 添加
|
||||
if (empty($data['id'])) {
|
||||
unset($data['id']);
|
||||
$data['create_time'] = time();
|
||||
if ($this->model->add($data)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '添加成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '添加失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑
|
||||
$data['update_time'] = time();
|
||||
if ($this->model->edit($data)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '编辑成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '编辑失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改状态
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
$data = input('param.');
|
||||
$editData = [
|
||||
'id' => $data['id'],
|
||||
'status' => $data['status']
|
||||
];
|
||||
|
||||
if ($this->model->edit($editData)) {
|
||||
return json([
|
||||
'code' => 200,
|
||||
'msg' => '更改成功'
|
||||
]);
|
||||
} else {
|
||||
return json([
|
||||
'code' => 400,
|
||||
'msg' => '更改失败'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除
|
||||
public function dell(AttachmentModel $attachmentModel)
|
||||
{
|
||||
$id = input('id');
|
||||
if (!empty($id)) {
|
||||
$ids = strpos($id, ',') !== false ? explode(',', $id) : [$id];
|
||||
foreach ($ids as $v) {
|
||||
if (!$this->model->getItem((int)$v)) {
|
||||
return json(['code' => 401, 'msg' => '您要删除掉分类不存在']);
|
||||
}
|
||||
if ($this->model->where(['pid' => $v])->value('id')) {
|
||||
return json(['code' => 402, 'msg' => '当前分类下还有子类暂无法删除']);
|
||||
}
|
||||
if ($attachmentModel->where(['nid' => $v])->value('id')) {
|
||||
return json(['code' => 403, 'msg' => '当前分类下有附件暂无法删除']);
|
||||
}
|
||||
}
|
||||
foreach ($ids as $v) {
|
||||
$this->model->del(['id' => $v]);
|
||||
}
|
||||
return json(['code' => 200, 'msg' => '删除成功']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller\general;
|
||||
|
||||
use app\admin\model\Admin;
|
||||
use app\common\controller\Backend;
|
||||
use fast\Random;
|
||||
use think\Session;
|
||||
use think\Validate;
|
||||
|
||||
/**
|
||||
* 个人配置
|
||||
*
|
||||
* @icon fa fa-user
|
||||
*/
|
||||
class Profile extends Backend
|
||||
{
|
||||
|
||||
protected $searchFields = 'id,title';
|
||||
|
||||
/**
|
||||
* 查看
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//设置过滤方法
|
||||
$this->request->filter(['strip_tags', 'trim']);
|
||||
if ($this->request->isAjax()) {
|
||||
$this->model = model('AdminLog');
|
||||
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
||||
|
||||
$list = $this->model
|
||||
->where($where)
|
||||
->where('admin_id', $this->auth->id)
|
||||
->order($sort, $order)
|
||||
->paginate($limit);
|
||||
|
||||
$result = array("total" => $list->total(), "rows" => $list->items());
|
||||
|
||||
return json($result);
|
||||
}
|
||||
return $this->view->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新个人信息
|
||||
*/
|
||||
public function update()
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post("row/a");
|
||||
$params = array_filter(array_intersect_key(
|
||||
$params,
|
||||
array_flip(array('email', 'nickname', 'password', 'avatar'))
|
||||
));
|
||||
unset($v);
|
||||
if (!Validate::is($params['email'], "email")) {
|
||||
$this->error(__("Please input correct email"));
|
||||
}
|
||||
if (isset($params['password'])) {
|
||||
if (!Validate::is($params['password'], "/^[\S]{6,30}$/")) {
|
||||
$this->error(__("Please input correct password"));
|
||||
}
|
||||
$params['salt'] = Random::alnum();
|
||||
$params['password'] = md5(md5($params['password']) . $params['salt']);
|
||||
}
|
||||
$exist = Admin::where('email', $params['email'])->where('id', '<>', $this->auth->id)->find();
|
||||
if ($exist) {
|
||||
$this->error(__("Email already exists"));
|
||||
}
|
||||
if ($params) {
|
||||
$admin = Admin::get($this->auth->id);
|
||||
$admin->save($params);
|
||||
//因为个人资料面板读取的Session显示,修改自己资料后同时更新Session
|
||||
Session::set("admin", $admin->toArray());
|
||||
$this->success();
|
||||
}
|
||||
$this->error();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户