first commit

This commit is contained in:
Mr.Qin
2022-08-19 19:48:37 +08:00
commit afdd648b65
3275 changed files with 631084 additions and 0 deletions

View File

@@ -0,0 +1,65 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\AdminController;
use app\common\library\ResultCode;
use app\common\library\Upload;
/**
* Ajax类
* Class Ajax
* @package app\admin\controller
*/
class Ajax extends AdminController
{
/**
* 测试接口
* @return \support\Response
*/
public function index(): \support\Response
{
return json(ResultCode::SUCCESS);
}
/**
* 文件上传
* @return \support\Response|void
* @throws \Exception
*/
public function upload()
{
if (request()->isPost()) {
$file = Upload::instance()->upload();
if (!$file) {
return $this->error(Upload::instance()->getError());
}
return json($file);
}
}
/**
* 远程下载图片
* @return mixed
*/
public function getImage()
{
if (request()->isPost()) {
$file = Upload::instance()->download(input('url'));
if (!$file) {
return $this->error(Upload::instance()->getError());
}
return json($file);
}
}
}

View File

@@ -0,0 +1,364 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\AdminController;
use app\common\library\Email;
use app\common\library\Ftp;
use think\cache\driver\Memcached;
use think\cache\driver\Redis;
use Webman\Event\Event;
use app\common\model\system\Attachment;
use app\common\model\system\Config;
use app\common\model\system\User;
use app\common\model\system\UserGroup;
use app\common\model\system\UserThird;
use app\common\model\system\UserValidate;
use system\Random;
use think\facade\Db;
class Index extends AdminController
{
public function __construct()
{
parent::__construct();
}
/**
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\DataNotFoundException
* @throws \Exception
*/
public function index()
{
return view('index/index');
}
/**
* 控制台首页
* @return mixed
* @throws \think\db\exception\BindParamException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function console()
{
$dataList = [];
$dateBefore = date('Y-m-d', strtotime('-30 day'));
$dateAfter = date('Y-m-d 23:59:59');
if (request()->isPost()) {
$cycle = input('cycle');
if (Event::hasListener('cmsuserEcharts')) {
[$dataList, $seriesList] = Event::emit('cmsuserEcharts', $cycle, true);
if (empty($seriesList)) {
return $this->error('暂无数据');
}
$userChartsOptions = $this->getEchartsData(array_values($dataList), $seriesList);
return $this->success('操作成功', '', $userChartsOptions);
}
return $this->error('请安装CMS插件');
}
for ($i = -29; $i <= 0; $i++) {
$dataList[date('m-d', strtotime($i . ' day'))] = date('m-d', strtotime($i . ' day'));
}
$seriesList = [];
$condition = '%m-%d';
$columns = ['用户注册' => 'create_time', '用户登录' => 'login_time', '邀请注册' => 'invite_id'];
foreach ($columns as $index => $field) {
$time = str_replace('invite_id', 'create_time', $field);
$resultList = User::where($time, 'between time', [$dateBefore, $dateAfter])
->when($condition, function ($query) use ($condition, $time, $field) {
$query->field("FROM_UNIXTIME($time, '$condition') as day,count(*) as count");
if ($field == 'invite_id') {
$query->where('invite_id', '<>', 0);
}
$query->group($time);
})->select()->toArray();
$tempList = [];
foreach ($dataList as $key => $item) {
$data = list_search($resultList, ['day' => $item]);
if (!empty($data)) {
$tempList[$key] = $data;
} else {
$tempList[$key] = ['day' => $item, 'count' => 0];
}
}
$seriesList[] = [
'name' => $index,
'type' => 'line',
'stack' => 'Total',
'showSymbol' => false,
'itemStyle' => ['normal' => ['areaStyle' => ['type' => 'default']]],
'data' => array_column($tempList, 'count'),
];
}
$registerChartsOptions = $this->getEchartsData(array_keys($dataList), $seriesList);
$userGroupData = [];
$userList = User::field('group_id,count(id) as count')->group('group_id')->select()->toArray();
foreach ($userList as $item) {
$title = UserGroup::where('id', $item['group_id'])->value('title');
if (!empty($title)) {
$userGroupData[] = [
'name' => $title,
'value' => $item['count']
];
} else {
$userGroupData[] = [
'name' => '未定义',
'value' => $item['count']
];
}
}
$userGroupData[] = ['name' => '性别(男)', 'value' => User::where('gender', 1)->count()];
$userGroupData[] = ['name' => '性别(女)', 'value' => User::where('gender', 0)->count()];
// 搜索词云数据
if (Event::hasListener('cmsHotSearch')) {
$searchWords = Event::emit('cmsHotSearch', null, true);
} else { // 模拟数据
for ($i = 0; $i < 50; $i++) {
$searchWords[] = [
'name' => Random::alpha(),
'value' => Random::number(),
];
}
}
$pluginList = get_plugin_list();
$tableList = Db::query('SHOW TABLE STATUS');
$assetsInfo = [
'pluginCount' => count($pluginList),
'pluginRunning' => array_sum(array_column($pluginList, 'status')),
'tableCount' => count($tableList),
'dbSize' => format_bytes(array_sum(array_map(function ($item) {
return $item['Data_length'] + $item['Index_length'];
}, $tableList))),
'attachmentCount' => Attachment::count(),
'attachmentSize' => format_bytes((int)Attachment::sum('filesize')),
];
$theLogsCount = Db::name('system_log')->count('id');
$exceptionCount = Db::name('system_log')->where('line', '>', 0)->count('id');
$devOpsData = [
$theLogsCount,
[
'value' => $exceptionCount,
'itemStyle' => [
'color' => '#a90000'
]
],
$theLogsCount - $exceptionCount,
UserValidate::whereNotNull('email')->count('id'),
UserValidate::whereNotNull('mobile')->count('id'),
User::count('id'),
UserThird::count('id'),
];
return view('/index/console', [
'assetsInfo' => $assetsInfo,
'workplace' => [],
'devOpsData' => json_encode($devOpsData, JSON_UNESCAPED_UNICODE),
'searchWords' => json_encode($searchWords, JSON_UNESCAPED_UNICODE),
'userGroupData' => json_encode($userGroupData, JSON_UNESCAPED_UNICODE),
'RegisterChartsOptions' => json_encode($registerChartsOptions, JSON_UNESCAPED_UNICODE),
]);
}
/**
* 获取数据结构
* @param array $dataList
* @param array $seriesList
* @return array
*/
protected function getEchartsData(array $dataList, array $seriesList): array
{
return [
'color' => ['#1890ff', '#ee6666', '#b0e689'],
'tooltip' => ['trigger' => 'axis'],
'legend' => [
'orient' => 'horizontal',
],
'grid' => [
'left' => '5%',
'top' => '13%',
'bottom' => '15%',
'right' => '5%'
],
'xAxis' => [
'type' => 'category',
'boundaryGap' => true,
'data' => $dataList,
],
'yAxis' => [
'type' => 'value',
],
'series' => $seriesList
];
}
/**
* 分析页
* @return mixed
*/
public function analysis(): \support\Response
{
return view('/index/analysis');
}
/**
* 监控页
* @return mixed
*/
public function monitor(): \support\Response
{
return view('/index/monitor');
}
/**
* 获取系统配置
*/
public function basecfg(): \support\Response
{
$config = Config::all();
$config['fsockopen'] = function_exists('fsockopen');
$config['stream_socket_client'] = function_exists('stream_socket_client');
return view('/index/basecfg', ['config' => $config]);
}
/**
* 编辑系统配置
*
* @param array $config
* @return \support\Response
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function baseSet(): \support\Response
{
if (request()->isPost()) {
$config = [];
$post = request()->all();
$list = Config::select()->toArray();
foreach ($list as $key => $value) {
$name = $value['name'];
if (isset($post[$name])) {
$option['id'] = $value['id'];
if ('array' == trim($value['type'])) {
$option['value'] = json_encode($post[$name], JSON_UNESCAPED_UNICODE);
} else {
$option['value'] = $post[$name];
}
$config[$key] = $option;
}
}
try {
(new Config())->saveAll($config);
$env = base_path() . '/.env';
$parse = parse_ini_file($env, true);
$parse['CACHE_DRIVER'] = $post['cache_type'];
$parse['CACHE_HOSTNAME'] = $post['cache_host'];
$parse['CACHE_HOSTPORT'] = $post['cache_port'];
$parse['CACHE_SELECT'] = min($post['cache_select'], 1);
$parse['CACHE_USERNAME'] = $post['cache_user'];
$parse['CACHE_PASSWORD'] = $post['cache_pass'];
write_file($env, parse_array_ini($parse));
} catch (\Throwable $th) {
return $this->error($th->getMessage());
}
}
return $this->success('保存成功!');
}
/**
* FTP测试上传
*/
public function testFtp(): \support\Response
{
if (request()->isPost()) {
if (Ftp::instance()->ftpTest(request()->post())) {
return $this->success('上传测试成功!');
}
}
return $this->error('上传测试失败!');
}
/**
* 邮件测试
*/
public function testEmail()
{
if (request()->isPost()) {
$info = Email::instance()->testEMail(request()->post());
return $info === true ? $this->success('测试邮件发送成功!') : $this->error($info);
}
}
/**
* 缓存测试
*/
public function testCache()
{
if (request()->isPost()) {
$param = request()->post();
if (!isset($param['type']) || empty($param['host']) || empty($param['port'])) {
return $this->error('参数错误!');
}
$options = [
'host' => $param['host'],
'port' => (int)$param['port'],
'username' => $param['user'],
'password' => $param['pass']
];
try {
if (strtolower($param['type']) == 'redis') {
$drive = new Redis($options);
} else {
$drive = new Memcached($options);
}
} catch (\Throwable $th) {
return $this->error($th->getMessage());
}
if ($drive->set('test', 'cacheOK', 1000)) {
return $this->success('缓存测试成功!');
} else {
return $this->error('缓存测试失败!');
}
}
return false;
}
}

View File

@@ -0,0 +1,145 @@
<?php
namespace app\admin\controller;
use app\AdminController;
use app\common\model\system\Admin;
use app\common\model\system\LoginLog;
use Webman\Event\Event;
use Webman\Http\Request;
class Login extends AdminController
{
/**
* 初始化方法
* @param Request $request
* @return \support\Response|void
* @throws \Exception
*/
public function __construct()
{
parent::__construct();
$this->model = new Admin();
$this->JumpUrl = '/admin/index';
}
/**
* 登录函数
* @return \support\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function index(): \support\Response
{
// 禁止重复访问
if (isset($this->admin['id'])) {
return $this->redirect('/admin/index');
}
if (request()->isPost()) {
$user = request()->post('name');
$pwd = request()->post('pwd');
$captcha = request()->post('captcha');
if ((isset($this->admin['count'])
&& $this->admin['count'] >= 5)
&& (isset($this->admin['time'])
&& $this->admin['time'] >= strtotime('- 5 minutes'))
) {
$error = '错误次数过多,请稍后再试!';
$this->writeLoginLogs($error);
return $this->error($error);
}
// 验证码
if (isset($this->admin['isCaptcha'])) {
if (!$captcha || !$this->captchaCheck($captcha)) {
$error = '验证码错误!';
$this->writeLoginLogs($error);
return $this->error($error);
}
}
// 验证表单令牌
if (!request()->checkToken('__token__', \request()->all())) {
$error = '表单令牌错误!';
$this->writeLoginLogs($error);
return $this->error($error, '', ['token' => token()]);
} else {
$result = Admin::checkLogin($user, $pwd);
if (empty($result)) {
$this->admin['time'] = time();
$this->admin['isCaptcha'] = true;
$this->admin['count'] = isset($this->admin['count']) ? $this->admin['count'] + 1 : 1;
\request()->session()->set($this->sename, $this->admin);
$error = '用户名或密码错误!';
$this->writeLoginLogs($error);
Event::emit('adminLoginError', \request()->all());
return $this->error($error, '', ['token' => token()]);
}
if ($result['status'] !== 1) {
$error = '账号已被禁用!';
$this->writeLoginLogs($error);
return $this->error($error);
}
$result->login_ip = request()->getRemoteIp();
$result->login_time = time();
$result->count = $result->count + 1;
try {
$result->save();
request()->session()->set($this->sename, $result->toArray());
} catch (\Throwable $th) {
return $this->error($th->getMessage());
}
$success = '登录成功!';
$this->writeLoginLogs($success, true);
Event::emit('adminLoginSuccess', $result->toArray());
return $this->success($success, $this->JumpUrl);
}
}
return view('login/index', [
'captcha' => $this->admin['isCaptcha'] ?? false,
]);
}
/**
* 写入登录日志
* @param string $error
* @param int $status
* @return void
*/
private function writeLoginLogs(string $error, int $status = 0)
{
$name = \request()->input('name');
$userAgent = \request()->header('user-agent');
$nickname = $this->model->where('name', $name)->value('nickname');
if (preg_match('/.*?\((.*?)\).*?/', $userAgent, $matches)) {
$user_os = substr($matches[1], 0, strpos($matches[1], ';'));
} else {
$user_os = '未知';
}
$user_browser = preg_replace('/[^(]+\((.*?)[^)]+\) .*?/','$1',$userAgent);
$data = [
'user_ip' => request()->getRemoteIp(),
'user_agent' => $userAgent,
'user_os' => $user_os,
'user_browser' => $user_browser,
'name' => $name,
'nickname' => $nickname ?? '未知',
'error' => $error,
'status' => $status,
];
LoginLog::create($data);
}
}

View File

@@ -0,0 +1,61 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller;
use app\AdminController;
use support\Response;
class Tpl extends AdminController
{
public function __construct()
{
parent::__construct();
}
/**
* 读取模板列表
* @return Response
*/
public function showTpl(): Response
{
// 读取配置文件
$list = include (base_path().'/extend/conf/tpl/tpl.php');
foreach ($list as $key => $value) {
$list[$key]['param'] = str_replace('extend/conf/tpl/','',$value['path']);
}
return view('/tpl/show_tpl',['list'=>$list]);
}
/**
* 编辑邮件模板
* @return Response
*/
public function editTpl(): Response
{
if (request()->isPost()) {
$post = request()->post();
$tpl = base_path().'/extend/conf/tpl/'.$post['tpl'];
if (write_file($tpl,$post['content'])) {
return $this->success('修改邮件模板成功!');
}
return $this->error('修改邮件模板失败!');
}
// 获取模板参数
$tpl = input('p');
$content = read_file(base_path().'/extend/conf/tpl/'.$tpl);
return view('/tpl/edit_tpl',['tpl'=>$tpl,'content'=>$content]);
}
}

View File

@@ -0,0 +1,574 @@
<?php
declare(strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Jobs;
use app\common\model\system\Department;
use app\common\model\system\Admin as AdminModel;
use app\common\model\system\AdminGroup as AdminGroupModel;
use app\common\model\system\AdminAccess as AdminAccessModel;
/**
* 管理员管理
* Class Admin
* @package app\admin\controller\system
*/
class Admin extends AdminController
{
/**
* 用户管理组
* @var null
*/
protected $group = null;
/**
* 用户岗位
* @var null
*/
public $jobs = null;
/**
* 用户部门
* @var null
*/
public $department = null;
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new AdminModel();
$this->jobs = Jobs::select()->toArray();
$this->group = AdminGroupModel::select()->toArray();
$this->department = Department::getListTree();
foreach ($this->group as $k => $v) {
$this->group[$k]['title'] = __($v['title']);
}
}
/**
* 获取资源列表
*/
public function index()
{
// 判断isAjax
if (request()->isAjax()) {
// 获取数据
$post = \request()->all();
$page = (int)request()->input('page') ?? 1;
$limit = (int)request()->input('limit') ?? 10;
$status = !empty($post['status']) ? $post['status'] - 1 : 1;
// 生成查询条件
$where = array();
if (!empty($post['name'])) {
$where[] = ['name', 'like', '%' . $post['name'] . '%'];
}
if (!empty($post['dep'])) {
$where[] = ['department_id', 'find in set', $post['dep']];
}
if (!empty($post['group_id'])) {
$where[] = ['group_id', 'find in set', $post['group_id']];
}
// 生成查询数据
$where[] = ['status', '=', $status];
$count = $this->model->where($where)->count();
$page = ($count <= $limit) ? 1 : $page;
$list = $this->model->where($where)->order("id asc")->withoutField('pwd')->limit($limit)->page($page)->select()->toArray();
// 循环处理数据
foreach ($list as $key => $value) {
$groupIDs = explode(',', $value['group_id']);
foreach ($groupIDs as $field => $id) {
// 查找组
$result = list_search($this->group, ['id' => $id]);
if (!empty($result)) {
$list[$key]['group'][$field] = $result;
}
}
if (!empty($list[$key]['group'])) {
$list[$key]['group'] = list_sort_by($list[$key]['group'], 'id');
}
$authNodes = $this->auth->getRulesNode($value['id']);
$list[$key][AUTH_RULES] = $authNodes[$this->auth->authPrivate];
$authNodes = $this->auth->getRulesNode($value['id'], AUTH_CATE);
$list[$key][AUTH_CATE] = $authNodes[$this->auth->authPrivate];
}
return $this->success('查询成功', null, $list, $count);
}
return view('/system/admin/index', [
'jobs' => $this->jobs,
'group' => $this->group,
'department' => json_encode($this->department),
]);
}
/**
* 添加管理员
* @return \support\Response
*/
public function add(): \support\Response
{
if (request()->isPost()) {
// 验证数据
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (!is_array($post)) {
return $this->error($post);
}
$where[] = ['name', '=', $post['name']];
$where[] = ['email', '=', $post['email']];
if ($this->model->whereOr($where)->find()) {
return $this->error('该用户名或邮箱已被注册!');
}
// 管理员加密
$post['pwd'] = encryptPwd($post['pwd']);
$post['create_ip'] = request()->getRemoteIp();
$data = $this->model->create($post);
if (!is_empty($data->id)) {
$access['admin_id'] = $data->id;
$access['group_id'] = $data->group_id;
AdminAccessModel::insert($access);
return $this->success('添加管理员成功!');
} else {
return $this->error('添加管理员失败!');
}
}
// 获取用户组
return view('', ['group' => $this->group]);
}
/**
* 更新管理员
*/
public function edit()
{
if (request()->isPost()) {
$id = request()->input('id');
if (!empty($id) && is_numeric($id)) {
// 验证数据
$post = request()->all();
$post = request_validate_rules($post, get_class($this->model), 'edit');
if (!is_array($post)) {
return $this->error($post);
}
if (!empty($post['pwd'])) {
$post['pwd'] = encryptPwd($post['pwd']);
} else {
unset($post['pwd']);
}
if ($this->model->update($post)) {
$access['group_id'] = $post['group_id'];
AdminAccessModel::where('admin_id', $id)->update($access);
return $this->success('更新管理员成功!');
} else {
return $this->error('更新管理员失败');
}
}
}
}
/**
* 编辑权限
*/
public function editRules()
{
if (request()->isPost()) {
return $this->_update_RuleCates();
}
}
/**
* 编辑栏目权限
*/
public function editCates()
{
return $this->_update_RuleCates(AUTH_CATE);
}
/**
* 更新权限函数
* @access protected
* @param string $type
* @return \support\Response|void
*/
protected function _update_RuleCates(string $type = AUTH_RULES)
{
if (request()->isPost()) {
$admin_id = input('admin_id');
$rules = request()->post($type) ?? [];
if (!empty($admin_id) && $admin_id > 0) {
$access = $this->auth->getRulesNode($admin_id, $type);
$rules = array_diff($rules, $access[$this->auth->authGroup]);
// 权限验证
if (!$this->auth->checkRuleOrCateNodes($rules, $type, $this->auth->authPrivate)) {
return $this->error('没有权限!');
}
// 获取个人节点
$differ = array_diff($access[$this->auth->authPrivate], $access[$this->auth->authGroup]);
$current = [];
if (!$this->auth->superAdmin()) {
$current = $this->auth->getRulesNode();
$current = array_diff($differ, $current[$this->auth->authPrivate]);
}
$rules = array_unique(array_merge($rules, $current));
$this->model = new AdminAccessModel();
$data = [
"$type" => implode(',', $rules)
];
if ($this->model->where('admin_id', $admin_id)->save($data)) {
return $this->success('更新权限成功!');
}
return $this->error('更新权限失败!');
}
}
}
/**
* 获取用户菜单
* getAdminRules
* @return void
*/
public function getUserMenu()
{
if (\request()->isAjax()) {
return $this->auth->getRulesMenu();
}
}
/**
* 权限函数接口
* @access public
* @return mixed|array
*/
public function getRuleCateTree()
{
if (request()->isAjax()) {
$type = input('type') ?? 'rules';
try {
$list = $this->auth->getRuleCatesTree($type, $this->auth->authPrivate);
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
return $list;
}
return [];
}
/**
* 模版页面
*/
public function theme()
{
return view('/system/admin/theme');
}
/**
* 消息模板
*/
public function message()
{
// 配置消息
$msg = [
'msg' => [
'0' => [
'title' => '你收到了几份周报!',
'type' => '周报类型',
'create_time' => '1周前',
],
'1' => [
'title' => '你收到了来自女下属的周报',
'type' => '周报类型',
'create_time' => '2周前',
]
],
'comment' => [
'0' => [
'title' => '一个领导评论了你',
'content' => '小伙子不错,继续努力!',
'create_time' => '1周前',
]
],
'things' => [
'0' => [
'title' => '客户说尽快修复瞟了么APP闪退的问题...',
'type' => '0',
'create_time' => '1周前',
],
'1' => [
'title' => '秦老板和经销商的下季度合同尽快签订!',
'type' => '1',
'create_time' => '2周前',
]
],
];
return view('/system/admin/message', [
'list' => $msg
]);
}
/**
* 个人中心
* @return mixed
*/
public function center(): \support\Response
{
if (request()->isPost()) {
$post = request()->post();
$post['id'] = $this->admin['id'];
if ($this->model->update($post)) {
return $this->success();
}
return $this->error();
}
$title = [];
$data = $this->model->find($this->admin['id']);
if (!empty($data['group_id'])) {
$group = AdminGroupModel::field('title')
->whereIn('id', $data['group_id'])
->select()
->toArray();
foreach ($group as $key => $value) {
$title[$key] = $value['title'];
}
}
$data['group'] = implode('', $title);
$data['tags'] = empty($data['tags']) ? $data['tags'] : unserialize($data['tags']);
return view('/system/admin/center', [
'data' => $data
]);
}
/**
* 修改个人资料
*/
public function modify()
{
if (request()->isAjax()) {
$post = request()->post();
$id = $this->admin['id'];
try {
//code...
switch ($post['field']) {
case 'face':
$id = $this->model->update(['id' => $id, 'face' => $post['face']]);
break;
case 'mood':
$id = $this->model->update(['id' => $id, 'mood' => $post['mood']]);
break;
case 'tags':
if (\is_empty($post['tags'])) {
break;
}
$data = $this->model->field('tags')->find($id);
if (!empty($data['tags'])) {
$tags = unserialize($data['tags']);
if (!empty($post['del'])) {
foreach ($tags as $key => $value) {
if ($value == $post['tags']) {
unset($tags[$key]);
}
}
} else {
$merge = array($post['tags']);
$tags = array_unique(array_merge($merge, $tags));
if (count($tags) > 10) {
throw new \Exception('最多拥有10个标签');
}
}
$tags = serialize($tags);
} else {
$tags = serialize(array($post['tags']));
}
$id = $this->model->update(['id' => $id, 'tags' => $tags]);
break;
default:
# code...
break;
}
} catch (\Exception $e) {
return $this->error($e->getMessage());
}
return $id ? $this->success() : $this->error();
}
}
/**
* 修改密码
* @return mixed
*/
public function pwd(): \support\Response
{
if (request()->isPost()) {
$pwd = input('pwd');
$post = request()->except(['pwd']);
if ($post['pass'] !== $post['repass']) {
return $this->error('两次输入的密码不一样!');
}
// 查找数据
$where[] = ['id', '=', $this->admin['id']];
$where[] = ['pwd', '=', encryptPwd($pwd)];
$result = $this->model->where($where)->find();
if (!empty($result)) {
$this->model->where($where)->update(['pwd' => encryptPwd($post['pass'])]);
return $this->success('更改密码成功!');
} else {
return $this->error('原始密码输入错误');
}
}
return view('/system/admin/pwd');
}
/**
* 语言配置
* @return mixed
* @throws \think\Exception
*/
public function language()
{
$language = input('l');
$env = base_path() . '/.env';
$array = parse_ini_file($env, true);
$array['LANG_DEFAULT_LANG'] = $language;
$content = parse_array_ini($array);
if (write_file($env, $content)) {
return json(['success']);
}
}
/**
* 更改状态
* @return \support\Response
*/
public function status()
{
$id = input('id');
if ($id == 1) {
return $this->error('超级管理员不能更改状态!');
}
$array['id'] = $id;
$array['status'] = input('status');
if ($this->model->update($array)) {
return $this->success('修改成功!');
}
return $this->error('修改失败,请检查您的数据!');
}
/**
* 删除管理员
* @return mixed
* @throws \think\db\exception\DbException
*/
public function del()
{
$id = input('id');
!is_array($id) && ($id = array($id));
if (!empty($id) && is_array($id)) {
// 过滤权限
if (in_array("1", $id)) {
return $this->error('禁止删除超管帐号!');
}
// 删除用户
if ($this->model->destroy($id)) {
$arr = implode(',', $id);
$where[] = ['admin_id', 'in', $arr];
AdminAccessModel::where($where)->delete();
return $this->success('删除管理员成功!');
}
}
return $this->error('删除管理员失败,请检查您的参数!');
}
/**
* 清理系统缓存
* @return \support\Response
* @throws \think\Exception
*/
public function clear(): \support\Response
{
if (request()->isAjax()) {
$type = input('type');
try {
// 清理内容
if ($type == 'all' || $type == 'content') {
\think\facade\Cache::clear();
}
// 清理模板
if ($type == 'all' || $type == 'template') {
recursive_delete(root_path('runtime/views'));
}
// 清理插件缓存
if ($type == 'all' || $type == 'plugin') {
plugin_refresh_hooks();
}
} catch (\Throwable $th) {
return $this->error($th->getMessage());
}
}
return $this->success('清理缓存成功,请刷新页面!');
}
}

View File

@@ -0,0 +1,199 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\AdminGroup as AdminGroupModel;
use Webman\Http\Request;
/**
* 管理员组管理
* Class AdminGroup
* @package app\admin\controller\system
*/
class AdminGroup extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new AdminGroupModel();
}
/**
* 获取资源列表
*/
public function index()
{
if (request()->isAjax()) {
$param = input();
$param['page'] = input('page');
$param['limit'] = input('limit');
// 查询条件
$where = array();
if (!empty($param['title'])) {
$where[] = ['title','like','%'.$param['title'].'%'];
}
if (!empty($param['alias'])) {
$where[] = ['alias','like','%'.$param['alias'].'%'];
}
if (!empty($param['content'])) {
$where[] = ['content','like','%'.$param['content'].'%'];
}
// 查询数据
$count = $this->model->where($where)->count();
$limit = is_empty($param['limit']) ? 10 : (int)$param['limit'];
$page = ($count <= $limit) ? 1 : $param['page'];
$list = $this->model->where($where)->order("id asc")->limit($limit)->page($page)->select()->toArray();
foreach ($list as $key => $value) {
$list[$key]['title'] = __($value['title']);
}
return $this->success('查询成功', null, $list, $count);
}
return view('/system/admin/group',['group'=>$this->model->getListGroup()]);
}
/**
* 添加角色
*/
public function add()
{
if (request()->isPost()) {
// 接收数据
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->create($post)) {
return $this->success('添加角色成功!');
}else {
return $this->error('添加角色失败!');
}
}
}
/**
* 编辑角色
*/
public function edit()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->update($post)) {
return $this->success('更新角色成功!');
}else {
return $this->error('更新角色失败');
}
}
}
/**
* 权限函数接口
* @access public
* @return mixed|array
*/
public function getRuleCateTree()
{
if (request()->isAjax()) {
$type = input('type') ?? 'rules';
return $this->auth->getRuleCatesTree($type, $this->auth->authGroup);
}
}
/**
* 更新权限
*/
public function editRules()
{
if (request()->isPost()) {
$id = input('id');
if (!is_empty($id) && is_numeric($id)) {
$rules = request()->post('rules') ?? [];
$array = [
'id'=>$id,
'rules'=>implode(',',$rules)
];
if (!$this->auth->checkRuleOrCateNodes($rules)) {
return $this->error('没有权限!');
}
if ($this->model->update($array)) {
return $this->success('更新权限成功!');
}
}
return $this->error('更新权限失败!');
}
}
/**
* 更新栏目
*/
public function editCates()
{
if (request()->isPost()) {
$id = input('id');
if (!is_empty($id) && is_numeric($id)) {
$cates = request()->post('cates') ?? [];
$array = [
'id'=>$id,
'cates'=>implode(',',$cates)
];
if (!$this->auth->checkRuleOrCateNodes($cates,AUTH_CATE)) {
return $this->error('没有权限!');
}
if ($this->model->update($array)) {
return $this->success('更新栏目权限成功!');
}
}
return $this->error('更新栏目权限失败!');
}
}
/**
* 删除角色/用户组
*/
public function del()
{
$id = input('id');
if (!empty($id) && is_numeric($id)) {
if ($id == 1) {
return $this->error('系统内置禁止删除!');
}
if ($this->model::destroy($id)) {
return $this->success('删除角色成功!');
}
}
return $this->error('删除角色失败,请检查您的参数!');
}
}

View File

@@ -0,0 +1,146 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\AdminRules as AdminRuleModel;
use Webman\Http\Request;
/**
* 管理员规则
* Class AdminRules
* @package app\admin\controller\system
*/
class AdminRules extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new AdminRuleModel();
}
/**
* 获取资源列表
*
*/
public function index()
{
if (request()->isAjax()) {
// 查询参数
$where = array();
$post['title'] = input('title');
$post['router'] = input('router');
if (!empty($post['title'])) {
$where[] = ['title','like','%'.$post['title'].'%'];
}
if (!empty($post['router'])) {
$where[] = ['router','like','%'.$post['router'].'%'];
}
// 获取总数
$total = $this->model->count();
$list = $this->model->where($where)->order('sort asc')->select()->toArray();
foreach ($list as $key => $value) {
$list[$key]['title'] = __($value['title']);
}
// 自定义查询
if (count($list) < $total) {
$parentNode = []; // 查找父节点
foreach ($list as $key => $value) {
if ($value['pid'] !== 0 && !list_search($list,['id'=>$value['pid']])) {
$parentNode[] = $this->parentNode($value['pid']);
}
}
foreach ($parentNode as $key => $value) {
$list = array_merge($list,$value);
}
}
$rules = $this->model->getListTree();
return $this->success('获取成功', '',[
'item'=> $list,
'rules'=> $rules
],
count($list),0);
}
return view('/system/admin/rules');
}
/**
* 添加节点数据
*/
public function add()
{
if (request()->isPost()) {
$post = \request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->create($post)) {
return $this->success('添加菜单成功!');
}else {
return $this->error('添加菜单失败!');
}
}
}
/**
* 编辑节点数据
*/
public function edit()
{
if (request()->isPost()) {
$post = \request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->update($post)) {
return $this->success('更新菜单成功!');
}else {
return $this->error('更新菜单失败');
}
}
}
/**
* 删除节点数据
*/
public function del()
{
$id = input('id');
if (!empty($id)) {
// 查询子节点
if ($this->model->where('pid',$id)->count()) {
return $this->error('当前菜单存在子菜单!');
}
// 删除单个
if ($this->model::destroy($id)) {
return $this->success('删除菜单成功!');
}
}
return $this->error('删除失败,请检查您的参数!');
}
}

View File

@@ -0,0 +1,72 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Attachment as AttachmentModel;
use Webman\Http\Request;
/**
* 附件管理
* Class Attachment
* @package app\admin\controller\system
*/
class Attachment extends AdminController
{
// 上传文件夹地址
protected $upload;
public function __construct()
{
parent::__construct();
$this->model = new AttachmentModel();
$this->upload = saenv('upload_path');
}
/**
* 获取资源列表
*/
public function index()
{
if (request()->isAjax()) {
// 生成查询条件
$post = request()->post();
$page = (int)input('page') ?: 1;
$limit = (int)input('limit') ?: 10;
$type = input('type','');
$where = [];
if (!empty($post['filename'])) {
$where[] = ['filename','like','%'.$post['filename'].'%'];
}
if (!empty($type)) {
$where[] = ['type','=',$type];
}
$count = $this->model->where($where)->count();
$page = ($count <= $limit) ? 1 : $page;
// 生成查询数据
$list = $this->model->where($where)->order("id desc")->limit($limit)->page($page)->select()->toArray();
return $this->success('查询成功', "", $list, $count);
}
return view('/system/attachment/index',[
'choose' => input('choose') ?: '',
]);
}
}

View File

@@ -0,0 +1,105 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Company as CompanyModel;
use Webman\Http\Request;
/**
* 公司信息
* Class Company
* @package app\admin\controller\system
*/
class Company extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new CompanyModel();
}
/**
* 获取资源列表
* @return \support\Response
*/
public function index(): \support\Response
{
if (request()->isAjax()) {
// 生成查询条件
$post = input();
$where = array();
if (!empty($post['title'])) {
$where[] = ['title','like','%'.$post['title'].'%'];
}
// 生成查询数据
$list = $this->model->where($where)->select()->toArray();
return $this->success('查询成功', null, $list, count($list));
}
return view('/system/company/index');
}
/**
* 添加公司信息
*/
public function add ()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post,get_class($this->model));
if (empty($post) || !is_array($post)) {
$this->error($post);
}
if ($this->model->create($post)){
return $this->success();
}
return $this->error();
}
return view('/system/company/add',[
'data'=> $this->getTableFields()
]);
}
/**
* 编辑公司信息
*/
public function edit()
{
$id = input('id');
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post,get_class($this->model));
if (empty($post) || !is_array($post)) {
$this->error($post);
}
if ($this->model->update($post)){
return $this->success();
}
return $this->error();
}
$data = $this->model->find($id);
return view('/system/company/add',['data'=> $data]);
}
}

View File

@@ -0,0 +1,147 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Department as DepartmentModel;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Http\Request;
/**
* 部门管理
* Class Department
* @package app\admin\controller\system
*/
class Department extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new DepartmentModel();
}
/**
* 获取资源列表
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index(): \support\Response
{
if (request()->isAjax()) {
// 查询参数
$where = array();
$post['head'] = input('head');
if (!empty($post['head'])) {
$where[] = ['head','like','%'.$post['head'].'%'];
}
// 获取总数
$total = $this->model->count();
$list = $this->model->where($where)->order('sort asc')->select()->toArray();
foreach ($list as $key => $value) {
$list[$key]['title'] = __($value['title']);
$list[$key]['datas'] = $this->model->getListTree();
}
// 自定义查询
if (count($list) < $total) {
$parentNode = [];
foreach ($list as $key => $value) {
if ($value['pid'] !== 0 && !list_search($list,['id'=>$value['pid']])) {
$parentNode[] = $this->parentNode($value['pid']);
}
}
foreach ($parentNode as $key => $value) {
$list = array_merge($list,$value);
}
}
$depart = $this->model->getListTree();
return $this->success('获取成功', '',[
'item'=> $list,
'depart'=> $depart
],
count($list));
}
return view('system/department/index');
}
/**
* 添加部门数据
*/
public function add()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->create($post)) {
return $this->success('添加部门成功!');
}else {
return $this->error('添加部门失败!');
}
}
}
/**
* 编辑部门数据
*/
public function edit()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->update($post)) {
return $this->success('更新部门成功!');
}else {
return $this->error('更新部门失败');
}
}
}
/**
* 删除部门数据
*/
public function del()
{
$id = input('id');
if (!empty($id) && is_numeric($id)) {
// 查询子部门
if ($this->model->where('pid',$id)->count()) {
return $this->error('当前部门存在子部门!');
}
// 删除单个
if ($this->model::destroy($id)) {
return $this->success('删除部门成功!');
}
}
return $this->error('删除失败,请检查您的参数!');
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Dictionary as DictionaryModel;
use Webman\Http\Request;
/**
* 字典管理
* Class Dictionary
* @package app\admin\controller\system
*/
class Dictionary extends AdminController
{
public function __construct()
{
parent::__construct();
$this->model = new DictionaryModel();
}
/**
* 字典首页
* @return \support\Response
*/
public function index(): \support\Response
{
$post = input();
$pid = input('pid');
$limit = input('limit/d') ?? 10;
$page = input('page/d') ?? 1;
if ($pid == null) {
$pid = (string)$this->model->minId();
}
if (request()->isAjax()) {
// 生成查询数据
$pid = !strstr($pid,',') ? $pid : explode(',',$pid);
$where[] = ['pid','in',$pid];
if (!empty($post['name'])) {
$where[] = ['name','like','%'.$post['name'].'%'];
}
$count = $this->model->where($where)->count();
$list = $this->model->where($where)->limit($limit)->page($page)->select()
->each(function($item,$key) use ($pid){
if ($key == 0 && $pid == '0') {
$item['LAY_CHECKED'] = true;
}
return $item;
});
return $this->success('查询成功', null, $list, $count);
}
return view('/system/dictionary/index',[ 'pid' => $pid]);
}
}

View File

@@ -0,0 +1,124 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\Jobs as JobsModel;
use Webman\Http\Request;
/**
* 岗位管理
* Class Jobs
* @package app\admin\controller\system
*/
class Jobs extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new JobsModel();
}
/**
* 获取资源列表
*/
public function index()
{
if (request()->isAjax()) {
$param = request()->all();
$param['page'] = input('page');
$param['limit'] = input('limit');
// 查询条件
$where = array();
if (!empty($param['title'])) {
$where[] = ['title','like','%'.$param['title'].'%'];
}
if (!empty($param['alias'])) {
$where[] = ['alias','like','%'.$param['alias'].'%'];
}
if (!empty($param['content'])) {
$where[] = ['content','like','%'.$param['content'].'%'];
}
// 查询数据
$count = $this->model->where($where)->count();
$limit = empty($param['limit']) ? 10 : (int)$param['limit'];
$page = ($count <= $limit) ? 1 : $param['page'];
$list = $this->model->where($where)->order("id asc")->limit($limit)->page($page)->select()->toArray();
foreach ($list as $key => $value) {
$list[$key]['title'] = __($value['title']);
}
return $this->success('查询成功', null, $list, $count);
}
return view('/system/jobs/index');
}
/**
* 添加岗位数据
*/
public function add()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->create($post)) {
return $this->success('添加岗位成功!');
}else {
return $this->error('添加岗位失败!');
}
}
}
/**
* 编辑岗位数据
*/
public function edit()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
if ($this->model->update($post)) {
return $this->success('更新岗位成功!');
}else {
return $this->error('更新岗位失败');
}
}
}
/**
* 删除岗位数据
*/
public function del()
{
$id = input('id');
if (!empty($id) && is_numeric($id)) {
if ($this->model::destroy($id)) {
return $this->success('删除岗位成功!');
}
}
return $this->error('删除失败,请检查您的参数!');
}
}

View File

@@ -0,0 +1,34 @@
<?php
declare (strict_types = 1);
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\LoginLog as LoginLogModel;
use Webman\Http\Request;
/**
* login_log
* 登录日志
* @author meystack <
* @version 1.0
*/
class LoginLog extends AdminController
{
/**
* LoginLog模型对象
* @return void
*/
public function __construct()
{
parent::__construct();
$this->model = new LoginLogModel;
}
/**
* 默认生成的方法为index/add/edit/del/status 五个方法
* 当创建CURD的时候DIY的函数体和模板为空请自行编写代码
*/
}

View File

@@ -0,0 +1,387 @@
<?php
declare (strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use system\File;
use system\Http;
use system\ZipArchives;
use app\AdminController;
use app\admin\library\Auth;
use Throwable;
use app\common\library\DataBase;
use app\common\model\system\AdminRules;
/**
* 插件市场
* Class Plugin
* @package app\admin\controller\system
*/
class Plugin extends AdminController
{
/**
* 查询最大数量
* @var int
*/
protected $limit = 500;
/**
* 获取本地插件列表
* @return \support\Response
*/
public function index(): \support\Response
{
$pluginList = get_plugin_list();
if (request()->isAjax()) {
$onlinePlugin = $this->getPluginList($pluginList);
return $this->success('获取成功', null, $onlinePlugin, count($onlinePlugin));
}
return view('/system/plugin/index', ['plugin' => json_encode($pluginList)]);
}
/**
* 安装插件
* @return \support\Response|void
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
*/
public function install()
{
if (request()->isPost()) {
$name = input('name');
$pluginPath = plugin_path($name);
if (is_dir($pluginPath)) {
return $this->error('请勿重复安装插件');
}
try {
$pluginZip = self::downLoad($name, ['name' => $name, 'token' => input('token')]);
ZipArchives::unzip($pluginZip, plugin_path(), '', true);
$listFiles = File::mutexCompare(File::getCopyDirs($name), root_path(), $pluginPath, true);
if (!empty($listFiles)) {
throw new \Exception(sprintf("存在文件冲突:%s", implode(',', $listFiles)), -117);
}
$pluginClass = get_plugin_instance($name);
$pluginClass->install();
self::pluginMenu($name);
self::executeSql($name);
self::enabled($name);
} catch (\Throwable $th) {
recursive_delete($pluginPath);
return $this->error($th->getMessage());
}
return $this->success('插件安装成功', null, get_plugin_config($name, true));
}
}
/**
* 卸载插件
* @return \support\Response|void
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
*/
public function uninstall()
{
if (request()->isAjax()) {
$name = input('name');
$config = get_plugin_config($name, true);
if (empty($config) || $config['status']) {
return $this->error('插件不存在或未禁用');
}
try {
$pluginPath = plugin_path($name);
$pluginClass = get_plugin_instance($name);
$pluginClass->uninstall();
if (getenv('APP_DEBUG') && Auth::instance()->SuperAdmin()) {
self::executeSql($name, 'uninstall');
}
AdminRules::disabled($name, true);
recursive_delete($pluginPath);
plugin_refresh_hooks();
} catch (Throwable $th) {
return $this->error($th->getMessage());
}
return $this->success('插件卸载成功');
}
}
/**
* 插件升级
* @return mixed|void
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \Exception
*/
public function upgrade()
{
if (request()->isPost()) {
try {
$name = input('name');
$token = input('token');
$version = input('version');
$pluginInfo = get_plugin_config($name, true);
if (!$pluginInfo) {
return $this->error('插件不存在');
}
if ($pluginInfo['status']) {
return $this->error('请禁用插件后再升级');
}
$pluginPath = plugin_path($name);
$pluginZip = self::downLoad($name, ['name' => $name, 'token' => $token, 'version' => $version]);
$formIndex = ZipArchives::unzip($pluginZip, plugin_path(), 'config.json');
$upgradeInfo = json_decode($formIndex, true);
// 判断升级版本号
if (version_compare($upgradeInfo['version'], $pluginInfo['version'], "<=")) {
throw new \Exception('升级版本不能低于已安装版本');
}
// 备份当前插件
$backupDir = root_path() . $name . '_' . $pluginInfo['version'] . '.zip';
ZipArchives::compression($backupDir, $pluginPath, plugin_path());
ZipArchives::unzip($pluginZip, plugin_path(), '', true);
$pluginClass = get_plugin_instance($name, 'upgrade');
$pluginClass->execute($pluginInfo['version'], $upgradeInfo['version']);
$data = array_merge($upgradeInfo, [
'extends' => $pluginInfo['extends'],
'rewrite' => $pluginInfo['rewrite'],
]);
write_file($pluginPath . 'config.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
self::pluginMenu($name);
self::executeSql($name);
self::enabled($name);
} catch (\Throwable $th) {
return $this->error($th->getMessage(), null, null, $th->getCode());
}
return $this->success('插件更新成功', null, $data);
}
}
/**
* 启用插件
* @param string $name
* @return bool
* @throws \Exception|\Psr\SimpleCache\InvalidArgumentException
*/
public static function enabled(string $name): bool
{
if (!$name || !is_dir(plugin_path($name))) {
throw new \Exception(__('插件数据不存在'), -117);
}
$pluginDir = plugin_path($name);
foreach (File::getCopyDirs($name) as $copyDir) {
copydirs($copyDir, root_path() . str_replace($pluginDir, '', $copyDir));
}
try {
$pluginClass = get_plugin_instance($name);
$pluginClass->enabled();
AdminRules::enabled($name);
set_plugin_config($name, ['status' => 1]);
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
return true;
}
/**
* 禁用插件
* @param string $name
* @return bool
* @throws \Psr\SimpleCache\InvalidArgumentException
* @throws \Exception
*/
public static function disabled(string $name): bool
{
if (!$name || !is_dir(plugin_path($name))) {
throw new \Exception(__('插件数据不存在'), -117);
}
try {
// 清理插件文件
$pluginDir = plugin_path($name);
foreach (File::getCopyDirs($name) as $dir) {
if (is_dir($dir)) {
$files = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $fileinfo) {
$dirFile = str_replace($pluginDir, root_path(), $fileinfo->getPathname());
if ($fileinfo->isFile()) {
@unlink($dirFile);
} else if ($fileinfo->isDir()) {
remove_empty_dir($dirFile);
}
}
}
}
$pluginClass = get_plugin_instance($name);
$pluginClass->disabled();
AdminRules::disabled($name);
set_plugin_config($name, ['status' => 0]);
} catch (\Exception $e) {
throw new \Exception($e->getMessage());
}
return true;
}
/**
* 修改插件配置
* @return \support\Response
* @throws \Psr\SimpleCache\InvalidArgumentException
*/
public function config(): \support\Response
{
$name = input('name');
if (preg_replace('/[^a-zA-Z0-9]/i', '', $name) !== $name) {
return $this->error('插件名称只能是字母和数字');
}
$config = get_plugin_config(strtolower($name), true);
if (empty($config)) {
return $this->error('插件不存在');
}
if (request()->isPost()) {
$post['extends'] = input('extends');
$post['rewrite'] = input('rewrite');
$config = array_merge($config, $post);
try {
set_plugin_config($name, $config);
} catch (Throwable $th) {
return $this->error($th->getMessage());
}
return $this->success();
}
return view($config['path'] . '/config.html', ['config' => $config]);
}
/**
* 修改插件状态
* 启用 / 禁用
* @return \support\Response|void
*/
public function status()
{
if (request()->isAjax()) {
try {
call_user_func([$this, input('status') == 1 ? 'enabled' : 'disabled'], input('id'));
} catch (Throwable $th) {
return $this->error($th->getMessage());
}
return $this->success();
}
}
/**
* 插件下载
* @param string $name
* @param array $extends
* @return string
* @throws \Exception
*/
public static function downLoad(string $name, array $extends): string
{
try {
$query = get_plugin_query();
$response = Http::get($query, $extends);
$body = json_decode($response, true);
$url = $body['data']['url'] ?: '';
if (!empty($url) && stristr($url, 'download')) {
$content = Http::get($url);
$filePath = plugin_path() . $name . '.zip';
write_file($filePath, $content);
} else {
throw new \Exception($body['msg'], $body['code'], $body['data']);
}
} catch (\Throwable $th) {
throw new \Exception(__("安装包下载失败"), -111);
}
return $filePath;
}
/**
* 执行SQL脚本文件
* @param string $name
* @param string $type
* @return void
*/
public static function executeSql(string $name, string $type = 'install')
{
$pluginPath = plugin_path($name);
$sqlFile = $pluginPath . $type . '.sql';
DataBase::importSql($sqlFile);
}
/**
* 获取菜单项
* @param string $name
* @return void
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function pluginMenu(string $name)
{
$pluginPath = plugin_path($name);
$pluginMenu = $pluginPath . 'data/menu.php';
if (is_file($pluginMenu)) {
$data = include($pluginMenu);
AdminRules::createMenu($data, $name);
}
}
/**
* 获取服务器插件列表
* @param array $pluginList
* @return array
*/
protected function getPluginList(array $pluginList = []): array
{
$PluginApiList = Http::get(config('app.api_url') . '/plugin/index', ['limit' => $this->limit]);
$PluginApiList = json_decode($PluginApiList, true)['data'];
foreach ($pluginList as $name => $plugin) {
$result = list_search($PluginApiList, ['name' => $plugin['name']]);
if (!empty($result)) {
$pluginList[$name] = $result;
}
}
return $pluginList;
}
}

View File

@@ -0,0 +1,80 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Http\Request;
use app\common\model\system\SystemLog as SystemLogModel;
/**
* 系统日志
* Class SystemLog
* @package app\admin\controller\system
*/
class SystemLog extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new SystemLogModel();
}
/**
* 获取资源列表
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index(): Response
{
if (request()->isAjax()) {
// 获取数据
$post = \request()->all();
$page = (int)input('page') ?? 1;
$limit = (int)input('limit') ?? 18;
// 生成查询数据
$where = array();
if (!empty($post['name'])) {
$where[] = ['url','like','%'.$post['name'].'%'];
}
if (!empty($post['type']) && $post['type'] == 'user') {
$where[] = ['name','<>','system'];
}else if (!empty($post['type']) && $post['type'] == 'system') {
$where[] = ['name','=','system'];
}
if (!empty($post['status']) && $post['status'] == 'normal') {
$where[] = ['error','=',null];
}else if (!empty($post['status']) && $post['status'] == 'error') {
$where[] = ['error','<>',''];
}
$where[] = ['status','=','1'];
$count = $this->model->where($where)->count();
$page = ($count <= $limit) ? 1 : $page;
$list = $this->model->where($where)->order('id', 'desc')->limit($limit)->page($page)->select()->toArray();
return $this->success('查询成功', "", $list, $count);
}
return view('/system/system_log/index');
}
}

View File

@@ -0,0 +1,183 @@
<?php
declare (strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\library\Ip2Region;
use app\common\model\system\User as UserModel;
use app\common\model\system\UserGroup as UserGroupModel;
use support\Response;
use system\Random;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use Webman\Http\Request;
/**
* 用户管理
* Class User
* @package app\admin\controller\system
*/
class User extends AdminController
{
/**
* @var array
*/
private $userGroup;
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new UserModel();
$this->userGroup = UserGroupModel::select()->toArray();
}
/**
* 获取资源
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function index(): \support\Response
{
if (request()->isAjax()) {
// 获取数据
$post = \request()->all();
$page = (int)input('page') ?? 1;
$limit = (int)input('limit') ?? 10;
$status = !empty($post['status']) ? (int)$post['status'] - 1 : 1;
// 生成查询条件
$where = array();
if (!empty($post['nickname'])) {
$where[] = ['nickname', 'like', '%' . $post['nickname'] . '%'];
}
if (!empty($post['group_id'])) {
$where[] = ['group_id', 'find in set', $post['group_id']];
}
// 生成查询数据
$where[] = ['status', '=', $status];
$count = $this->model->where($where)->count();
$page = ($count <= $limit) ? 1 : $page;
$list = $this->model->where($where)->order("id asc")->limit($limit)->page($page)->select();
// 循环处理数据
foreach ($list as $key => $value) {
$value->hidden(['pwd', 'salt']);
$region = Ip2Region::instance()->memorySearch($value['login_ip']);
$region = explode('|', $region['region']);
$list[$key]['region'] = $region;
$result = list_search($this->userGroup, ['id' => $value['group_id']]);
if (!empty($result)) {
$list[$key]['group'] = $result['title'];
}
}
// TODO..
return $this->success('查询成功', "", $list, $count);
}
return view('/system/user/index', [
'UserGroup' => $this->userGroup,
]);
}
/**
* 添加会员
*/
public function add()
{
if (request()->isPost()) {
$post = request()->post();
$post = request_validate_rules($post, get_class($this->model));
if (empty($post) || !is_array($post)) {
return $this->error($post);
}
// 禁止重复注册
$whereName[] = ['nickname', '=', $post['nickname']];
$whereEmail[] = ['email', '=', $post['email']];
if ($this->model->whereOr([$whereName, $whereEmail])->find()) {
return $this->error('该用户ID或邮箱已经存在');
}
// 生成密码
$salt = Random::alpha();
$post['salt'] = $salt;
$post['pwd'] = encryptPwd($post['pwd'], $post['salt']);
if ($this->model->create($post)) {
return $this->success('注册成功!');
}
return $this->error('注册失败!');
}
}
/**
* 编辑会员
*/
public function edit()
{
if (request()->isPost()) {
$post = \request()->post();
// 查询数据
$data = $this->model->find($post['id']);
if ($data['nickname'] != $post['nickname']) {
$whereName[] = ['nickname', '=', $post['nickname']];
if ($this->model->where($whereName)->find()) {
return $this->error('该用户ID已经存在');
}
}
if ($data['email'] != $post['email']) {
$whereEmail[] = ['email', '=', $post['email']];
if ($this->model->where($whereEmail)->find()) {
return $this->error('该用户邮箱已经存在!');
}
}
// 为空则去掉密码
if (empty($post['pwd'])) {
unset($post['pwd']);
} else {
$salt = Random::alpha();
$post['salt'] = $salt;
$post['pwd'] = encryptPwd($post['pwd'], $post['salt']);
}
if ($this->model->update($post)) {
return $this->success('更新成功!');
}
return $this->error('更新失败!');
}
}
/**
* 删除会员
*/
public function del()
{
return $this->error('不允许删除会员');
}
}

View File

@@ -0,0 +1,70 @@
<?php
declare (strict_types = 1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
use app\AdminController;
use app\common\model\system\UserGroup as UserGroupModel;
/**
* 用户组别管理
* Class UserGroup
* @package app\admin\controller\system
*/
class UserGroup extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new UserGroupModel();
}
/**
* 获取资源
*/
public function index()
{
if (request()->isAjax()) {
$param = input();
$param['page'] = input('page/d');
$param['limit'] = input('limit/d');
// 查询条件
$where = array();
if (!empty($param['title'])) {
$where[] = ['title','like','%'.$param['title'].'%'];
}
if (!empty($param['alias'])) {
$where[] = ['alias','like','%'.$param['alias'].'%'];
}
if (!empty($param['content'])) {
$where[] = ['content','like','%'.$param['content'].'%'];
}
// 查询数据
$count = $this->model->where($where)->count();
$limit = is_empty($param['limit']) ? 10 : $param['limit'];
$page = ($count <= $limit) ? 1 : $param['page'];
$list = $this->model->where($where)->order("id asc")->limit($limit)->page($page)->select()->toArray();
foreach ($list as $key => $value) {
$list[$key]['title'] = __($value['title']);
}
return $this->success('查询成功', null, $list, $count);
}
return view('system/user/group');
}
}