mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 19:42:47 +08:00
将所有主要逻辑代码迁移到extend中,并在service中注册调用;
This commit is contained in:
@@ -4,97 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace app;
|
namespace app;
|
||||||
|
|
||||||
use think\App;
|
use base\BaseControllerBase;
|
||||||
use think\exception\ValidateException;
|
|
||||||
use think\facade\Log;
|
|
||||||
use think\Validate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制器基础类
|
* 控制器基础类.
|
||||||
*/
|
*/
|
||||||
abstract class BaseController
|
abstract class BaseController extends BaseControllerBase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Request实例
|
|
||||||
* @var \think\Request
|
|
||||||
*/
|
|
||||||
protected $request;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用实例
|
|
||||||
* @var \think\App
|
|
||||||
*/
|
|
||||||
protected $app;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否批量验证
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $batchValidate = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 控制器中间件
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $middleware = [];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 构造方法
|
|
||||||
* @access public
|
|
||||||
* @param App $app 应用对象
|
|
||||||
*/
|
|
||||||
public function __construct(App $app)
|
|
||||||
{
|
|
||||||
$this->app = $app;
|
|
||||||
$this->request = $this->app->request;
|
|
||||||
|
|
||||||
// 控制器初始化
|
|
||||||
$this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始化
|
|
||||||
protected function initialize()
|
|
||||||
{
|
|
||||||
|
|
||||||
Log::debug('request url :' . $this->request->url());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 验证数据
|
|
||||||
* @access protected
|
|
||||||
* @param array $data 数据
|
|
||||||
* @param string|array $validate 验证器名或者验证规则数组
|
|
||||||
* @param array $message 提示信息
|
|
||||||
* @param bool $batch 是否批量验证
|
|
||||||
* @return array|string|true
|
|
||||||
* @throws ValidateException
|
|
||||||
*/
|
|
||||||
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
|
||||||
{
|
|
||||||
if (is_array($validate)) {
|
|
||||||
$v = new Validate();
|
|
||||||
$v->rule($validate);
|
|
||||||
} else if ($validate instanceof Validate) {
|
|
||||||
$v = $validate;
|
|
||||||
} else {
|
|
||||||
if (strpos($validate, '.')) {
|
|
||||||
// 支持场景
|
|
||||||
list($validate, $scene) = explode('.', $validate);
|
|
||||||
}
|
|
||||||
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
|
||||||
$v = new $class();
|
|
||||||
if (!empty($scene)) {
|
|
||||||
$v->scene($scene);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$v->message($message);
|
|
||||||
|
|
||||||
// 是否批量验证
|
|
||||||
if ($batch || $this->batchValidate) {
|
|
||||||
$v->batch(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $v->failException(true)->check($data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
// 当前文件的内容应当兼容 /extend/base/admin/config/admin.php的内容
|
||||||
|
|
||||||
use think\facade\Env;
|
use think\facade\Env;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | 应用设置
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
use think\facade\Env;
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | 控制台配置
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
return [
|
|
||||||
// 指令定义
|
|
||||||
'commands' => [
|
|
||||||
|
|
||||||
],
|
|
||||||
];
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
// | 路由设置
|
|
||||||
// +----------------------------------------------------------------------
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
// 路由中间件
|
|
||||||
'middleware' => [
|
|
||||||
|
|
||||||
],
|
|
||||||
];
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// 当前文件的内容应当兼容 /extend/base/admin/event.php的内容
|
||||||
|
|
||||||
// 事件定义文件
|
// 事件定义文件
|
||||||
return [
|
return [
|
||||||
'bind' => [
|
'bind' => [
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// 当前文件的内容应当兼容 /extend/base/admin/middleware.php的内容
|
||||||
|
|
||||||
// 全局中间件定义文件
|
// 全局中间件定义文件
|
||||||
return [
|
return [
|
||||||
|
|
||||||
|
|||||||
322
app/common.php
322
app/common.php
@@ -1,325 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// 应用公共文件
|
|
||||||
|
|
||||||
use app\commno\exception\EventException;
|
|
||||||
use app\common\service\AuthService;
|
|
||||||
use think\exception\HttpResponseException;
|
|
||||||
use think\facade\App;
|
use think\facade\App;
|
||||||
use think\facade\Cache;
|
|
||||||
use think\facade\Env;
|
|
||||||
use think\facade\Event;
|
|
||||||
use think\facade\Filesystem;
|
|
||||||
use think\response\View;
|
|
||||||
use think\route\Url;
|
|
||||||
|
|
||||||
include_once __DIR__ . '/common/app/functions.php';
|
include App::getRootPath() . '/extend/base/helper.php';
|
||||||
|
|
||||||
if (!function_exists('__url')) {
|
|
||||||
/**
|
|
||||||
* 构建URL地址
|
|
||||||
* @param string $url
|
|
||||||
* @param array $vars
|
|
||||||
* @param bool $suffix
|
|
||||||
* @param bool $domain
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function __url(string $url = '', array $vars = [], $suffix = true, $domain = false)
|
|
||||||
{
|
|
||||||
$url = url($url, $vars, $suffix, $domain)->build();
|
|
||||||
|
|
||||||
$url_data = parse_url($url);
|
|
||||||
|
|
||||||
$url_path = $url_data['path'];
|
|
||||||
|
|
||||||
$url_arr = explode('/', $url_path);
|
|
||||||
|
|
||||||
$app_map = config('app.app_map');
|
|
||||||
|
|
||||||
$app_name = array_search($url_arr[1], $app_map);
|
|
||||||
|
|
||||||
if (!empty($app_name)) {
|
|
||||||
$url_arr[1] = $app_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
$url_path = implode('/', $url_arr);
|
|
||||||
|
|
||||||
$url_data['path'] = $url_path;
|
|
||||||
|
|
||||||
$url = unparse_url($url_data);
|
|
||||||
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('password')) {
|
|
||||||
/**
|
|
||||||
* 密码加密算法.
|
|
||||||
* @param $value 需要加密的值
|
|
||||||
* @param $type 加密类型,默认为md5 (md5, hash)
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
function password($value, $salt = '_encrypt')
|
|
||||||
{
|
|
||||||
$value = sha1('ul_' . $salt) . md5($value) . md5($salt) . sha1($value);
|
|
||||||
|
|
||||||
return sha1($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('xdebug')) {
|
|
||||||
/**
|
|
||||||
* debug调试.
|
|
||||||
* @deprecated 不建议使用,建议直接使用框架自带的log组件
|
|
||||||
* @param string|array $data 打印信息
|
|
||||||
* @param string $type 类型
|
|
||||||
* @param string $suffix 文件后缀名
|
|
||||||
* @param bool $force
|
|
||||||
* @param null $file
|
|
||||||
*/
|
|
||||||
function xdebug($data, $type = 'xdebug', $suffix = null, $force = false, $file = null)
|
|
||||||
{
|
|
||||||
!is_dir(runtime_path() . 'xdebug/') && mkdir(runtime_path() . 'xdebug/');
|
|
||||||
if (is_null($file)) {
|
|
||||||
$file = is_null($suffix) ? runtime_path() . 'xdebug/' . date('Ymd') . '.txt' : runtime_path() . 'xdebug/' . date('Ymd') . "_{$suffix}" . '.txt';
|
|
||||||
}
|
|
||||||
file_put_contents($file, '[' . date('Y-m-d H:i:s') . '] ' . "========================= {$type} ===========================" . PHP_EOL, FILE_APPEND);
|
|
||||||
|
|
||||||
$str = '';
|
|
||||||
|
|
||||||
if (is_string($data)) {
|
|
||||||
$str = $data;
|
|
||||||
} else {
|
|
||||||
if (is_array($data) || is_object($data)) {
|
|
||||||
$str = print_r($data, true);
|
|
||||||
} else {
|
|
||||||
$str = var_export($data, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$str . PHP_EOL;
|
|
||||||
|
|
||||||
$force ? file_put_contents($file, $str) : file_put_contents($file, $str, FILE_APPEND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('sysconfig')) {
|
|
||||||
/**
|
|
||||||
* 获取系统配置信息.
|
|
||||||
* @param $group
|
|
||||||
* @param null|bool|string $name
|
|
||||||
* @return array|mixed
|
|
||||||
*/
|
|
||||||
function sysconfig($group, $name = null, $default = null)
|
|
||||||
{
|
|
||||||
if ($name === true) {
|
|
||||||
$value = Cache::get('sysconfig_' . $group);
|
|
||||||
|
|
||||||
if (empty($value)) {
|
|
||||||
$value = \app\admin\model\SystemConfig::where('name', $group)->value('value');
|
|
||||||
Cache::tag('sysconfig')->set('sysconfig_' . $group, $value);
|
|
||||||
}
|
|
||||||
if (is_null($value)) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
$where = ['group' => $group];
|
|
||||||
$value = empty($name) ? Cache::get("sysconfig_{$group}") : Cache::get("sysconfig_{$group}_{$name}");
|
|
||||||
if (empty($value)) {
|
|
||||||
if (!empty($name)) {
|
|
||||||
$where['name'] = $name;
|
|
||||||
$value = \app\admin\model\SystemConfig::where($where)->value('value');
|
|
||||||
Cache::tag('sysconfig')->set("sysconfig_{$group}_{$name}", $value, 3600);
|
|
||||||
} else {
|
|
||||||
$value = \app\admin\model\SystemConfig::where($where)->column('value', 'name');
|
|
||||||
Cache::tag('sysconfig')->set("sysconfig_{$group}", $value, 3600);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (is_null($value)) {
|
|
||||||
return $default;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('array_format_key')) {
|
|
||||||
/**
|
|
||||||
* 二位数组重新组合数据.
|
|
||||||
* @param $array
|
|
||||||
* @param $key
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
function array_format_key($array, $key)
|
|
||||||
{
|
|
||||||
$newArray = [];
|
|
||||||
foreach ($array as $vo) {
|
|
||||||
$newArray[$vo[$key]] = $vo;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $newArray;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('auth')) {
|
|
||||||
/**
|
|
||||||
* auth权限验证
|
|
||||||
* @param $node
|
|
||||||
* @return bool
|
|
||||||
* @throws \think\db\exception\DataNotFoundException
|
|
||||||
* @throws \think\db\exception\DbException
|
|
||||||
* @throws \think\db\exception\ModelNotFoundException
|
|
||||||
*/
|
|
||||||
function auth($node = null)
|
|
||||||
{
|
|
||||||
$authService = new AuthService(session('admin.id'));
|
|
||||||
$check = $authService->checkNode($node);
|
|
||||||
|
|
||||||
return $check;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function json_message($data = [], $code = 0, $msg = '')
|
|
||||||
{
|
|
||||||
if (is_string($data)) {
|
|
||||||
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
|
|
||||||
$data = [
|
|
||||||
'jump_to_url' => $data,
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$code = $code === 0 ? 500 : $code;
|
|
||||||
$msg = $data;
|
|
||||||
$data = [];
|
|
||||||
}
|
|
||||||
} elseif ($data instanceof Url) {
|
|
||||||
$data = [
|
|
||||||
'jump_to_url' => (string) $data,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
return json([
|
|
||||||
'code' => $code,
|
|
||||||
'msg' => $msg,
|
|
||||||
'data' => $data,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!function_exists('unparse_url')) {
|
|
||||||
function unparse_url($parsed_url)
|
|
||||||
{
|
|
||||||
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
|
||||||
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
|
||||||
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
|
||||||
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
|
||||||
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
|
||||||
$pass = ($user || $pass) ? "$pass@" : '';
|
|
||||||
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
|
||||||
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
|
||||||
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
|
|
||||||
|
|
||||||
return "$scheme$user$pass$host$port$path$query$fragment";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function build_upload_url($url, $upload_type = null)
|
|
||||||
{
|
|
||||||
if (is_null($upload_type)) {
|
|
||||||
$upload_type = sysconfig('upload', 'upload_type', 'local_public');
|
|
||||||
}
|
|
||||||
|
|
||||||
return Filesystem::disk($upload_type)->url($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
function event_handle_result($name, $key, $type = 'all', $params = []) : array
|
|
||||||
{
|
|
||||||
$list_result = Event::trigger($name, $params);
|
|
||||||
|
|
||||||
$result = [];
|
|
||||||
|
|
||||||
foreach ($list_result as $key_event => $value_event) {
|
|
||||||
if (!isset($value_event[$key])) {
|
|
||||||
if (Env::get('adminsystem.strict_event')) {
|
|
||||||
throw new EventException("Event view {$name} trigger a result without a {$key}");
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($type == 'all') {
|
|
||||||
$result[] = $value_event[$key];
|
|
||||||
} elseif ($type == 'last') {
|
|
||||||
$result = [];
|
|
||||||
$result[] = $value_event[$key];
|
|
||||||
} elseif ($type == 'first') {
|
|
||||||
$result[] = $value_event[$key];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
function event_view_content($name)
|
|
||||||
{
|
|
||||||
$list_result = event_handle_result($name, 'view_content');
|
|
||||||
|
|
||||||
$content = implode('', $list_result);
|
|
||||||
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
function event_view_replace($content, $name)
|
|
||||||
{
|
|
||||||
$list_result = event_handle_result($name, 'view_replace');
|
|
||||||
|
|
||||||
$content_event = implode('', $list_result);
|
|
||||||
|
|
||||||
if (empty($content_event)) {
|
|
||||||
return $content;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $content_event;
|
|
||||||
}
|
|
||||||
|
|
||||||
function event_view_replace_js($name)
|
|
||||||
{
|
|
||||||
$list_result = event_handle_result($name, 'view_replace_js');
|
|
||||||
|
|
||||||
$content_event = implode('', $list_result);
|
|
||||||
|
|
||||||
return "<script id='event-replace-js-{$name}' type='text/plain'>{$content_event}</script>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function event_response($name, $params = [])
|
|
||||||
{
|
|
||||||
$list_result = event_handle_result($name, 'response', 'last', $params);
|
|
||||||
|
|
||||||
if (empty($list_result)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $list_result[0];
|
|
||||||
|
|
||||||
if (is_string($response)) {
|
|
||||||
$response = View::create($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new HttpResponseException($response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 以扩展的架构定位app下的文件位置
|
|
||||||
*
|
|
||||||
* @param string $file_path 文件路径,不要以/开头,不需要以app开头,会自动定位app或extend/base。
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
function app_file_path($file_path)
|
|
||||||
{
|
|
||||||
$app_file_path = App::getRootPath() . 'app' . DIRECTORY_SEPARATOR . $file_path;
|
|
||||||
if (!is_file($app_file_path)) {
|
|
||||||
$app_file_path = App::getRootPath() . 'extend' . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . $file_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $app_file_path;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<?php
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
|
|
||||||
];
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
use think\migration\Migrator;
|
|
||||||
use think\migration\db\Column;
|
|
||||||
|
|
||||||
class {$class_name} extends Migrator
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Change Method.
|
|
||||||
*
|
|
||||||
* Write your reversible migrations using this method.
|
|
||||||
*
|
|
||||||
* More information on writing migrations is available here:
|
|
||||||
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
|
|
||||||
*
|
|
||||||
* The following commands can be used in this method and Phinx will
|
|
||||||
* automatically reverse them when rolling back:
|
|
||||||
*
|
|
||||||
* createTable
|
|
||||||
* renameTable
|
|
||||||
* addColumn
|
|
||||||
* renameColumn
|
|
||||||
* addIndex
|
|
||||||
* addForeignKey
|
|
||||||
*
|
|
||||||
* Remember to call "create()" or "update()" and NOT "save()" when working
|
|
||||||
* with the Table class.
|
|
||||||
*/
|
|
||||||
public function change()
|
|
||||||
{
|
|
||||||
$table = $this->table('{$table}')
|
|
||||||
->setComment('{$table_info.TABLE_COMMENT}')
|
|
||||||
{volist name="table_columns" id="column"}->addColumn('{$column.field}', '{$column.type}', [{volist name="column.options" id="option"}'{$key}' => {$option|raw}, {/volist}])
|
|
||||||
{/volist}
|
|
||||||
{volist name="table_keys_uni" id="vo"}->addIndex('{$vo}',['unique'=>true])
|
|
||||||
{/volist}
|
|
||||||
{volist name="table_keys_text" id="vo"}->addIndex('{$vo}',['type'=>'fulltext'])
|
|
||||||
{/volist}
|
|
||||||
{volist name="table_keys" id="vo"}->addIndex('{$vo}')
|
|
||||||
{/volist}->create();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return [
|
|
||||||
[
|
|
||||||
'name' => 'http_demo', // 定时任务的名称,不能重复
|
|
||||||
'type' => 'site', // 定时任务的类型,默认只支持site,你也可以重写定时器命令行以支持其他命令
|
|
||||||
'target' => '/tools/timer.ResetPassword/do', // 要访问的地址,如果不是以https开头,那么以后台的系统配置中读取相关配置,如果没有配置则不执行
|
|
||||||
'frequency' => 600 // 执行频率,单位:秒,填写10,则每10秒过后执行一次
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'name' => 'clear_log', // 定时任务的名称,不能重复
|
|
||||||
'type' => 'site', // 定时任务的类型,默认只支持site,你也可以重写定时器命令行以支持其他命令
|
|
||||||
'target' => '/tools/timer.ClearLog/do', // 要访问的地址,如果不是以https开头,那么以后台的系统配置中读取相关配置,如果没有配置则不执行
|
|
||||||
'frequency' => 600 // 执行频率,单位:秒,填写10,则每10秒过后执行一次
|
|
||||||
],
|
|
||||||
];
|
|
||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
// 事件定义文件
|
// 事件定义文件
|
||||||
|
|
||||||
use app\common\event\AdminLoginSuccess\LogEvent;
|
return [
|
||||||
use app\common\event\AdminLoginType\DemoEvent;
|
|
||||||
|
|
||||||
$event = [
|
|
||||||
'bind' => [
|
'bind' => [
|
||||||
],
|
],
|
||||||
|
|
||||||
@@ -16,19 +13,13 @@ $event = [
|
|||||||
'LogLevel' => [],
|
'LogLevel' => [],
|
||||||
'LogWrite' => [],
|
'LogWrite' => [],
|
||||||
'AdminLoginSuccess' => [
|
'AdminLoginSuccess' => [
|
||||||
LogEvent::class,
|
|
||||||
],
|
],
|
||||||
'AdminLoginType' => [
|
'AdminLoginType' => [
|
||||||
DemoEvent::class,
|
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
'subscribe' => [
|
'subscribe' => [
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$listen = include __DIR__ . '/common/app/listen.php';
|
|
||||||
|
|
||||||
$event['listen'] = array_merge($event['listen'], $listen);
|
|
||||||
|
|
||||||
return $event;
|
|
||||||
|
|||||||
@@ -2,19 +2,6 @@
|
|||||||
|
|
||||||
// 全局中间件定义文件
|
// 全局中间件定义文件
|
||||||
|
|
||||||
$middleware_default = [
|
return [
|
||||||
// 全局请求缓存
|
|
||||||
// \think\middleware\CheckRequestCache::class,
|
|
||||||
// 多语言加载
|
|
||||||
// \think\middleware\LoadLangPack::class,
|
|
||||||
// Session初始化
|
|
||||||
100 => \think\middleware\SessionInit::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$middleware_common = include_once __DIR__ . '/common/app/middleware.php';
|
|
||||||
|
|
||||||
$middleware = array_merge($middleware_default, $middleware_common);
|
|
||||||
|
|
||||||
ksort($middleware);
|
|
||||||
|
|
||||||
return $middleware;
|
|
||||||
|
|||||||
@@ -2,16 +2,6 @@
|
|||||||
|
|
||||||
// 容器Provider定义文件
|
// 容器Provider定义文件
|
||||||
|
|
||||||
use app\common\provider\ExceptionHandle;
|
return [
|
||||||
use app\common\provider\Request;
|
|
||||||
use app\common\provider\View;
|
|
||||||
|
|
||||||
$provider_default = [
|
|
||||||
'think\Request' => Request::class,
|
|
||||||
'think\exception\Handle' => ExceptionHandle::class,
|
|
||||||
'think\View' => View::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$provider_common = include_once __DIR__ . '/common/app/provider.php';
|
|
||||||
|
|
||||||
return array_merge($provider_default, $provider_common);
|
|
||||||
|
|||||||
@@ -2,18 +2,10 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use think\migration\Service;
|
use think\UlthonAdminService;
|
||||||
|
|
||||||
$service_default = [
|
$service = [
|
||||||
0 => 'think\\captcha\\CaptchaService',
|
10 => UlthonAdminService::class,
|
||||||
1 => 'think\\app\\Service',
|
|
||||||
2 => Service::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$service_common = include_once __DIR__ . '/common/app/service.php';
|
|
||||||
|
|
||||||
$service = array_merge($service_default, $service_common);
|
|
||||||
|
|
||||||
ksort($service);
|
|
||||||
|
|
||||||
return $service;
|
return $service;
|
||||||
|
|||||||
@@ -4,21 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace app\tools\controller\timer;
|
namespace app\tools\controller\timer;
|
||||||
|
|
||||||
use app\common\controller\TimerController;
|
use base\tools\controller\timer\ClearLogBase;
|
||||||
use think\facade\Db;
|
|
||||||
use think\facade\Log;
|
|
||||||
use think\Request;
|
|
||||||
|
|
||||||
class ClearLog extends TimerController
|
class ClearLog extends ClearLogBase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $frequency = 600;
|
|
||||||
|
|
||||||
public function do()
|
|
||||||
{
|
|
||||||
Log::debug('清除3天的日志');
|
|
||||||
Db::name('debug_log')->where('create_time', '<', time() - 60 * 60 * 24 * 3)->delete();
|
|
||||||
|
|
||||||
return 'success';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,25 +4,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace app\tools\controller\timer;
|
namespace app\tools\controller\timer;
|
||||||
|
|
||||||
use app\common\controller\TimerController;
|
use base\tools\controller\timer\ResetPasswordBase;
|
||||||
use think\facade\Console;
|
|
||||||
|
|
||||||
class ResetPassword extends TimerController
|
class ResetPassword extends ResetPasswordBase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected $frequency = 600;
|
|
||||||
|
|
||||||
public function do()
|
|
||||||
{
|
|
||||||
|
|
||||||
if (!env('adminsystem.is_demo', false)) {
|
|
||||||
return $this->error('本功能只有在演示环境下在能使用', '', '/');
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = Console::call('admin:resetPassword', [
|
|
||||||
'--password=123456'
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $output->fetch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
100
extend/base/BaseControllerBase.php
Normal file
100
extend/base/BaseControllerBase.php
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace base;
|
||||||
|
|
||||||
|
use think\App;
|
||||||
|
use think\exception\ValidateException;
|
||||||
|
use think\facade\Log;
|
||||||
|
use think\Validate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器基础类
|
||||||
|
*/
|
||||||
|
abstract class BaseControllerBase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Request实例
|
||||||
|
* @var \think\Request
|
||||||
|
*/
|
||||||
|
protected $request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用实例
|
||||||
|
* @var \think\App
|
||||||
|
*/
|
||||||
|
protected $app;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否批量验证
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $batchValidate = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器中间件
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $middleware = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构造方法
|
||||||
|
* @access public
|
||||||
|
* @param App $app 应用对象
|
||||||
|
*/
|
||||||
|
public function __construct(App $app)
|
||||||
|
{
|
||||||
|
$this->app = $app;
|
||||||
|
$this->request = $this->app->request;
|
||||||
|
|
||||||
|
// 控制器初始化
|
||||||
|
$this->initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
protected function initialize()
|
||||||
|
{
|
||||||
|
|
||||||
|
Log::debug('request url :' . $this->request->url());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证数据
|
||||||
|
* @access protected
|
||||||
|
* @param array $data 数据
|
||||||
|
* @param string|array $validate 验证器名或者验证规则数组
|
||||||
|
* @param array $message 提示信息
|
||||||
|
* @param bool $batch 是否批量验证
|
||||||
|
* @return array|string|true
|
||||||
|
* @throws ValidateException
|
||||||
|
*/
|
||||||
|
protected function validate(array $data, $validate, array $message = [], bool $batch = false)
|
||||||
|
{
|
||||||
|
if (is_array($validate)) {
|
||||||
|
$v = new Validate();
|
||||||
|
$v->rule($validate);
|
||||||
|
} else if ($validate instanceof Validate) {
|
||||||
|
$v = $validate;
|
||||||
|
} else {
|
||||||
|
if (strpos($validate, '.')) {
|
||||||
|
// 支持场景
|
||||||
|
list($validate, $scene) = explode('.', $validate);
|
||||||
|
}
|
||||||
|
$class = false !== strpos($validate, '\\') ? $validate : $this->app->parseClass('validate', $validate);
|
||||||
|
$v = new $class();
|
||||||
|
if (!empty($scene)) {
|
||||||
|
$v->scene($scene);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$v->message($message);
|
||||||
|
|
||||||
|
// 是否批量验证
|
||||||
|
if ($batch || $this->batchValidate) {
|
||||||
|
$v->batch(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $v->failException(true)->check($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
18
extend/base/admin/event.php
Normal file
18
extend/base/admin/event.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// 事件定义文件
|
||||||
|
return [
|
||||||
|
'bind' => [
|
||||||
|
],
|
||||||
|
|
||||||
|
'listen' => [
|
||||||
|
'AppInit' => [],
|
||||||
|
'HttpRun' => [],
|
||||||
|
'HttpEnd' => [],
|
||||||
|
'LogLevel' => [],
|
||||||
|
'LogWrite' => [],
|
||||||
|
],
|
||||||
|
|
||||||
|
'subscribe' => [
|
||||||
|
],
|
||||||
|
];
|
||||||
14
extend/base/admin/middleware.php
Normal file
14
extend/base/admin/middleware.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
// 全局中间件定义文件
|
||||||
|
return [
|
||||||
|
|
||||||
|
// Session初始化
|
||||||
|
\think\middleware\SessionInit::class,
|
||||||
|
|
||||||
|
// 系统操作日志
|
||||||
|
\app\admin\middleware\SystemLog::class,
|
||||||
|
|
||||||
|
// Csrf安全校验
|
||||||
|
\app\admin\middleware\CsrfMiddleware::class,
|
||||||
|
|
||||||
|
];
|
||||||
@@ -45,7 +45,7 @@ class TimerBase extends Command
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
$config_list = include __DIR__ . '/timer/config.php';
|
$config_list = include app_file_path('common/command/timer/config.php');
|
||||||
|
|
||||||
$list_promises = [];
|
$list_promises = [];
|
||||||
foreach ($config_list as $config_item) {
|
foreach ($config_list as $config_item) {
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ class MigrateBase extends Command
|
|||||||
$data['table_keys_uni'] = $table_keys_uni;
|
$data['table_keys_uni'] = $table_keys_uni;
|
||||||
$data['table_keys_text'] = $table_keys_text;
|
$data['table_keys_text'] = $table_keys_text;
|
||||||
|
|
||||||
$migrate_content = View::fetch(__DIR__ . '/migrate.tpl', $data);
|
$migrate_content = View::fetch(app_file_path('common/command/curd/migrate.tpl'), $data);
|
||||||
|
|
||||||
file_put_contents(__DIR__ . '/migrate_output.php', "<?php\n\n" . $migrate_content);
|
file_put_contents(__DIR__ . '/migrate_output.php', "<?php\n\n" . $migrate_content);
|
||||||
file_put_contents($dist_file_path, "<?php\n\n" . $migrate_content);
|
file_put_contents($dist_file_path, "<?php\n\n" . $migrate_content);
|
||||||
|
|||||||
325
extend/base/helper.php
Normal file
325
extend/base/helper.php
Normal file
@@ -0,0 +1,325 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
// 应用公共文件
|
||||||
|
|
||||||
|
use app\commno\exception\EventException;
|
||||||
|
use app\common\service\AuthService;
|
||||||
|
use think\exception\HttpResponseException;
|
||||||
|
use think\facade\App;
|
||||||
|
use think\facade\Cache;
|
||||||
|
use think\facade\Env;
|
||||||
|
use think\facade\Event;
|
||||||
|
use think\facade\Filesystem;
|
||||||
|
use think\response\View;
|
||||||
|
use think\route\Url;
|
||||||
|
|
||||||
|
include_once __DIR__ . '/common/app/functions.php';
|
||||||
|
|
||||||
|
if (!function_exists('__url')) {
|
||||||
|
/**
|
||||||
|
* 构建URL地址
|
||||||
|
* @param string $url
|
||||||
|
* @param array $vars
|
||||||
|
* @param bool $suffix
|
||||||
|
* @param bool $domain
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function __url(string $url = '', array $vars = [], $suffix = true, $domain = false)
|
||||||
|
{
|
||||||
|
$url = url($url, $vars, $suffix, $domain)->build();
|
||||||
|
|
||||||
|
$url_data = parse_url($url);
|
||||||
|
|
||||||
|
$url_path = $url_data['path'];
|
||||||
|
|
||||||
|
$url_arr = explode('/', $url_path);
|
||||||
|
|
||||||
|
$app_map = config('app.app_map');
|
||||||
|
|
||||||
|
$app_name = array_search($url_arr[1], $app_map);
|
||||||
|
|
||||||
|
if (!empty($app_name)) {
|
||||||
|
$url_arr[1] = $app_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url_path = implode('/', $url_arr);
|
||||||
|
|
||||||
|
$url_data['path'] = $url_path;
|
||||||
|
|
||||||
|
$url = unparse_url($url_data);
|
||||||
|
|
||||||
|
return $url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('password')) {
|
||||||
|
/**
|
||||||
|
* 密码加密算法.
|
||||||
|
* @param $value 需要加密的值
|
||||||
|
* @param $type 加密类型,默认为md5 (md5, hash)
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
function password($value, $salt = '_encrypt')
|
||||||
|
{
|
||||||
|
$value = sha1('ul_' . $salt) . md5($value) . md5($salt) . sha1($value);
|
||||||
|
|
||||||
|
return sha1($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('xdebug')) {
|
||||||
|
/**
|
||||||
|
* debug调试.
|
||||||
|
* @deprecated 不建议使用,建议直接使用框架自带的log组件
|
||||||
|
* @param string|array $data 打印信息
|
||||||
|
* @param string $type 类型
|
||||||
|
* @param string $suffix 文件后缀名
|
||||||
|
* @param bool $force
|
||||||
|
* @param null $file
|
||||||
|
*/
|
||||||
|
function xdebug($data, $type = 'xdebug', $suffix = null, $force = false, $file = null)
|
||||||
|
{
|
||||||
|
!is_dir(runtime_path() . 'xdebug/') && mkdir(runtime_path() . 'xdebug/');
|
||||||
|
if (is_null($file)) {
|
||||||
|
$file = is_null($suffix) ? runtime_path() . 'xdebug/' . date('Ymd') . '.txt' : runtime_path() . 'xdebug/' . date('Ymd') . "_{$suffix}" . '.txt';
|
||||||
|
}
|
||||||
|
file_put_contents($file, '[' . date('Y-m-d H:i:s') . '] ' . "========================= {$type} ===========================" . PHP_EOL, FILE_APPEND);
|
||||||
|
|
||||||
|
$str = '';
|
||||||
|
|
||||||
|
if (is_string($data)) {
|
||||||
|
$str = $data;
|
||||||
|
} else {
|
||||||
|
if (is_array($data) || is_object($data)) {
|
||||||
|
$str = print_r($data, true);
|
||||||
|
} else {
|
||||||
|
$str = var_export($data, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$str . PHP_EOL;
|
||||||
|
|
||||||
|
$force ? file_put_contents($file, $str) : file_put_contents($file, $str, FILE_APPEND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('sysconfig')) {
|
||||||
|
/**
|
||||||
|
* 获取系统配置信息.
|
||||||
|
* @param $group
|
||||||
|
* @param null|bool|string $name
|
||||||
|
* @return array|mixed
|
||||||
|
*/
|
||||||
|
function sysconfig($group, $name = null, $default = null)
|
||||||
|
{
|
||||||
|
if ($name === true) {
|
||||||
|
$value = Cache::get('sysconfig_' . $group);
|
||||||
|
|
||||||
|
if (empty($value)) {
|
||||||
|
$value = \app\admin\model\SystemConfig::where('name', $group)->value('value');
|
||||||
|
Cache::tag('sysconfig')->set('sysconfig_' . $group, $value);
|
||||||
|
}
|
||||||
|
if (is_null($value)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
$where = ['group' => $group];
|
||||||
|
$value = empty($name) ? Cache::get("sysconfig_{$group}") : Cache::get("sysconfig_{$group}_{$name}");
|
||||||
|
if (empty($value)) {
|
||||||
|
if (!empty($name)) {
|
||||||
|
$where['name'] = $name;
|
||||||
|
$value = \app\admin\model\SystemConfig::where($where)->value('value');
|
||||||
|
Cache::tag('sysconfig')->set("sysconfig_{$group}_{$name}", $value, 3600);
|
||||||
|
} else {
|
||||||
|
$value = \app\admin\model\SystemConfig::where($where)->column('value', 'name');
|
||||||
|
Cache::tag('sysconfig')->set("sysconfig_{$group}", $value, 3600);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_null($value)) {
|
||||||
|
return $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('array_format_key')) {
|
||||||
|
/**
|
||||||
|
* 二位数组重新组合数据.
|
||||||
|
* @param $array
|
||||||
|
* @param $key
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function array_format_key($array, $key)
|
||||||
|
{
|
||||||
|
$newArray = [];
|
||||||
|
foreach ($array as $vo) {
|
||||||
|
$newArray[$vo[$key]] = $vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newArray;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('auth')) {
|
||||||
|
/**
|
||||||
|
* auth权限验证
|
||||||
|
* @param $node
|
||||||
|
* @return bool
|
||||||
|
* @throws \think\db\exception\DataNotFoundException
|
||||||
|
* @throws \think\db\exception\DbException
|
||||||
|
* @throws \think\db\exception\ModelNotFoundException
|
||||||
|
*/
|
||||||
|
function auth($node = null)
|
||||||
|
{
|
||||||
|
$authService = new AuthService(session('admin.id'));
|
||||||
|
$check = $authService->checkNode($node);
|
||||||
|
|
||||||
|
return $check;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function json_message($data = [], $code = 0, $msg = '')
|
||||||
|
{
|
||||||
|
if (is_string($data)) {
|
||||||
|
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
|
||||||
|
$data = [
|
||||||
|
'jump_to_url' => $data,
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$code = $code === 0 ? 500 : $code;
|
||||||
|
$msg = $data;
|
||||||
|
$data = [];
|
||||||
|
}
|
||||||
|
} elseif ($data instanceof Url) {
|
||||||
|
$data = [
|
||||||
|
'jump_to_url' => (string) $data,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return json([
|
||||||
|
'code' => $code,
|
||||||
|
'msg' => $msg,
|
||||||
|
'data' => $data,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!function_exists('unparse_url')) {
|
||||||
|
function unparse_url($parsed_url)
|
||||||
|
{
|
||||||
|
$scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
|
||||||
|
$host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
|
||||||
|
$port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
|
||||||
|
$user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
|
||||||
|
$pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
|
||||||
|
$pass = ($user || $pass) ? "$pass@" : '';
|
||||||
|
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
|
||||||
|
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
|
||||||
|
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
|
||||||
|
|
||||||
|
return "$scheme$user$pass$host$port$path$query$fragment";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function build_upload_url($url, $upload_type = null)
|
||||||
|
{
|
||||||
|
if (is_null($upload_type)) {
|
||||||
|
$upload_type = sysconfig('upload', 'upload_type', 'local_public');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Filesystem::disk($upload_type)->url($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
function event_handle_result($name, $key, $type = 'all', $params = []) : array
|
||||||
|
{
|
||||||
|
$list_result = Event::trigger($name, $params);
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($list_result as $key_event => $value_event) {
|
||||||
|
if (!isset($value_event[$key])) {
|
||||||
|
if (Env::get('adminsystem.strict_event')) {
|
||||||
|
throw new EventException("Event view {$name} trigger a result without a {$key}");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($type == 'all') {
|
||||||
|
$result[] = $value_event[$key];
|
||||||
|
} elseif ($type == 'last') {
|
||||||
|
$result = [];
|
||||||
|
$result[] = $value_event[$key];
|
||||||
|
} elseif ($type == 'first') {
|
||||||
|
$result[] = $value_event[$key];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function event_view_content($name)
|
||||||
|
{
|
||||||
|
$list_result = event_handle_result($name, 'view_content');
|
||||||
|
|
||||||
|
$content = implode('', $list_result);
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
function event_view_replace($content, $name)
|
||||||
|
{
|
||||||
|
$list_result = event_handle_result($name, 'view_replace');
|
||||||
|
|
||||||
|
$content_event = implode('', $list_result);
|
||||||
|
|
||||||
|
if (empty($content_event)) {
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $content_event;
|
||||||
|
}
|
||||||
|
|
||||||
|
function event_view_replace_js($name)
|
||||||
|
{
|
||||||
|
$list_result = event_handle_result($name, 'view_replace_js');
|
||||||
|
|
||||||
|
$content_event = implode('', $list_result);
|
||||||
|
|
||||||
|
return "<script id='event-replace-js-{$name}' type='text/plain'>{$content_event}</script>";
|
||||||
|
}
|
||||||
|
|
||||||
|
function event_response($name, $params = [])
|
||||||
|
{
|
||||||
|
$list_result = event_handle_result($name, 'response', 'last', $params);
|
||||||
|
|
||||||
|
if (empty($list_result)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $list_result[0];
|
||||||
|
|
||||||
|
if (is_string($response)) {
|
||||||
|
$response = View::create($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new HttpResponseException($response);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 以扩展的架构定位app下的文件位置.
|
||||||
|
*
|
||||||
|
* @param string $file_path 文件路径,不要以/开头,不需要以app开头,会自动定位app或extend/base。
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function app_file_path($file_path)
|
||||||
|
{
|
||||||
|
$app_file_path = App::getRootPath() . 'app' . DIRECTORY_SEPARATOR . $file_path;
|
||||||
|
if (!is_file($app_file_path)) {
|
||||||
|
$app_file_path = App::getRootPath() . 'extend' . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . $file_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $app_file_path;
|
||||||
|
}
|
||||||
22
extend/base/tools/controller/timer/ClearLogBase.php
Normal file
22
extend/base/tools/controller/timer/ClearLogBase.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace base\tools\controller\timer;
|
||||||
|
|
||||||
|
use app\common\controller\TimerController;
|
||||||
|
use think\facade\Db;
|
||||||
|
use think\facade\Log;
|
||||||
|
|
||||||
|
class ClearLogBase extends TimerController
|
||||||
|
{
|
||||||
|
protected $frequency = 600;
|
||||||
|
|
||||||
|
public function do()
|
||||||
|
{
|
||||||
|
Log::debug('清除3天的日志');
|
||||||
|
Db::name('debug_log')->where('create_time', '<', time() - 60 * 60 * 24 * 3)->delete();
|
||||||
|
|
||||||
|
return 'success';
|
||||||
|
}
|
||||||
|
}
|
||||||
26
extend/base/tools/controller/timer/ResetPasswordBase.php
Normal file
26
extend/base/tools/controller/timer/ResetPasswordBase.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace base\tools\controller\timer;
|
||||||
|
|
||||||
|
use app\common\controller\TimerController;
|
||||||
|
use think\facade\Console;
|
||||||
|
|
||||||
|
class ResetPasswordBase extends TimerController
|
||||||
|
{
|
||||||
|
protected $frequency = 600;
|
||||||
|
|
||||||
|
public function do()
|
||||||
|
{
|
||||||
|
if (!env('adminsystem.is_demo', false)) {
|
||||||
|
return $this->error('本功能只有在演示环境下在能使用', '', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = Console::call('admin:resetPassword', [
|
||||||
|
'--password=123456',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $output->fetch();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
extend/think/UlthonAdminApp.php
Normal file
18
extend/think/UlthonAdminApp.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace think;
|
||||||
|
|
||||||
|
class UlthonAdminApp extends App
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 加载应用文件和配置.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function load(): void
|
||||||
|
{
|
||||||
|
// 引入系统函数
|
||||||
|
include App::getRootPath() . '/extend/base/helper.php';
|
||||||
|
|
||||||
|
parent::load();
|
||||||
|
}
|
||||||
|
}
|
||||||
76
extend/think/UlthonAdminService.php
Normal file
76
extend/think/UlthonAdminService.php
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace think;
|
||||||
|
|
||||||
|
use app\common\event\AdminLoginSuccess\LogEvent;
|
||||||
|
use app\common\event\AdminLoginType\DemoEvent;
|
||||||
|
use app\common\provider\ExceptionHandle;
|
||||||
|
use app\common\provider\Request;
|
||||||
|
use app\common\provider\View;
|
||||||
|
use think\app\Service as AppService;
|
||||||
|
use think\captcha\CaptchaService;
|
||||||
|
use think\facade\App;
|
||||||
|
use think\migration\Service;
|
||||||
|
|
||||||
|
class UlthonAdminService extends \think\Service
|
||||||
|
{
|
||||||
|
public function boot()
|
||||||
|
{
|
||||||
|
// 绑定系统事件
|
||||||
|
$event_listen = [
|
||||||
|
'AppInit' => [],
|
||||||
|
'HttpRun' => [],
|
||||||
|
'HttpEnd' => [],
|
||||||
|
'LogLevel' => [],
|
||||||
|
'LogWrite' => [],
|
||||||
|
'AdminLoginSuccess' => [
|
||||||
|
LogEvent::class,
|
||||||
|
],
|
||||||
|
'AdminLoginType' => [
|
||||||
|
DemoEvent::class,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->app->event->listenEvents($event_listen);
|
||||||
|
|
||||||
|
// 注册验证码服务
|
||||||
|
$this->app->register(CaptchaService::class);
|
||||||
|
|
||||||
|
// 注册多应用服务
|
||||||
|
$this->app->register(AppService::class);
|
||||||
|
|
||||||
|
// 注册数据库迁移服务
|
||||||
|
$this->app->register(Service::class);
|
||||||
|
|
||||||
|
// 绑定标识容器
|
||||||
|
|
||||||
|
$provider_default = [
|
||||||
|
'think\Request' => Request::class,
|
||||||
|
'think\exception\Handle' => ExceptionHandle::class,
|
||||||
|
'think\View' => View::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
$provider_setting = include App::getRootPath() . '/app/provider.php';
|
||||||
|
|
||||||
|
if (isset($provider_setting['think\App'])) {
|
||||||
|
unset($provider_setting['think\App']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$provider = array_merge($provider_default, $provider_setting);
|
||||||
|
|
||||||
|
$this->app->bind($provider);
|
||||||
|
|
||||||
|
// 导入系统中间件
|
||||||
|
|
||||||
|
$middleware = [
|
||||||
|
// 全局请求缓存
|
||||||
|
// \think\middleware\CheckRequestCache::class,
|
||||||
|
// 多语言加载
|
||||||
|
// \think\middleware\LoadLangPack::class,
|
||||||
|
// Session初始化
|
||||||
|
100 => \think\middleware\SessionInit::class,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->app->middleware->import($middleware);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user