chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+95
View File
@@ -0,0 +1,95 @@
<?php
/*
* @Author: YwxApp <ywx@ywxapp.cn>
* @Date: 2026-07-21 16:29:59
* @LastEditors: YwxApp <ywx@ywxapp.cn>
* @LastEditTime: 2026-08-04 11:25:35
* @Description:
* @FilePath: \ywxapp_dev\app\backend\controller\Upgrade.php
* @CustomString: Copyright (c) 2026 YwxApp
*/
declare(strict_types=1);
namespace app\backend\controller;
use think\facade\View;
use ywxapp\service\FrameworkService;
use ywxapp\controller\BackendBase;
/**
* 主框架在线升级(客户端后台)
*
* 检测中心站 upgrade 插件发布的版本,并一键下载覆盖升级。
* 访问:/backend/framework/index
*/
class Upgrade extends BackendBase
{
public function initialize() {}
/**
* 升级页面 / 检测接口
*/
public function index()
{
if ($this->request->isAjax()) {
$svc = FrameworkService::instance();
$info = $svc->checkVersion(true);
return $this->result->success($info, $info['has_update'] ? '有可用更新' : '已是最新版本');
}
View::assign('current', config('ywxapp.version'));
return View::fetch('upgrade/index');
}
/**
* 检测更新(AJAX):/admin/framework/check
*/
public function check()
{
$svc = FrameworkService::instance();
$info = $svc->checkVersion(true);
return $this->result->success($info, $info['has_update'] ? '有可用更新' : '已是最新版本');
}
/**
* 执行升级:下载核心包 → 备份 → 覆盖 → 更新版本号
*/
public function upgrade()
{
try {
set_time_limit(0);
$svc = FrameworkService::instance();
$check = $svc->checkVersion(true);
if (!$check['has_update']) {
return $this->result->error('当前已是最新版本');
}
if (!empty($check['error'])) {
return $this->result->error($check['error']);
}
$version = $check['latest'];
// 手动选择升级包类型:auto(默认,按 use_patch 择优)/ full(完整包)/ patch(增量小包)
$sel = strtolower(trim((string) $this->request->param('type', 'auto')));
if ($sel === 'auto') {
$usePatch = !empty($check['use_patch']);
} elseif ($sel === 'patch') {
if (empty($check['use_patch'])) {
return $this->result->error('当前版本(' . ($check['current'] ?? '') . ')不是增量补丁的基础版本('
. ($check['patch_from'] ?? '') . '),无法使用增量小包,请改用完整包');
}
$usePatch = true;
} elseif ($sel === 'full') {
if (empty($check['has_full'])) {
return $this->result->error('当前无可用的完整包,请改用增量小包');
}
$usePatch = false;
} else {
return $this->result->error('未知的升级包类型:' . $sel . '(可选 auto/full/patch');
}
$zip = $svc->download($version, $usePatch ? 'patch' : 'full');
$res = $svc->apply($zip, $version, $usePatch ? 1 : 0);
$mode = ($res['mode'] ?? 'full') === 'patch' ? '(增量补丁)' : '(整包)';
return $this->result->success($res, '升级成功' . $mode . ',当前版本:' . $version);
} catch (\Exception $e) {
return $this->result->error($e->getMessage());
}
}
}