Pre Merge pull request !503 from mrcdh/1.x-dev

pull/503/MERGE
mrcdh 2025-09-03 09:56:28 +00:00 committed by Gitee
commit 4e47b6586b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
15 changed files with 56 additions and 67 deletions

View File

@ -3,7 +3,6 @@
namespace app\admin\controller;
use app\common\controller\Backend;
use fast\Http;
use think\addons\AddonException;
use think\addons\Service;
use think\Cache;
@ -36,7 +35,7 @@ class Addon extends Backend
public function index()
{
$addons = get_addon_list();
foreach ($addons as $k => &$v) {
foreach ($addons as &$v) {
$config = get_addon_config($v['name']);
$v['config'] = $config ? 1 : 0;
$v['url'] = str_replace($this->request->server('SCRIPT_NAME'), '', $v['url']);
@ -50,7 +49,7 @@ class Addon extends Backend
*/
public function config($name = null)
{
$name = $name ? $name : $this->request->get("name");
$name = $name ?: $this->request->get("name");
if (!$name) {
$this->error(__('Parameter %s can not be empty', 'name'));
}
@ -65,7 +64,7 @@ class Addon extends Backend
if ($this->request->isPost()) {
$params = $this->request->post("row/a", [], 'trim');
if ($params) {
foreach ($config as $k => &$v) {
foreach ($config as &$v) {
if (isset($params[$v['name']])) {
if ($v['type'] == 'array') {
$params[$v['name']] = is_array($params[$v['name']]) ? $params[$v['name']] : (array)json_decode($params[$v['name']], true);
@ -179,7 +178,7 @@ class Addon extends Backend
if ($tables) {
$prefix = Config::get('database.prefix');
//删除插件关联表
foreach ($tables as $index => $table) {
foreach ($tables as $table) {
//忽略非插件标识的表名
if (!preg_match("/^{$prefix}{$name}/", $table)) {
continue;
@ -331,7 +330,7 @@ class Addon extends Backend
$filter = (array)json_decode($filter, true);
$addons = get_addon_list();
$list = [];
foreach ($addons as $k => $v) {
foreach ($addons as $v) {
if ($search && stripos($v['name'], $search) === false && stripos($v['title'], $search) === false && stripos($v['intro'], $search) === false) {
continue;
}
@ -448,7 +447,7 @@ class Addon extends Backend
}
$rows = $json['rows'] ?? [];
foreach ($rows as $index => $row) {
foreach ($rows as $row) {
if (!isset($row['name'])) {
continue;
}

View File

@ -6,7 +6,6 @@ use app\admin\model\AdminLog;
use app\common\controller\Backend;
use app\common\exception\UploadException;
use app\common\library\Upload;
use fast\Random;
use think\addons\Service;
use think\Cache;
use think\Config;
@ -14,7 +13,6 @@ use think\Db;
use think\Lang;
use think\Loader;
use think\Response;
use think\Validate;
/**
* Ajax异步请求接口
@ -231,7 +229,6 @@ class Ajax extends Backend
$type = $this->request->get('type', '');
$pid = $this->request->get('pid', '');
$where = ['status' => 'normal'];
$categorylist = null;
if ($pid || $pid === '0') {
$where['pid'] = $pid;
}
@ -258,7 +255,6 @@ class Ajax extends Backend
$city = $this->request->get('city');
}
$where = ['pid' => 0, 'level' => 1];
$provincelist = null;
if ($province !== null) {
$where['pid'] = $province;
$where['level'] = 2;
@ -277,7 +273,7 @@ class Ajax extends Backend
public function icon()
{
$suffix = $this->request->request("suffix");
$suffix = $suffix ? $suffix : "FILE";
$suffix = $suffix ?: "FILE";
$data = build_suffix_image($suffix);
$header = ['Content-Type' => 'image/svg+xml'];
$offset = 30 * 60 * 60 * 24; // 缓存一个月

View File

@ -16,7 +16,7 @@ class Category extends Backend
{
/**
* @var \app\common\model\Category
* @var CategoryModel
*/
protected $model = null;
protected $categorylist = [];
@ -31,7 +31,7 @@ class Category extends Backend
$tree->init(collection($this->model->order('weigh desc,id desc')->select())->toArray(), 'pid');
$this->categorylist = $tree->getTreeList($tree->getTreeArray(0), 'name');
$categorydata = [0 => ['type' => 'all', 'name' => __('None')]];
foreach ($this->categorylist as $k => $v) {
foreach ($this->categorylist as $v) {
$categorydata[$v['id']] = $v;
}
$typeList = CategoryModel::getTypeList();
@ -55,7 +55,7 @@ class Category extends Backend
//构造父类select列表选项数据
$list = [];
foreach ($this->categorylist as $k => $v) {
foreach ($this->categorylist as $v) {
if ($search) {
if ($v['type'] == $type && stripos($v['name'], $search) !== false || stripos($v['nickname'], $search) !== false) {
if ($type == "all" || $type == null) {
@ -114,7 +114,7 @@ class Category extends Backend
$params = $this->preExcludeFields($params);
if ($params['pid'] != $row['pid']) {
$childrenIds = Tree::instance()->init(collection(\app\common\model\Category::select())->toArray())->getChildrenIds($row['id'], true);
$childrenIds = Tree::instance()->init(collection(CategoryModel::select())->toArray())->getChildrenIds($row['id'], true);
if (in_array($params['pid'], $childrenIds)) {
$this->error(__('Can not change the parent to child or itself'));
}

View File

@ -40,7 +40,7 @@ class Dashboard extends Backend
$time += 86400;
}
$userlist = array_fill_keys($column, 0);
foreach ($joinlist as $k => $v) {
foreach ($joinlist as $v) {
$userlist[$v['join_date']] = $v['nums'];
}
@ -48,7 +48,7 @@ class Dashboard extends Backend
$addonList = get_addon_list();
$totalworkingaddon = 0;
$totaladdon = count($addonList);
foreach ($addonList as $index => $item) {
foreach ($addonList as $item) {
if ($item['state']) {
$totalworkingaddon += 1;
}

View File

@ -109,7 +109,7 @@ class Index extends Backend
$this->success(__('Login successful'), $url, ['url' => $url, 'id' => $this->auth->id, 'username' => $username, 'avatar' => $this->auth->avatar]);
} else {
$msg = $this->auth->getError();
$msg = $msg ? $msg : __('Username or password is incorrect');
$msg = $msg ?: __('Username or password is incorrect');
$this->error($msg, $url, ['token' => $this->request->token()]);
}
}

View File

@ -42,16 +42,16 @@ class Admin extends Backend
$groupdata = [];
if ($this->auth->isSuperAdmin()) {
$result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
foreach ($result as $k => $v) {
foreach ($result as $v) {
$groupdata[$v['id']] = $v['name'];
}
} else {
$result = [];
$groups = $this->auth->getGroups();
foreach ($groups as $m => $n) {
foreach ($groups as $n) {
$childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
$temp = [];
foreach ($childlist as $k => $v) {
foreach ($childlist as $v) {
$temp[$v['id']] = $v['name'];
}
$result[__($n['name'])] = $temp;
@ -83,13 +83,13 @@ class Admin extends Backend
->select();
$adminGroupName = [];
foreach ($authGroupList as $k => $v) {
foreach ($authGroupList as $v) {
if (isset($groupName[$v['group_id']])) {
$adminGroupName[$v['uid']][$v['group_id']] = $groupName[$v['group_id']];
}
}
$groups = $this->auth->getGroups();
foreach ($groups as $m => $n) {
foreach ($groups as $n) {
$adminGroupName[$this->auth->id][$n['id']] = $n['name'];
}
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
@ -101,8 +101,8 @@ class Admin extends Backend
->order($sort, $order)
->paginate($limit);
foreach ($list as $k => &$v) {
$groups = isset($adminGroupName[$v['id']]) ? $adminGroupName[$v['id']] : [];
foreach ($list as &$v) {
$groups = $adminGroupName[$v['id']] ?? [];
$v['groups'] = implode(',', array_keys($groups));
$v['groups_text'] = implode(',', array_values($groups));
}
@ -227,7 +227,7 @@ class Admin extends Backend
}
$grouplist = $this->auth->getGroups($row['id']);
$groupids = [];
foreach ($grouplist as $k => $v) {
foreach ($grouplist as $v) {
$groupids[] = $v['id'];
}
$this->view->assign("row", $row);
@ -243,7 +243,7 @@ class Admin extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
$ids = array_intersect($this->childrenAdminIds, array_filter(explode(',', $ids)));
// 避免越权删除管理员
@ -253,7 +253,7 @@ class Admin extends Backend
})->select();
if ($adminList) {
$deleteIds = [];
foreach ($adminList as $k => $v) {
foreach ($adminList as $v) {
$deleteIds[] = $v->id;
}
$deleteIds = array_values(array_diff($deleteIds, [$this->auth->id]));

View File

@ -2,7 +2,6 @@
namespace app\admin\controller\auth;
use app\admin\model\AuthGroup;
use app\common\controller\Backend;
/**
@ -100,7 +99,7 @@ class Adminlog extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
$isSuperAdmin = $this->auth->isSuperAdmin();
$childrenAdminIds = $this->childrenAdminIds;

View File

@ -3,7 +3,6 @@
namespace app\admin\controller\auth;
use app\admin\model\AuthGroup;
use app\admin\model\AuthGroupAccess;
use app\common\controller\Backend;
use fast\Tree;
use think\Db;
@ -19,7 +18,7 @@ class Group extends Backend
{
/**
* @var \app\admin\model\AuthGroup
* @var AuthGroup
*/
protected $model = null;
//当前登录管理员所有子组别
@ -59,7 +58,7 @@ class Group extends Backend
$groupList = $tree->getTreeList($tree->getTreeArray(0));
}
$groupName = [];
foreach ($groupList as $k => $v) {
foreach ($groupList as $v) {
$groupName[$v['id']] = $v['name'];
}
@ -191,7 +190,7 @@ class Group extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
$ids = explode(',', $ids);
$grouplist = $this->auth->getGroups();
@ -215,7 +214,6 @@ class Group extends Backend
$groupone = $this->model->get(['pid' => $v['id']]);
if ($groupone) {
$ids = array_diff($ids, [$v['id']]);
continue;
}
}
if (!$ids) {
@ -257,7 +255,7 @@ class Group extends Backend
$currentGroupModel = $model->get($id);
}
if (($pid || $parentGroupModel) && (!$id || $currentGroupModel)) {
$id = $id ? $id : null;
$id = $id ?: null;
$ruleList = collection(model('AuthRule')->order('weigh', 'desc')->order('id', 'asc')->select())->toArray();
//读取父类角色所有节点列表
$parentRuleList = [];
@ -265,7 +263,7 @@ class Group extends Backend
$parentRuleList = $ruleList;
} else {
$parentRuleIds = explode(',', $parentGroupModel->rules);
foreach ($ruleList as $k => $v) {
foreach ($ruleList as $v) {
if (in_array($v['id'], $parentRuleIds)) {
$parentRuleList[] = $v;
}
@ -289,7 +287,7 @@ class Group extends Backend
if (!$id || !in_array($pid, $this->childrenGroupIds) || !in_array($pid, $groupTree->getChildrenIds($id, true))) {
$parentRuleList = $ruleTree->getTreeList($ruleTree->getTreeArray(0), 'name');
$hasChildrens = [];
foreach ($parentRuleList as $k => $v) {
foreach ($parentRuleList as $v) {
if ($v['haschild']) {
$hasChildrens[] = $v['id'];
}
@ -306,7 +304,7 @@ class Group extends Backend
continue;
}
$state = array('selected' => in_array($v['id'], $currentRuleIds) && !in_array($v['id'], $hasChildrens));
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ? $v['pid'] : '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
$nodeList[] = array('id' => $v['id'], 'parent' => $v['pid'] ?: '#', 'text' => __($v['title']), 'type' => 'menu', 'state' => $state);
}
$this->success('', null, $nodeList);
} else {

View File

@ -6,8 +6,6 @@ use app\admin\model\AuthRule;
use app\common\controller\Backend;
use fast\Tree;
use think\Cache;
use think\db\Query;
use think\exception\HttpResponseException;
/**
* 规则管理
@ -19,7 +17,7 @@ class Rule extends Backend
{
/**
* @var \app\admin\model\AuthRule
* @var AuthRule
*/
protected $model = null;
protected $rulelist = [];
@ -34,14 +32,14 @@ class Rule extends Backend
$this->model = model('AuthRule');
// 必须将结果集转换为数组
$ruleList = \think\Db::name("auth_rule")->field('type,condition,remark,menutype,extend,pinyin,py,createtime,updatetime', true)->order('weigh DESC,id ASC')->select();
foreach ($ruleList as $k => &$v) {
foreach ($ruleList as &$v) {
$v['title'] = __($v['title']);
}
unset($v);
Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    '];
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
$ruledata = [0 => __('None')];
foreach ($this->rulelist as $k => &$v) {
foreach ($this->rulelist as &$v) {
if (!$v['ismenu']) {
continue;
}
@ -141,10 +139,10 @@ class Rule extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
$delIds = [];
foreach (explode(',', $ids) as $k => $v) {
foreach (explode(',', $ids) as $v) {
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true));
}
$delIds = array_unique($delIds);

View File

@ -66,7 +66,7 @@ class Attachment extends Backend
->paginate($limit);
$cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root(true));
foreach ($list as $k => &$v) {
foreach ($list as &$v) {
$v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
}
unset($v);
@ -111,7 +111,7 @@ class Attachment extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
\think\Hook::add('upload_delete', function ($params) {
if ($params['storage'] == 'local') {

View File

@ -5,7 +5,6 @@ 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;
@ -20,7 +19,7 @@ class Config extends Backend
{
/**
* @var \app\common\model\Config
* @var ConfigModel
*/
protected $model = null;
protected $noNeedRight = ['check', 'rulelist', 'selectpage', 'get_fields_list'];
@ -62,7 +61,7 @@ class Config extends Backend
$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) {
foreach ($dictValue as &$item) {
$item = __($item);
}
unset($item);
@ -76,8 +75,8 @@ class Config extends Backend
$siteList[$v['group']]['list'][] = $value;
}
$index = 0;
foreach ($siteList as $k => &$v) {
$v['active'] = !$index ? true : false;
foreach ($siteList as &$v) {
$v['active'] = !$index;
$index++;
}
$this->view->assign('siteList', $siteList);
@ -222,7 +221,7 @@ class Config extends Backend
$keyValue = $this->request->request("keyValue", "");
$keyValueArr = array_filter(explode(',', $keyValue));
$regexList = \app\common\model\Config::getRegexList();
$regexList = ConfigModel::getRegexList();
$list = [];
foreach ($regexList as $k => $v) {
if ($keyValueArr) {
@ -268,7 +267,7 @@ class Config extends Backend
public function selectpage()
{
$id = $this->request->get("id/d");
$config = \app\common\model\Config::get($id);
$config = ConfigModel::get($id);
if (!$config) {
$this->error(__('Invalid parameters'));
}

View File

@ -78,6 +78,5 @@ class Profile extends Backend
}
$this->error();
}
return;
}
}

View File

@ -27,7 +27,7 @@ class Rule extends Backend
$this->view->assign("statusList", $this->model->getStatusList());
// 必须将结果集转换为数组
$ruleList = collection($this->model->order('weigh', 'desc')->select())->toArray();
foreach ($ruleList as $k => &$v) {
foreach ($ruleList as &$v) {
$v['title'] = __($v['title']);
$v['remark'] = __($v['remark']);
}
@ -35,7 +35,7 @@ class Rule extends Backend
Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    '];
$this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title');
$ruledata = [0 => __('None')];
foreach ($this->rulelist as $k => &$v) {
foreach ($this->rulelist as &$v) {
if (!$v['ismenu']) {
continue;
}
@ -90,10 +90,10 @@ class Rule extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
if ($ids) {
$delIds = [];
foreach (explode(',', $ids) as $k => $v) {
foreach (explode(',', $ids) as $v) {
$delIds = array_merge($delIds, Tree::instance()->getChildrenIds($v, true));
}
$delIds = array_unique($delIds);

View File

@ -2,6 +2,7 @@
namespace app\admin\controller\user;
use app\admin\model\UserGroup;
use app\common\controller\Backend;
use app\common\library\Auth;
@ -44,12 +45,12 @@ class User extends Backend
->where($where)
->order($sort, $order)
->paginate($limit);
foreach ($list as $k => $v) {
foreach ($list as $v) {
$v->avatar = $v->avatar ? cdnurl($v->avatar, true) : letter_avatar($v->nickname);
$v->hidden(['password', 'salt']);
}
$rows = $list->items();
addtion($rows, [['field' => 'group_id', 'display' => 'group_name', 'model' => \app\admin\model\UserGroup::class]]);
addtion($rows, [['field' => 'group_id', 'display' => 'group_name', 'model' => UserGroup::class]]);
$result = array("total" => $list->total(), "rows" => $rows);
return json($result);
@ -81,7 +82,7 @@ class User extends Backend
if (!$row) {
$this->error(__('No Results were found'));
}
$this->view->assign('groupList', build_select('row[group_id]', \app\admin\model\UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
$this->view->assign('groupList', build_select('row[group_id]', UserGroup::column('id,name'), $row['group_id'], ['class' => 'form-control selectpicker']));
return parent::edit($ids);
}
@ -93,7 +94,7 @@ class User extends Backend
if (!$this->request->isPost()) {
$this->error(__("Invalid parameters"));
}
$ids = $ids ? $ids : $this->request->post("ids");
$ids = $ids ?: $this->request->post("ids");
$row = $this->model->get($ids);
$this->modelValidate = true;
if (!$row) {

View File

@ -521,7 +521,7 @@ trait Backend
$database = \think\Config::get('database.database');
$fieldArr = [];
$list = db()->query("SELECT COLUMN_NAME,COLUMN_COMMENT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ?", [$table, $database]);
foreach ($list as $k => $v) {
foreach ($list as $v) {
if ($importHeadType == 'comment') {
$v['COLUMN_COMMENT'] = explode(':', $v['COLUMN_COMMENT'])[0]; //字段备注有:时截取
$fieldArr[$v['COLUMN_COMMENT']] = $v['COLUMN_NAME'];
@ -575,7 +575,7 @@ trait Backend
try {
//是否包含admin_id字段
$has_admin_id = false;
foreach ($fieldArr as $name => $key) {
foreach ($fieldArr as $key) {
if ($key == 'admin_id') {
$has_admin_id = true;
break;