SystemCleardata.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: sugar1569
  5. * Date: 2018/5/24
  6. * Time: 10:58
  7. */
  8. namespace app\admin\controller\system;
  9. use app\admin\controller\AuthController;
  10. use app\admin\model\store\StoreProduct;
  11. use crmeb\services\JsonService as Json;
  12. use think\facade\Db;
  13. /**
  14. * 清除默认数据理控制器
  15. * Class SystemclearData
  16. * @package app\admin\controller\system
  17. */
  18. class SystemclearData extends AuthController
  19. {
  20. public function index(){
  21. return $this->fetch();
  22. }
  23. //清除用户数据
  24. public function userRelevantData(){
  25. self::clearData('user_recharge',1);
  26. self::clearData('user_address',1);
  27. self::clearData('user_bill',1);
  28. self::clearData('user_enter',1);
  29. self::clearData('user_extract',1);
  30. self::clearData('user_notice',1);
  31. self::clearData('user_notice_see',1);
  32. self::clearData('wechat_qrcode',1);
  33. self::clearData('wechat_message',1);
  34. self::clearData('store_visit',1);
  35. self::clearData('store_coupon_user',1);
  36. self::clearData('store_coupon_issue_user',1);
  37. self::clearData('store_bargain_user',1);
  38. self::clearData('store_bargain_user_help',1);
  39. self::clearData('store_product_reply',1);
  40. self::clearData('store_product_cate',1);
  41. self::clearData('routine_qrcode',1);
  42. self::clearData('routine_form_id',1);
  43. self::clearData('user_sign',1);
  44. self::clearData('user_task_finish',1);
  45. self::clearData('user_level',1);
  46. self::clearData('user_token',1);
  47. self::clearData('user_group',1);
  48. $this->delDirAndFile('./public/uploads/store/comment');
  49. self::clearData('store_product_relation',1);
  50. return Json::successful('清除数据成功!');
  51. }
  52. //清除商城数据
  53. public function storeData(){
  54. self::clearData('store_coupon',1);
  55. self::clearData('store_coupon_issue',1);
  56. self::clearData('store_bargain',1);
  57. self::clearData('store_combination',1);
  58. self::clearData('store_combination_attr',1);
  59. self::clearData('store_combination_attr_result',1);
  60. self::clearData('store_combination_attr_value',1);
  61. self::clearData('store_product_attr',1);
  62. self::clearData('store_product_cate',1);
  63. self::clearData('store_product_attr_result',1);
  64. self::clearData('store_product_attr_value',1);
  65. self::clearData('store_seckill',1);
  66. self::clearData('store_seckill_attr',1);
  67. self::clearData('store_seckill_attr_result',1);
  68. self::clearData('store_seckill_attr_value',1);
  69. self::clearData('store_product',1);
  70. self::clearData('store_visit',1);
  71. return Json::successful('清除数据成功!');
  72. }
  73. //清除产品分类
  74. public function categoryData(){
  75. self::clearData('store_category',1);
  76. return Json::successful('清除数据成功!');
  77. }
  78. //清除订单数据
  79. public function orderData(){
  80. self::clearData('store_order',1);
  81. self::clearData('store_order_cart_info',1);
  82. self::clearData('store_order_status',1);
  83. self::clearData('store_pink',1);
  84. self::clearData('store_cart',1);
  85. self::clearData('store_order_status',1);
  86. return Json::successful('清除数据成功!');
  87. }
  88. //清除客服数据
  89. public function kefuData(){
  90. self::clearData('store_service',1);
  91. $this->delDirAndFile('./public/uploads/store/service');
  92. self::clearData('store_service_log',1);
  93. return Json::successful('清除数据成功!');
  94. }
  95. //清除微信管理数据
  96. public function wechatData(){
  97. self::clearData('wechat_media',1);
  98. self::clearData('wechat_reply',1);
  99. self::clearData('cache',1);
  100. $this->delDirAndFile('./public/uploads/wechat');
  101. return Json::successful('清除数据成功!');
  102. }
  103. //清除所有附件
  104. public function uploadData(){
  105. self::clearData('system_attachment',1);
  106. self::clearData('system_attachment_category',1);
  107. $this->delDirAndFile('./public/uploads/');
  108. return Json::successful('清除上传文件成功!');
  109. }
  110. //清除微信用户
  111. public function wechatuserData(){
  112. self::clearData('wechat_user',1);
  113. self::clearData('user',1);
  114. return Json::successful('清除数据成功!');
  115. }
  116. //清除内容分类
  117. public function articledata(){
  118. self::clearData('article_category',1);
  119. self::clearData('article',1);
  120. self::clearData('article_content',1);
  121. return Json::successful('清除数据成功!');
  122. }
  123. //清除系统记录
  124. public function systemdata(){
  125. self::clearData('system_notice_admin',1);
  126. self::clearData('system_log',1);
  127. return Json::successful('清除数据成功!');
  128. }
  129. /**
  130. * 清除数据
  131. * @param int $type
  132. * @throws \Exception
  133. */
  134. public function undata($type = 1)
  135. {
  136. switch ((int)$type){
  137. case 1:
  138. \app\admin\model\system\SystemAttachment::where('module_type',2)->delete();
  139. break;
  140. case 2:
  141. StoreProduct::where('is_del',1)->delete();
  142. break;
  143. }
  144. return Json::successful('清除数据成功!');
  145. }
  146. //清除制定表数据
  147. public function clearData($table_name,$status){
  148. $table_name = config('database.connections.' . config('database.default'))['prefix'].$table_name;
  149. if($status){
  150. @db::execute('TRUNCATE TABLE '.$table_name);
  151. }else{
  152. @db::execute('DELETE FROM'.$table_name);
  153. }
  154. }
  155. //递归删除文件
  156. function delDirAndFile($dirName,$subdir=true){
  157. if ($handle = @opendir("$dirName")){
  158. while(false !== ($item = readdir($handle))){
  159. if($item != "." && $item != ".."){
  160. if(is_dir("$dirName/$item"))
  161. $this->delDirAndFile("$dirName/$item",false);
  162. else
  163. @unlink("$dirName/$item");
  164. }
  165. }
  166. closedir($handle);
  167. if(!$subdir) @rmdir($dirName);
  168. }
  169. }
  170. }