SystemClearData.php 7.9 KB

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