InstallMiddleware.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-26
  7. *
  8. *
  9. */
  10. namespace app\common\middleware;
  11. use app\Request;
  12. use think\exception\HttpResponseException;
  13. use think\facade\Route;
  14. use think\Response;
  15. class InstallMiddleware extends BaseMiddleware
  16. {
  17. public function before(Request $request)
  18. {
  19. // 系统维护开关(示例条件,实际应根据配置)
  20. $isMaintenance = false; // 改为从配置读取
  21. if ($isMaintenance) {
  22. // 创建符合前端格式的响应
  23. $response = json([
  24. 'status' => 400,
  25. 'message' => '系统正在升级中'
  26. ], 503); // 使用503状态码表示服务不可用
  27. // 抛出异常中断请求
  28. throw new HttpResponseException($response);
  29. }
  30. if(!file_exists(__DIR__.'/../../../install/install.lock')){
  31. throw new HttpResponseException( Response::create('/install.html', 'redirect')->code(302));
  32. }
  33. }
  34. public function after(Response $response)
  35. {
  36. }
  37. }