SystemClearData.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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\adminapi\controller\v1\system;
  12. use think\facade\App;
  13. use app\adminapi\controller\AuthController;
  14. use app\services\system\SystemClearServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\system\attachment\SystemAttachmentServices;
  17. /**
  18. * 清除默认数据理控制器
  19. * Class SystemClearData
  20. * @package app\admin\controller\system
  21. */
  22. class SystemClearData extends AuthController
  23. {
  24. /**
  25. * 构造方法
  26. * SystemClearData constructor.
  27. * @param App $app
  28. * @param SystemClearServices $services
  29. */
  30. public function __construct(App $app, SystemClearServices $services)
  31. {
  32. parent::__construct($app);
  33. $this->services = $services;
  34. }
  35. /**
  36. * 统一方法
  37. * @param $type
  38. * @return mixed
  39. */
  40. public function index($type)
  41. {
  42. switch ($type) {
  43. case 'temp':
  44. return $this->userTemp();
  45. break;
  46. case 'recycle':
  47. return $this->recycleProduct();
  48. break;
  49. case 'store':
  50. return $this->storeData();
  51. break;
  52. case 'category':
  53. return $this->categoryData();
  54. break;
  55. case 'order':
  56. return $this->orderData();
  57. break;
  58. case 'kefu':
  59. return $this->kefuData();
  60. break;
  61. case 'wechat':
  62. return $this->wechatData();
  63. break;
  64. case 'attachment':
  65. return $this->attachmentData();
  66. break;
  67. case 'article':
  68. return $this->articledata();
  69. break;
  70. case 'system':
  71. return $this->systemdata();
  72. break;
  73. case 'user':
  74. return $this->userRelevantData();
  75. break;
  76. case 'wechatuser':
  77. return $this->wechatuserData();
  78. break;
  79. default:
  80. return app('json')->fail(100100);
  81. }
  82. }
  83. /**
  84. * 清除用户生成的临时附件
  85. * @return mixed
  86. */
  87. public function userTemp()
  88. {
  89. /** @var SystemAttachmentServices $services */
  90. $services = app()->make(SystemAttachmentServices::class);
  91. $imageUrl = $services->getColumn(['module_type' => 2], 'att_dir');
  92. foreach ($imageUrl as $item) {
  93. @unlink(app()->getRootPath() . 'public' . $item);
  94. }
  95. $services->delete(2, 'module_type');
  96. $this->services->clearData(['qrcode'], true);
  97. return app('json')->success(100046);
  98. }
  99. /**
  100. * 清除回收站商品
  101. * @return mixed
  102. */
  103. public function recycleProduct()
  104. {
  105. /** @var StoreProductServices $services */
  106. $services = app()->make(StoreProductServices::class);
  107. $services->delete(1, 'is_del');
  108. return app('json')->success(100046);
  109. }
  110. /**
  111. * 清除用户数据
  112. * @return mixed
  113. */
  114. public function userRelevantData()
  115. {
  116. $this->services->clearData([
  117. 'user_recharge', 'user_address', 'user_bill', 'user_enter', 'user_extract',
  118. 'user_notice', 'user_notice_see', 'wechat_message', 'store_visit',
  119. 'store_coupon_user', 'store_coupon_issue_user', 'store_bargain_user', 'store_bargain_user_help',
  120. 'store_product_reply', 'store_product_cate', 'user_sign',
  121. 'user_level', 'user_group', 'user_visit', 'user_label', 'user_label_relation', 'user_label_relation',
  122. 'store_product_relation', 'sms_record', 'system_file', 'system_store', 'system_store_staff',
  123. 'member_card', 'member_card_batch', 'member_ship', 'qrcode', 'user_brokerage_frozen', 'user_invoice'
  124. ], true);
  125. $this->services->delDirAndFile('./public/uploads/store/comment');
  126. return app('json')->success(100046);
  127. }
  128. /**
  129. * 清除商城数据
  130. * @return mixed
  131. */
  132. public function storeData()
  133. {
  134. $this->services->clearData([
  135. 'store_coupon_issue', 'store_bargain', 'store_combination', 'store_product_attr',
  136. 'store_product_attr_result', 'store_product_cate', 'store_product_attr_value', 'store_product_description',
  137. 'store_product_rule', 'store_seckill', 'store_product', 'store_visit', 'store_product_log', 'category', 'delivery_service',
  138. 'live_anchor', 'live_goods', 'live_room', 'live_room_goods', 'store_product_coupon'
  139. ], true);
  140. return app('json')->success(100046);
  141. }
  142. /**
  143. * 清除商品分类
  144. * @return mixed
  145. */
  146. public function categoryData()
  147. {
  148. $this->services->clearData(['store_category'], true);
  149. return app('json')->success(100046);
  150. }
  151. /**
  152. * 清除订单数据
  153. * @return mixed
  154. */
  155. public function orderData()
  156. {
  157. $this->services->clearData(['store_order', 'store_order_cart_info', 'store_order_status', 'store_pink',
  158. 'store_cart', 'store_order_status', 'other_order', 'other_order_status', 'store_order_invoice'
  159. ], true);
  160. return app('json')->success(100046);
  161. }
  162. /**
  163. * 清除客服数据
  164. * @return mixed
  165. */
  166. public function kefuData()
  167. {
  168. $this->services->clearData([
  169. 'store_service', 'store_service_log', 'store_service_record', 'store_service_feedback', 'store_service_speechcraft'
  170. ], true);
  171. $this->services->delDirAndFile('./public/uploads/store/service');
  172. return app('json')->success(100046);
  173. }
  174. /**
  175. * 清除微信管理数据
  176. * @return mixed
  177. */
  178. public function wechatData()
  179. {
  180. $this->services->clearData([
  181. 'wechat_media', 'wechat_reply', 'cache', 'wechat_key',
  182. 'wechat_news_category'
  183. ], true);
  184. $this->services->delDirAndFile('./public/uploads/wechat');
  185. return app('json')->success(100046);
  186. }
  187. /**
  188. * 清除所有附件
  189. * @return mixed
  190. */
  191. public function attachmentData()
  192. {
  193. $this->services->clearData([
  194. 'system_attachment', 'system_attachment_category'
  195. ], true);
  196. $this->services->delDirAndFile('./public/uploads/');
  197. return app('json')->success(100046);
  198. }
  199. /**
  200. * 清除微信用户
  201. * @return mixed
  202. */
  203. public function wechatuserData()
  204. {
  205. $this->services->clearData([
  206. 'user', 'wechat_user'
  207. ], true);
  208. return app('json')->success(100046);
  209. }
  210. //清除内容分类
  211. public function articledata()
  212. {
  213. $this->services->clearData([
  214. 'article_category', 'article', 'article_content'
  215. ], true);
  216. return app('json')->success(100046);
  217. }
  218. //清除系统记录
  219. public function systemdata()
  220. {
  221. $this->services->clearData([
  222. 'system_notice_admin', 'system_log'
  223. ], true);
  224. return app('json')->success(100046);
  225. }
  226. /**
  227. * 替换域名方法
  228. * @return mixed
  229. */
  230. public function replaceSiteUrl()
  231. {
  232. list($url) = $this->request->postMore([
  233. ['url', '']
  234. ], true);
  235. if (!$url)
  236. return app('json')->fail(400304);
  237. if (!verify_domain($url))
  238. return app('json')->fail(400305);
  239. $this->services->replaceSiteUrl($url);
  240. return app('json')->success(400306);
  241. }
  242. }