SystemCleardata.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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\user\User;
  14. use app\admin\model\wechat\WechatUser;
  15. use service\JsonService as Json;
  16. use think\db;
  17. use think\Config;
  18. /**
  19. * 清除默认数据理控制器
  20. * Class SystemCleardata
  21. * @package app\admin\controller\system
  22. *
  23. */
  24. class SystemCleardata extends AuthController
  25. {
  26. public function index()
  27. {
  28. return $this->fetch();
  29. }
  30. //清除用户数据
  31. public function UserRelevant()
  32. {
  33. SystemCleardata::ClearData('user_recharge', 1);
  34. SystemCleardata::ClearData('user_address', 1);
  35. SystemCleardata::ClearData('user_bill', 1);
  36. SystemCleardata::ClearData('user_enter', 1);
  37. SystemCleardata::ClearData('user_extract', 1);
  38. SystemCleardata::ClearData('user_notice', 1);
  39. SystemCleardata::ClearData('user_notice_see', 1);
  40. SystemCleardata::ClearData('wechat_qrcode', 1);
  41. SystemCleardata::ClearData('wechat_message', 1);
  42. SystemCleardata::ClearData('store_coupon_user', 1);
  43. SystemCleardata::ClearData('store_coupon_issue_user', 1);
  44. SystemCleardata::ClearData('store_bargain_user', 1);
  45. SystemCleardata::ClearData('store_bargain_user_help', 1);
  46. SystemCleardata::ClearData('store_product_reply', 1);
  47. $this->delDirAndFile('./public/uploads/store/comment');
  48. SystemCleardata::ClearData('store_product_relation', 1);
  49. return Json::successful('清除数据成功!');
  50. }
  51. //清除商城数据
  52. public function storedata()
  53. {
  54. SystemCleardata::ClearData('store_coupon', 1);
  55. SystemCleardata::ClearData('store_coupon_issue', 1);
  56. SystemCleardata::ClearData('store_bargain', 1);
  57. SystemCleardata::ClearData('store_combination', 1);
  58. SystemCleardata::ClearData('store_product_attr', 1);
  59. SystemCleardata::ClearData('store_product_attr_result', 1);
  60. SystemCleardata::ClearData('store_product_attr_value', 1);
  61. SystemCleardata::ClearData('store_seckill', 1);
  62. SystemCleardata::ClearData('store_product', 1);
  63. $this->delDirAndFile('./public/uploads/store/product');
  64. return Json::successful('清除数据成功!');
  65. }
  66. //清除产品分类
  67. public function categorydata()
  68. {
  69. SystemCleardata::ClearData('store_category', 1);
  70. $this->delDirAndFile('./public/uploads/store/product');
  71. return Json::successful('清除数据成功!');
  72. }
  73. //清除订单数据
  74. public function orderdata()
  75. {
  76. SystemCleardata::ClearData('store_order', 1);
  77. SystemCleardata::ClearData('store_order_cart_info', 1);
  78. SystemCleardata::ClearData('store_order_copy', 1);
  79. SystemCleardata::ClearData('store_order_status', 1);
  80. SystemCleardata::ClearData('store_pink', 1);
  81. SystemCleardata::ClearData('store_cart', 1);
  82. return Json::successful('清除数据成功!');
  83. }
  84. //清除客服数据
  85. public function kefudata()
  86. {
  87. SystemCleardata::ClearData('store_service', 1);
  88. $this->delDirAndFile('./public/uploads/store/service');
  89. SystemCleardata::ClearData('store_service_log', 1);
  90. return Json::successful('清除数据成功!');
  91. }
  92. //修改用户默认密码
  93. public function userdate()
  94. {
  95. // SystemCleardata::ClearData('user',1);
  96. $headimgurl = WechatUser::Where('uid', 1)->value('headimgurl');
  97. $data['account'] = 'crmeb';
  98. $data['pwd'] = md5(123456);
  99. $data['avatar'] = $headimgurl;
  100. $data['add_time'] = time();
  101. $data['status'] = 1;
  102. $data['level'] = 0;
  103. $data['user_type'] = "wechat";
  104. $data['is_promoter'] = 1;
  105. User::create($data);
  106. return Json::successful('清除数据成功!');
  107. }
  108. //清除微信管理数据
  109. public function wechatdata()
  110. {
  111. SystemCleardata::ClearData('wechat_media', 1);
  112. SystemCleardata::ClearData('wechat_reply', 1);
  113. SystemCleardata::ClearData('wechat_news_content', 1);
  114. SystemCleardata::ClearData('wechat_news', 1);
  115. SystemCleardata::ClearData('wechat_news_category', 1);
  116. $this->delDirAndFile('./public/uploads/wechat');
  117. return Json::successful('清除数据成功!');
  118. }
  119. //清除所有附件
  120. public function uploaddata()
  121. {
  122. $this->delDirAndFile('./public/uploads');
  123. return Json::successful('清除上传文件成功!');
  124. }
  125. //清除微信用户
  126. public function wechatuserdata()
  127. {
  128. $data = WechatUser::get(1)->toArray();
  129. SystemCleardata::ClearData('wechat_user', 1);
  130. unset($data['uid']);
  131. WechatUser::set($data);
  132. return Json::successful('清除数据成功!');
  133. }
  134. //清除内容分类
  135. public function articledata()
  136. {
  137. SystemCleardata::ClearData('article_category', 1);
  138. $this->delDirAndFile('./public/uploads/article/');
  139. return Json::successful('清除数据成功!');
  140. }
  141. //清除制定表数据
  142. public function ClearData($table_name, $status)
  143. {
  144. $table_name = Config::get('database')['prefix'] . $table_name;
  145. if ($status) {
  146. db::query('TRUNCATE TABLE ' . $table_name);
  147. } else {
  148. db::query('DELETE FROM' . $table_name);
  149. }
  150. }
  151. //递归删除文件
  152. function delDirAndFile($dirName, $subdir = true)
  153. {
  154. if ($handle = opendir("$dirName")) {
  155. while (false !== ($item = readdir($handle))) {
  156. if ($item != "." && $item != "..") {
  157. if (is_dir("$dirName/$item"))
  158. $this->delDirAndFile("$dirName/$item", false);
  159. else
  160. @unlink("$dirName/$item");
  161. }
  162. }
  163. closedir($handle);
  164. if (!$subdir) @rmdir($dirName);
  165. }
  166. }
  167. }