SystemClear.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 app\admin\model\special\Special;
  14. use app\admin\model\special\SpecialSource;
  15. use app\admin\model\special\SpecialTask;
  16. use service\CacheService;
  17. use service\JsonService as Json;
  18. /**
  19. * 清除缓存
  20. * Class Clear
  21. * @package app\admin\controller
  22. *
  23. */
  24. class systemClear extends AuthController
  25. {
  26. public function index()
  27. {
  28. return $this->fetch();
  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. public function delete_cache()
  39. {
  40. $this->delDirAndFile("./runtime/temp");
  41. $this->delDirAndFile("./runtime/cache");
  42. return Json::successful('清除缓存成功!');
  43. }
  44. public function delete_log()
  45. {
  46. $this->delDirAndFile("./runtime/log");
  47. return Json::successful('清除日志成功!');
  48. }
  49. function delDirAndFile($dirName, $subdir = true)
  50. {
  51. if ($handle = opendir("$dirName")) {
  52. while (false !== ($item = readdir($handle))) {
  53. if ($item != "." && $item != "..") {
  54. if (is_dir("$dirName/$item"))
  55. $this->delDirAndFile("$dirName/$item", false);
  56. else
  57. @unlink("$dirName/$item");
  58. }
  59. }
  60. closedir($handle);
  61. if (!$subdir) @rmdir($dirName);
  62. }
  63. }
  64. public function data_compatible_back()
  65. {
  66. $specialList = Special::select();
  67. if (!$specialList) {
  68. return Json::successful('无需兼容!');
  69. }
  70. $isTask = SpecialSource::find();
  71. if ($isTask) {
  72. return Json::successful('无需兼容!');
  73. }
  74. try{
  75. foreach ($specialList as $k => $v) {
  76. SpecialTask::beginTrans();
  77. $specialTaskList = SpecialTask::where('special_id', $v['id'])->select();
  78. if (count($specialTaskList)) {
  79. foreach ($specialTaskList as $tk => $tv) {
  80. $source_inster['special_id'] = $tv['special_id'];
  81. $source_inster['source_id'] = $tv['id'];
  82. $source_inster['pay_status'] = PAY_MONEY;
  83. $source_inster['add_time'] = time();
  84. SpecialSource::set($source_inster);
  85. if ($tv['live_id'] == 0){
  86. $task_update['type'] = 1;
  87. }else{
  88. $task_update['type'] = 4;
  89. }
  90. SpecialTask::where(['id'=>$tv['id']])->update($task_update);
  91. }
  92. Special::where(['id'=>$v['id']])->update(['type' => 1]);
  93. }else{
  94. Special::where(['id'=>$v['id']])->update(['type' => 4]);
  95. }
  96. SpecialTask::commitTrans();
  97. }
  98. return Json::successful('兼容成功!');
  99. }catch (\Exception $e){
  100. SpecialTask::rollbackTrans();
  101. echo $e->getMessage();die;
  102. return Json::fail('兼容失败!');
  103. }
  104. }
  105. public function data_compatible()
  106. {
  107. $specialList = Special::select();
  108. if (!$specialList) {
  109. return Json::successful('无需兼容!');
  110. }
  111. try{
  112. foreach ($specialList as $k => $v) {
  113. Special::where(['id'=>$v['id']])->update(['type' => 1]);
  114. }
  115. $specialTaskList = SpecialTask::select();
  116. foreach ($specialTaskList as $tk => $tv) {
  117. SpecialTask::where(['id'=>$tv['id']])->update(['type' => 1]);
  118. }
  119. return Json::successful('兼容成功!');
  120. }catch (\Exception $e){
  121. return Json::fail('兼容失败!');
  122. }
  123. }
  124. }