CacheForm.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. /*
  8. * @Author: 凯
  9. * @Date: 2021-05-06 10:01:08
  10. * @LastEditTime: 2021-05-06 10:14:11
  11. * @LastEditors: Please set LastEditors
  12. * @Description: In User Settings Edit
  13. * @FilePath: \admin_php\modules\admin\models\CacheForm.php
  14. */
  15. namespace app\modules\admin\models;
  16. use yii\base\Model;
  17. class CacheForm extends Model
  18. {
  19. // 清除服务商证书密钥缓存
  20. public function clearServerMchKey()
  21. {
  22. $dir = \Yii::$app->basePath . '/utils/WechatMerchant/cert';
  23. $this->delFileUnderDir($dir);
  24. }
  25. /**
  26. * @description:
  27. * @param {*}
  28. * @return {*}
  29. */
  30. public function clearImages()
  31. {
  32. $dir = \Yii::$app->basePath . '/runtime/image';
  33. $this->delFileUnderDir($dir);
  34. $dir = \Yii::$app->basePath . '/web/temp';
  35. $this->delFileUnderDir($dir);
  36. }
  37. /**
  38. * @description:
  39. * @param {*}
  40. * @return {*}
  41. */
  42. public function clearData()
  43. {
  44. return cache()->flush();
  45. }
  46. /**
  47. * @description:
  48. * @param {*}
  49. * @return {*}
  50. */
  51. public function clearUpdata()
  52. {
  53. $dir = \Yii::$app->basePath . '/temp/update';
  54. $this->delFileUnderDir($dir);
  55. }
  56. //循环目录下的所有文件
  57. private function delFileUnderDir($dirName, $delDir = false, $ignoreList = [])
  58. {
  59. // 判断是否存在该目录
  60. if (file_exists("$dirName")) {
  61. if ($handle = opendir("$dirName")) {
  62. while (false !== ($item = readdir($handle))) {
  63. if ($item != "." && $item != ".." && !in_array($item, $ignoreList)) {
  64. if (is_dir("$dirName/$item")) {
  65. $this->delFileUnderDir("$dirName/$item", true, $ignoreList);
  66. } else {
  67. unlink("$dirName/$item");
  68. }
  69. }
  70. }
  71. closedir($handle);
  72. if ($delDir) {
  73. rmdir("$dirName");
  74. }
  75. }
  76. }
  77. }
  78. }