SystemClearData.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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 app\services\product\product\StoreDescriptionServices;
  13. use app\services\product\product\StoreProductCateServices;
  14. use app\services\product\product\StoreProductCouponServices;
  15. use app\services\product\product\StoreProductReplyServices;
  16. use app\services\product\sku\StoreProductAttrResultServices;
  17. use app\services\product\sku\StoreProductAttrServices;
  18. use app\services\product\sku\StoreProductAttrValueServices;
  19. use think\facade\App;
  20. use app\adminapi\controller\AuthController;
  21. use app\services\system\SystemClearServices;
  22. use app\services\product\product\StoreProductServices;
  23. use app\services\system\attachment\SystemAttachmentServices;
  24. /**
  25. * 清除默认数据理控制器
  26. * Class SystemClearData
  27. * @package app\admin\controller\system
  28. */
  29. class SystemClearData extends AuthController
  30. {
  31. /**
  32. * 构造方法
  33. * SystemClearData constructor.
  34. * @param App $app
  35. * @param SystemClearServices $services
  36. */
  37. public function __construct(App $app, SystemClearServices $services)
  38. {
  39. parent::__construct($app);
  40. $this->services = $services;
  41. }
  42. /**
  43. * 统一方法
  44. * @param $type
  45. * @return mixed
  46. */
  47. public function index($type)
  48. {
  49. switch ($type) {
  50. case 'temp':
  51. return $this->userTemp();
  52. case 'recycle':
  53. return $this->recycleProduct();
  54. case 'store':
  55. return $this->storeData();
  56. case 'category':
  57. return $this->categoryData();
  58. case 'order':
  59. return $this->orderData();
  60. case 'kefu':
  61. return $this->kefuData();
  62. case 'wechat':
  63. return $this->wechatData();
  64. case 'article':
  65. return $this->articleData();
  66. case 'attachment':
  67. return $this->attachmentData();
  68. case 'system':
  69. return $this->systemData();
  70. case 'user':
  71. return $this->userRelevantData();
  72. default:
  73. return app('json')->fail(100100);
  74. }
  75. }
  76. /**
  77. * 清除用户生成的临时附件
  78. * @return mixed
  79. */
  80. public function userTemp()
  81. {
  82. /** @var SystemAttachmentServices $services */
  83. $services = app()->make(SystemAttachmentServices::class);
  84. $imageUrl = $services->getColumn(['module_type' => 2], 'att_dir');
  85. foreach ($imageUrl as $item) {
  86. @unlink(app()->getRootPath() . 'public' . $item);
  87. }
  88. $services->delete(2, 'module_type');
  89. $this->services->clearData(['qrcode'], true);
  90. return app('json')->success(100046);
  91. }
  92. /**
  93. * 清除回收站商品
  94. * @return mixed
  95. */
  96. public function recycleProduct()
  97. {
  98. /** @var StoreProductServices $product */
  99. $product = app()->make(StoreProductServices::class);
  100. $ids = $product->getColumn(['is_del' => 1], 'id');
  101. //清除规格表数据
  102. /** @var StoreProductAttrServices $ProductAttr */
  103. $productAttr = app()->make(StoreProductAttrServices::class);
  104. $productAttr->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  105. /** @var StoreProductAttrResultServices $productAttrResult */
  106. $productAttrResult = app()->make(StoreProductAttrResultServices::class);
  107. $productAttrResult->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  108. /** @var StoreProductAttrValueServices $productAttrValue */
  109. $productAttrValue = app()->make(StoreProductAttrValueServices::class);
  110. $productAttrValue->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  111. //删除商品详情
  112. /** @var StoreDescriptionServices $productDescription */
  113. $productDescription = app()->make(StoreDescriptionServices::class);
  114. $productDescription->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  115. //删除商品关联分类数据
  116. /** @var StoreProductCateServices $productCate */
  117. $productCate = app()->make(StoreProductCateServices::class);
  118. $productCate->delete([['product_id', 'in', $ids]]);
  119. //删除商品关联优惠券数据
  120. /** @var StoreProductCouponServices $productCoupon */
  121. $productCoupon = app()->make(StoreProductCouponServices::class);
  122. $productCoupon->delete([['product_id', 'in', $ids]]);
  123. //删除商品收藏记录
  124. /** @var StoreProductReplyServices $productRelation */
  125. $productRelation = app()->make(StoreProductReplyServices::class);
  126. $productRelation->delete([['product_id', 'in', $ids], ['reply_type', '=', 'product']]);
  127. //删除商品的评论
  128. /** @var StoreProductReplyServices $productReply */
  129. $productReply = app()->make(StoreProductReplyServices::class);
  130. $productReply->delete([['product_id', 'in', $ids]]);
  131. /** @var StoreProductServices $services */
  132. $services = app()->make(StoreProductServices::class);
  133. $services->delete(1, 'is_del');
  134. return app('json')->success(100046);
  135. }
  136. /**
  137. * 清除用户数据
  138. * @return mixed
  139. */
  140. public function userRelevantData()
  141. {
  142. $this->services->clearData([
  143. 'agent_level_task_record',
  144. 'member_card',
  145. 'member_card_batch',
  146. 'capital_flow',
  147. 'delivery_service',
  148. 'division_agent_apply',
  149. 'luck_lottery_record',
  150. 'other_order',
  151. 'other_order_status',
  152. 'qrcode',
  153. 'sms_record',
  154. 'store_bargain_user',
  155. 'store_bargain_user_help',
  156. 'store_cart',
  157. 'store_coupon_issue_user',
  158. 'store_coupon_user',
  159. 'store_integral_order',
  160. 'store_integral_order_status',
  161. 'store_order',
  162. 'store_order_cart_info',
  163. 'store_order_economize',
  164. 'store_order_invoice',
  165. 'store_order_refund',
  166. 'store_order_status',
  167. 'store_pink',
  168. 'store_product_relation',
  169. 'store_product_reply',
  170. 'store_service',
  171. 'store_service_feedback',
  172. 'store_service_log',
  173. 'store_service_record',
  174. 'store_visit',
  175. 'system_store_staff',
  176. 'user',
  177. 'user_address',
  178. 'user_bill',
  179. 'user_brokerage',
  180. 'user_brokerage_frozen',
  181. 'user_cancel',
  182. 'user_enter',
  183. 'user_extract',
  184. 'user_friends',
  185. 'user_group',
  186. 'user_invoice',
  187. 'user_label',
  188. 'user_label_relation',
  189. 'user_level',
  190. 'user_money',
  191. 'user_notice',
  192. 'user_notice_see',
  193. 'user_recharge',
  194. 'user_search',
  195. 'user_sign',
  196. 'user_spread',
  197. 'user_visit',
  198. 'wechat_user',
  199. ], true);
  200. $this->services->delDirAndFile('./public/uploads/store/comment');
  201. return app('json')->success(100046);
  202. }
  203. /**
  204. * 清除商城数据
  205. * @return mixed
  206. */
  207. public function storeData()
  208. {
  209. $this->services->clearData([
  210. 'agent_level_task',
  211. 'agent_level_task_record',
  212. 'article',
  213. 'article_category',
  214. 'article_content',
  215. 'auxiliary',
  216. 'cache',
  217. 'capital_flow',
  218. 'category',
  219. 'delivery_service',
  220. 'division_agent_apply',
  221. 'live_anchor',
  222. 'live_goods',
  223. 'live_room',
  224. 'live_room_goods',
  225. 'luck_lottery',
  226. 'luck_lottery_record',
  227. 'luck_prize',
  228. 'member_card',
  229. 'member_card_batch',
  230. 'message_system',
  231. 'other_order',
  232. 'other_order_status',
  233. 'qrcode',
  234. 'sms_record',
  235. 'store_advance',
  236. 'store_bargain',
  237. 'store_bargain_user',
  238. 'store_bargain_user_help',
  239. 'store_cart',
  240. 'store_category',
  241. 'store_combination',
  242. 'store_coupon_issue',
  243. 'store_coupon_issue_user',
  244. 'store_coupon_product',
  245. 'store_coupon_user',
  246. 'store_integral',
  247. 'store_integral_order',
  248. 'store_integral_order_status',
  249. 'store_order',
  250. 'store_order_cart_info',
  251. 'store_order_economize',
  252. 'store_order_invoice',
  253. 'store_order_refund',
  254. 'store_order_status',
  255. 'store_pink',
  256. 'store_product',
  257. 'store_product_attr',
  258. 'store_product_attr_result',
  259. 'store_product_attr_value',
  260. 'store_product_cate',
  261. 'store_product_coupon',
  262. 'store_product_description',
  263. 'store_product_log',
  264. 'store_product_relation',
  265. 'store_product_reply',
  266. 'store_product_rule',
  267. 'store_product_virtual',
  268. 'store_seckill',
  269. 'store_service',
  270. 'store_service_feedback',
  271. 'store_service_log',
  272. 'store_service_record',
  273. 'store_visit',
  274. 'system_file',
  275. 'system_log',
  276. 'system_notice',
  277. 'system_notice_admin',
  278. 'system_store',
  279. 'system_store_staff',
  280. 'user',
  281. 'user_address',
  282. 'user_bill',
  283. 'user_brokerage',
  284. 'user_brokerage_frozen',
  285. 'user_cancel',
  286. 'user_enter',
  287. 'user_extract',
  288. 'user_friends',
  289. 'user_group',
  290. 'user_invoice',
  291. 'user_label',
  292. 'user_label_relation',
  293. 'user_level',
  294. 'user_money',
  295. 'user_notice',
  296. 'user_notice_see',
  297. 'user_recharge',
  298. 'user_search',
  299. 'user_sign',
  300. 'user_spread',
  301. 'user_visit',
  302. 'wechat_key',
  303. 'wechat_media',
  304. 'wechat_message',
  305. 'wechat_news_category',
  306. 'wechat_qrcode',
  307. 'wechat_qrcode_cate',
  308. 'wechat_qrcode_record',
  309. 'wechat_reply',
  310. 'wechat_user',
  311. ], true);
  312. return app('json')->success(100046);
  313. }
  314. /**
  315. * 清除商品分类
  316. * @return mixed
  317. */
  318. public function categoryData()
  319. {
  320. $this->services->clearData(['store_category'], true);
  321. return app('json')->success(100046);
  322. }
  323. /**
  324. * 清除订单数据
  325. * @return mixed
  326. */
  327. public function orderData()
  328. {
  329. $this->services->clearData([
  330. 'other_order',
  331. 'other_order_status',
  332. 'store_cart',
  333. 'store_integral_order',
  334. 'store_integral_order_status',
  335. 'store_order',
  336. 'store_order_cart_info',
  337. 'store_order_economize',
  338. 'store_order_invoice',
  339. 'store_order_refund',
  340. 'store_order_status',
  341. 'store_pink',
  342. ], true);
  343. return app('json')->success(100046);
  344. }
  345. /**
  346. * 清除客服数据
  347. * @return mixed
  348. */
  349. public function kefuData()
  350. {
  351. $this->services->clearData([
  352. 'store_service',
  353. 'store_service_log',
  354. 'store_service_record',
  355. 'store_service_feedback',
  356. 'store_service_speechcraft'
  357. ], true);
  358. $this->services->delDirAndFile('./public/uploads/store/service');
  359. return app('json')->success(100046);
  360. }
  361. /**
  362. * 清除微信管理数据
  363. * @return mixed
  364. */
  365. public function wechatData()
  366. {
  367. $this->services->clearData([
  368. 'cache',
  369. 'wechat_key',
  370. 'wechat_media',
  371. 'wechat_message',
  372. 'wechat_news_category',
  373. 'wechat_qrcode',
  374. 'wechat_qrcode_cate',
  375. 'wechat_qrcode_record',
  376. 'wechat_reply'
  377. ], true);
  378. $this->services->delDirAndFile('./public/uploads/wechat');
  379. return app('json')->success(100046);
  380. }
  381. /**
  382. * 清除所有附件
  383. * @return mixed
  384. */
  385. public function attachmentData()
  386. {
  387. $this->services->clearData([
  388. 'system_attachment',
  389. 'system_attachment_category'
  390. ], true);
  391. $this->services->delDirAndFile('./public/uploads/');
  392. return app('json')->success(100046);
  393. }
  394. //清除内容分类
  395. public function articleData()
  396. {
  397. $this->services->clearData([
  398. 'article_category',
  399. 'article',
  400. 'article_content'
  401. ], true);
  402. return app('json')->success(100046);
  403. }
  404. //清除系统记录
  405. public function systemData()
  406. {
  407. $this->services->clearData([
  408. 'system_notice_admin',
  409. 'system_log'
  410. ], true);
  411. return app('json')->success(100046);
  412. }
  413. /**
  414. * 替换域名方法
  415. * @return mixed
  416. */
  417. public function replaceSiteUrl()
  418. {
  419. list($url) = $this->request->postMore([
  420. ['url', '']
  421. ], true);
  422. if (!$url)
  423. return app('json')->fail(400304);
  424. if (!verify_domain($url))
  425. return app('json')->fail(400305);
  426. $this->services->replaceSiteUrl($url);
  427. return app('json')->success(400306);
  428. }
  429. }