初始上传
This commit is contained in:
24
app/event/init/AppEnd.php
Executable file
24
app/event/init/AppEnd.php
Executable file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
namespace app\event\init;
|
||||
|
||||
/**
|
||||
* 应用结束
|
||||
*/
|
||||
class AppEnd
|
||||
{
|
||||
// 行为扩展的执行入口必须是run
|
||||
public function handle()
|
||||
{
|
||||
return success();
|
||||
|
||||
}
|
||||
}
|
||||
2
app/event/init/HttpRun.php
Executable file
2
app/event/init/HttpRun.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
get_funcs('HttpRun');
|
||||
68
app/event/init/InitAddon.php
Executable file
68
app/event/init/InitAddon.php
Executable file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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("system_check_auth")) 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
2
app/event/init/InitAuth.php
Executable file
2
app/event/init/InitAuth.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
get_funcs('InitAuth');
|
||||
130
app/event/init/InitConfig.php
Executable file
130
app/event/init/InitConfig.php
Executable file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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');
|
||||
|
||||
//是否展示帮助快捷链接
|
||||
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("非法请求");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化配置信息
|
||||
*/
|
||||
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',
|
||||
'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');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
66
app/event/init/InitCron.php
Executable file
66
app/event/init/InitCron.php
Executable file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/**
|
||||
* Niushop商城系统 - 团队十年电商经验汇集巨献!
|
||||
* =========================================================
|
||||
* Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
|
||||
* ----------------------------------------------
|
||||
* 官方网址: https://www.niushop.com
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user