Clear.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\system;
  12. use app\admin\controller\AuthController;
  13. use service\CacheService;
  14. use service\JsonService as Json;
  15. use think\Log;
  16. use think\Cache;
  17. /**
  18. * 首页控制器
  19. * Class Clear
  20. */
  21. class Clear extends AuthController
  22. {
  23. public function index()
  24. {
  25. return $this->fetch();
  26. }
  27. /**
  28. * 刷新数据缓存
  29. */
  30. public function refresh_cache()
  31. {
  32. `php think optimize:schema`;
  33. `php think optimize:autoload`;
  34. `php think optimize:route`;
  35. `php think optimize:config`;
  36. return Json::successful('数据缓存刷新成功!');
  37. }
  38. /**
  39. * 清除首页缓存
  40. */
  41. public function del_home_redis()
  42. {
  43. $subjectUrl = getUrlToDomain();
  44. del_redis_hash($subjectUrl . "wap_index_has", "recommend_list");
  45. del_redis_hash($subjectUrl . "web_index_has", "recommend_list");
  46. return Json::successful('清除首页缓存成功!');
  47. }
  48. /**
  49. * 删除缓存
  50. */
  51. public function delete_cache()
  52. {
  53. Cache::clear();
  54. array_map('unlink', glob(TEMP_PATH . '/*.php'));
  55. return Json::successful('清除缓存成功!');
  56. }
  57. /**
  58. * 删除日志
  59. */
  60. public function delete_log()
  61. {
  62. array_map('unlink', glob(LOG_PATH . '/*.log'));
  63. $this->delDirAndFile(LOG_PATH);
  64. return Json::successful('清除日志成功!');
  65. }
  66. function delDirAndFile($dirName, $subdir = true)
  67. {
  68. if ($handle = opendir("$dirName")) {
  69. while (false !== ($item = readdir($handle))) {
  70. if ($item != "." && $item != "..") {
  71. if (is_dir("$dirName/$item"))
  72. $this->delDirAndFile("$dirName/$item", false);
  73. else
  74. @unlink("$dirName/$item");
  75. }
  76. }
  77. closedir($handle);
  78. if (!$subdir) @rmdir($dirName);
  79. }
  80. }
  81. }