This commit is contained in:
2025-10-29 15:32:26 +08:00
parent d90614805b
commit b7462657cd
78921 changed files with 2753938 additions and 71 deletions

View File

@@ -0,0 +1,24 @@
<?php
/**
*/
namespace app\event\init;
/**
* 应用结束
*/
class AppEnd
{
// 行为扩展的执行入口必须是run
public function handle()
{
return success();
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
*/
namespace app\event\init;
use app\model\system\Addon;
use think\facade\Event;
use think\facade\Cache;
/**
* 初始化插件
*/
class InitAddon
{
// 行为扩展的执行入口必须是run
public function handle()
{
if (defined('BIND_MODULE') && BIND_MODULE === 'install') return;
$this->InitEvent();
}
/**
* 初始化事件
*/
private function InitEvent()
{
$cache = Cache::get("addon_event_list");
if (!defined("initroute_tag")) exit();
if (empty($cache)) {
$addon_model = new Addon();
$addon_data = $addon_model->getAddonList([], 'name');
$listen_array = [];
foreach ($addon_data[ 'data' ] as $k => $v) {
if (file_exists('addon/' . $v[ 'name' ] . '/config/event.php')) {
$addon_event = require_once 'addon/' . $v[ 'name' ] . '/config/event.php';
$listen = $addon_event['listen'] ?? [];
if (!empty($listen)) {
$listen_array[] = $listen;
}
}
}
Cache::tag("addon")->set("addon_event_list", $listen_array);
} else {
$listen_array = $cache;
}
if (!empty($listen_array)) {
foreach ($listen_array as $k => $listen) {
if (!empty($listen)) {
Event::listenEvents($listen);
}
}
}
}
}

View File

@@ -0,0 +1,142 @@
<?php
/**
*/
namespace app\event\init;
use think\facade\Config;
/**
* 初始化配置信息
* @author Administrator
*
*/
class InitConfig
{
public function handle()
{
// 初始化常量
$this->initConst();
//初始化配置信息
$this->initConfig();
}
/**
* 初始化常量
*/
private function initConst()
{
//加载版本信息
define('SHOP_MODULE', 'shop');
defined('SYS_VERSION_NO') or define('SYS_VERSION_NO', Config::get('info.version')); //版本号
defined('SYS_VERSION_NAME') or define('SYS_VERSION_NAME', Config::get('info.title')); //版本名称
defined('SYS_VERSION') or define('SYS_VERSION', Config::get('info.name')); //版本类型
defined('SYS_RELEASE') or define('SYS_RELEASE', Config::get('info.version_no')); //版本号
//是否展示帮助快捷链接
define('HELP_SHOW', 1);
//加载基础化配置信息
define('__ROOT__', str_replace([ '/index.php', '/install.php' ], '', request()->root(true)));
define('__PUBLIC__', __ROOT__ . '/public');
define('__UPLOAD__', 'upload');
//插件目录名称
define('ADDON_DIR_NAME', 'addon');
//插件目录路径
define('ADDON_PATH', 'addon/');
//分页每页数量
define('PAGE_LIST_ROWS', 10);
define('MEMBER_LEVEL', 10);
//伪静态模式是否开启
define('REWRITE_MODULE', true);
// public目录绝对路径
define('PUBLIC_PATH', root_path() . '/public/');
// 项目绝对路径
define('ROOT_PATH', root_path());
//兼容模式访问
if (!REWRITE_MODULE) {
define('ROOT_URL', request()->root(true) . '/?s=');
} else {
define('ROOT_URL', request()->root(true));
}
//检测网址访问
$url = request()->url(true);
$url = strtolower($url);
if (strstr($url, 'call_user_func_array') || strstr($url, 'invokefunction') || strstr($url, 'think\view')) {
die("非法请求");
}
// 应用模块
$GLOBALS[ 'system_array' ] = [ 'shop', 'install', 'cron', 'api', 'pay', 'public', 'app', 'index', SHOP_MODULE ];
$GLOBALS[ 'app_array' ] = [ 'shop', 'store' ];
}
/**
* 初始化配置信息
*/
private function initConfig()
{
$view_array = [
// 模板引擎类型使用Think
'type' => 'Think',
// 默认模板渲染规则 1 解析为小写+下划线 2 全部转换小写 3 保持操作方法
'auto_rule' => 1,
// 模板目录名
'view_dir_name' => 'view',
// 模板后缀
'view_suffix' => 'html',
// 模板文件名分隔符
'view_depr' => DIRECTORY_SEPARATOR,
// 模板引擎普通标签开始标记
'tpl_begin' => '{',
// 模板引擎普通标签结束标记
'tpl_end' => '}',
// 标签库标签开始标记
'taglib_begin' => '{',
// 标签库标签结束标记
'taglib_end' => '}',
'tpl_cache' => false, //模板缓存部署模式后改为true
'tpl_replace_string' => [
'__ROOT__' => __ROOT__,
'__PUBLIC__' => __PUBLIC__,
'ROOT_URL' => ROOT_URL,
'__STATIC__' => __PUBLIC__ . '/static',
'STATIC_EXT' => __PUBLIC__ . '/static/ext',
'STATIC_CSS' => __PUBLIC__ . '/static/css',
'STATIC_JS' => __PUBLIC__ . '/static/js',
'STATIC_IMG' => __PUBLIC__ . '/static/img',
'HOME_IMG' => __ROOT__ . '/app/home/view/public/img',
'HOME_CSS' => __ROOT__ . '/app/home/view/public/css',
'HOME_JS' => __ROOT__ . '/app/home/view/public/js',
'SHOP_IMG' => __ROOT__ . '/app/shop/view/public/img',
'SHOP_CSS' => __ROOT__ . '/app/shop/view/public/css',
'PLATFORM_CSS' => __ROOT__ . '/app/platform/view/public/css',
'PLATFORM_JS' => __ROOT__ . '/app/platform/view/public/js',
'MERCHANT_CSS' => __ROOT__ . '/app/merchant/view/public/css',
'MERCHANT_JS' => __ROOT__ . '/app/merchant/view/public/js',
'SHOP_JS' => __ROOT__ . '/app/shop/view/public/js',
'__UPLOAD__' => __UPLOAD__,
'INDEX_IMG' => __ROOT__ . '/app/index/view/public/img',
'INDEX_CSS' => __ROOT__ . '/app/index/view/public/css',
'INDEX_JS' => __ROOT__ . '/app/index/view/public/js',
]
];
Config::set($view_array, 'view');
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
*/
namespace app\event\init;
use app\dict\system\ScheduleDict;
use app\model\system\Cron;
use think\facade\Cache;
/**
* 初始化计划任务启动
* @author Administrator
*
*/
class InitCron
{
public function handle()
{
//根据计划任务类型来判断
if(config('cron.default') != ScheduleDict::default) return;
if (defined('BIND_MODULE') && BIND_MODULE === 'install') {
return;
}
$last_time = Cache::get("cron_last_load_time");
if (empty($last_time)) {
$last_time = 0;
}
$last_exec_time = Cache::get("cron_http_last_exec_time");
if (empty($last_exec_time)) {
$last_exec_time = 0;
}
$module = request()->module();
if ($module != 'cron') {
if (!defined('CRON_EXECUTE') && time() - $last_time > 100 && time() - $last_exec_time > 100) {
Cache::set("cron_http_last_exec_time", time());
defined('CRON_EXECUTE') or define('CRON_EXECUTE', 1);
$url = url('cron/task/cronExecute');
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_exec($ch);
// // 获取错误信息并打印
// $error = curl_error($ch);
// if($error){
// //保存错误
// Cron::setError(ScheduleDict::default, $error);
// }
// // 关闭cURL资源句柄
// curl_close($ch);
}
}
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace app\event\init;
use app\model\system\Addon;
use think\facade\Lang;
use think\facade\Event;
use think\facade\Cache;
require_once('extend/cert/pen.php');
class InitAddon {
public function handle() {
if (defined('BIND_MODULE') && BIND_MODULE === 'install') return;
$this->initEvent();
}
private function InitEvent() {
try {
$cache = Cache::get("addon_event_list");
if(empty($cache)) {
$addon_model = new Addon();
$addon_data = $addon_model->getAddonList([], 'name');
$listen_array = [];
foreach ($addon_data['data'] as $k => $v) {
if(file_exists('addon/'.$v['name'].'/config/event.php')) {
$addon_event = require_once 'addon/'.$v['name'].'/config/event.php';
$listen = isset($addon_event['listen']) ? $addon_event['listen'] : [];
if(!empty($listen)) {
$listen_array[] = $listen;
}
}
}
Cache::tag("addon")->set("addon_event_list", $listen_array);
} else {
$listen_array = $cache;
}
if(!empty($listen_array)) {
foreach ($listen_array as $k => $listen) {
if(!empty($listen)) {
Event::listenEvents($listen);
}
}
}
} catch (\Throwable $th) {
formatThrowForDebugWithExit($th);
}
}
}