| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- /**
- * @package merchant
- *
- * @author xaboy
- * @day 2020-03-26
- *
- *
- */
- namespace app\common\middleware;
- use app\Request;
- use think\exception\HttpResponseException;
- use think\facade\Route;
- use think\Response;
- class InstallMiddleware extends BaseMiddleware
- {
- public function before(Request $request)
- {
- // 系统维护开关(示例条件,实际应根据配置)
- $isMaintenance = false; // 改为从配置读取
- if ($isMaintenance) {
- // 创建符合前端格式的响应
- $response = json([
- 'status' => 400,
- 'message' => '系统正在升级中'
- ], 503); // 使用503状态码表示服务不可用
- // 抛出异常中断请求
- throw new HttpResponseException($response);
- }
- if(!file_exists(__DIR__.'/../../../install/install.lock')){
- throw new HttpResponseException( Response::create('/install.html', 'redirect')->code(302));
- }
- }
- public function after(Response $response)
- {
- }
- }
|