SystemClearData.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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($id = 0)
  97. {
  98. /** @var StoreProductServices $product */
  99. $product = app()->make(StoreProductServices::class);
  100. if ($id) {
  101. $ids = [$id];
  102. } else {
  103. $ids = $product->getColumn(['is_del' => 1], 'id');
  104. }
  105. //清除规格表数据
  106. /** @var StoreProductAttrServices $ProductAttr */
  107. $productAttr = app()->make(StoreProductAttrServices::class);
  108. $productAttr->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  109. /** @var StoreProductAttrResultServices $productAttrResult */
  110. $productAttrResult = app()->make(StoreProductAttrResultServices::class);
  111. $productAttrResult->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  112. /** @var StoreProductAttrValueServices $productAttrValue */
  113. $productAttrValue = app()->make(StoreProductAttrValueServices::class);
  114. $productAttrValue->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  115. //删除商品详情
  116. /** @var StoreDescriptionServices $productDescription */
  117. $productDescription = app()->make(StoreDescriptionServices::class);
  118. $productDescription->delete([['product_id', 'in', $ids], ['type', '=', '0']]);
  119. //删除商品关联分类数据
  120. /** @var StoreProductCateServices $productCate */
  121. $productCate = app()->make(StoreProductCateServices::class);
  122. $productCate->delete([['product_id', 'in', $ids]]);
  123. //删除商品关联优惠券数据
  124. /** @var StoreProductCouponServices $productCoupon */
  125. $productCoupon = app()->make(StoreProductCouponServices::class);
  126. $productCoupon->delete([['product_id', 'in', $ids]]);
  127. //删除商品收藏记录
  128. /** @var StoreProductReplyServices $productRelation */
  129. $productRelation = app()->make(StoreProductReplyServices::class);
  130. $productRelation->delete([['product_id', 'in', $ids], ['reply_type', '=', 'product']]);
  131. //删除商品的评论
  132. /** @var StoreProductReplyServices $productReply */
  133. $productReply = app()->make(StoreProductReplyServices::class);
  134. $productReply->delete([['product_id', 'in', $ids]]);
  135. /** @var StoreProductServices $services */
  136. $services = app()->make(StoreProductServices::class);
  137. if ($id) {
  138. $services->delete($id);
  139. return true;
  140. } else {
  141. $services->delete(1, 'is_del');
  142. return app('json')->success(100046);
  143. }
  144. }
  145. /**
  146. * 清除用户数据
  147. * @return mixed
  148. */
  149. public function userRelevantData()
  150. {
  151. $this->services->clearData([
  152. 'agent_level_task_record',
  153. 'member_card',
  154. 'member_card_batch',
  155. 'capital_flow',
  156. 'delivery_service',
  157. 'division_agent_apply',
  158. 'luck_lottery_record',
  159. 'other_order',
  160. 'other_order_status',
  161. 'qrcode',
  162. 'sms_record',
  163. 'store_bargain_user',
  164. 'store_bargain_user_help',
  165. 'store_cart',
  166. 'store_coupon_issue_user',
  167. 'store_coupon_user',
  168. 'store_integral_order',
  169. 'store_integral_order_status',
  170. 'store_order',
  171. 'store_order_cart_info',
  172. 'store_order_economize',
  173. 'store_order_invoice',
  174. 'store_order_refund',
  175. 'store_order_status',
  176. 'store_pink',
  177. 'store_product_relation',
  178. 'store_product_reply',
  179. 'store_service',
  180. 'store_service_feedback',
  181. 'store_service_log',
  182. 'store_service_record',
  183. 'store_visit',
  184. 'system_store_staff',
  185. 'user',
  186. 'user_address',
  187. 'user_bill',
  188. 'user_brokerage',
  189. 'user_brokerage_frozen',
  190. 'user_cancel',
  191. 'user_enter',
  192. 'user_extract',
  193. 'user_friends',
  194. 'user_group',
  195. 'user_invoice',
  196. 'user_label',
  197. 'user_label_relation',
  198. 'user_level',
  199. 'user_money',
  200. 'user_notice',
  201. 'user_notice_see',
  202. 'user_recharge',
  203. 'user_search',
  204. 'user_sign',
  205. 'user_spread',
  206. 'user_visit',
  207. 'wechat_user',
  208. ], true);
  209. $this->services->delDirAndFile('./public/uploads/store/comment');
  210. return app('json')->success(100046);
  211. }
  212. /**
  213. * 清除商城数据
  214. * @return mixed
  215. */
  216. public function storeData()
  217. {
  218. $this->services->clearData([
  219. 'agent_level_task',
  220. 'agent_level_task_record',
  221. 'article',
  222. 'article_category',
  223. 'article_content',
  224. 'auxiliary',
  225. 'cache',
  226. 'capital_flow',
  227. 'category',
  228. 'delivery_service',
  229. 'division_agent_apply',
  230. 'live_anchor',
  231. 'live_goods',
  232. 'live_room',
  233. 'live_room_goods',
  234. 'luck_lottery',
  235. 'luck_lottery_record',
  236. 'luck_prize',
  237. 'member_card',
  238. 'member_card_batch',
  239. 'message_system',
  240. 'other_order',
  241. 'other_order_status',
  242. 'qrcode',
  243. 'sms_record',
  244. 'store_advance',
  245. 'store_bargain',
  246. 'store_bargain_user',
  247. 'store_bargain_user_help',
  248. 'store_cart',
  249. 'store_category',
  250. 'store_combination',
  251. 'store_coupon_issue',
  252. 'store_coupon_issue_user',
  253. 'store_coupon_product',
  254. 'store_coupon_user',
  255. 'store_integral',
  256. 'store_integral_order',
  257. 'store_integral_order_status',
  258. 'store_order',
  259. 'store_order_cart_info',
  260. 'store_order_economize',
  261. 'store_order_invoice',
  262. 'store_order_refund',
  263. 'store_order_status',
  264. 'store_pink',
  265. 'store_product',
  266. 'store_product_attr',
  267. 'store_product_attr_result',
  268. 'store_product_attr_value',
  269. 'store_product_cate',
  270. 'store_product_coupon',
  271. 'store_product_description',
  272. 'store_product_log',
  273. 'store_product_relation',
  274. 'store_product_reply',
  275. 'store_product_rule',
  276. 'store_product_virtual',
  277. 'store_seckill',
  278. 'store_service',
  279. 'store_service_feedback',
  280. 'store_service_log',
  281. 'store_service_record',
  282. 'store_visit',
  283. 'system_file',
  284. 'system_log',
  285. 'system_notice',
  286. 'system_notice_admin',
  287. 'system_store',
  288. 'system_store_staff',
  289. 'user',
  290. 'user_address',
  291. 'user_bill',
  292. 'user_brokerage',
  293. 'user_brokerage_frozen',
  294. 'user_cancel',
  295. 'user_enter',
  296. 'user_extract',
  297. 'user_friends',
  298. 'user_group',
  299. 'user_invoice',
  300. 'user_label',
  301. 'user_label_relation',
  302. 'user_level',
  303. 'user_money',
  304. 'user_notice',
  305. 'user_notice_see',
  306. 'user_recharge',
  307. 'user_search',
  308. 'user_sign',
  309. 'user_spread',
  310. 'user_visit',
  311. 'wechat_key',
  312. 'wechat_media',
  313. 'wechat_message',
  314. 'wechat_news_category',
  315. 'wechat_qrcode',
  316. 'wechat_qrcode_cate',
  317. 'wechat_qrcode_record',
  318. 'wechat_reply',
  319. 'wechat_user',
  320. ], true);
  321. return app('json')->success(100046);
  322. }
  323. /**
  324. * 清除商品分类
  325. * @return mixed
  326. */
  327. public function categoryData()
  328. {
  329. $this->services->clearData(['store_category'], true);
  330. return app('json')->success(100046);
  331. }
  332. /**
  333. * 清除订单数据
  334. * @return mixed
  335. */
  336. public function orderData()
  337. {
  338. $this->services->clearData([
  339. 'other_order',
  340. 'other_order_status',
  341. 'store_cart',
  342. 'store_integral_order',
  343. 'store_integral_order_status',
  344. 'store_order',
  345. 'store_order_cart_info',
  346. 'store_order_economize',
  347. 'store_order_invoice',
  348. 'store_order_refund',
  349. 'store_order_status',
  350. 'store_pink',
  351. ], true);
  352. return app('json')->success(100046);
  353. }
  354. /**
  355. * 清除客服数据
  356. * @return mixed
  357. */
  358. public function kefuData()
  359. {
  360. $this->services->clearData([
  361. 'store_service',
  362. 'store_service_log',
  363. 'store_service_record',
  364. 'store_service_feedback',
  365. 'store_service_speechcraft'
  366. ], true);
  367. $this->services->delDirAndFile('./public/uploads/store/service');
  368. return app('json')->success(100046);
  369. }
  370. /**
  371. * 清除微信管理数据
  372. * @return mixed
  373. */
  374. public function wechatData()
  375. {
  376. $this->services->clearData([
  377. 'cache',
  378. 'wechat_key',
  379. 'wechat_media',
  380. 'wechat_message',
  381. 'wechat_news_category',
  382. 'wechat_qrcode',
  383. 'wechat_qrcode_cate',
  384. 'wechat_qrcode_record',
  385. 'wechat_reply'
  386. ], true);
  387. $this->services->delDirAndFile('./public/uploads/wechat');
  388. return app('json')->success(100046);
  389. }
  390. /**
  391. * 清除所有附件
  392. * @return mixed
  393. */
  394. public function attachmentData()
  395. {
  396. $this->services->clearData([
  397. 'system_attachment',
  398. 'system_attachment_category'
  399. ], true);
  400. $this->services->delDirAndFile('./public/uploads/');
  401. return app('json')->success(100046);
  402. }
  403. //清除内容分类
  404. public function articleData()
  405. {
  406. $this->services->clearData([
  407. 'article_category',
  408. 'article',
  409. 'article_content'
  410. ], true);
  411. return app('json')->success(100046);
  412. }
  413. //清除系统记录
  414. public function systemData()
  415. {
  416. $this->services->clearData([
  417. 'system_notice_admin',
  418. 'system_log'
  419. ], true);
  420. return app('json')->success(100046);
  421. }
  422. /**
  423. * 替换域名方法
  424. * @return mixed
  425. */
  426. public function replaceSiteUrl()
  427. {
  428. list($url) = $this->request->postMore([
  429. ['url', '']
  430. ], true);
  431. if (!$url)
  432. return app('json')->fail(400304);
  433. if (!verify_domain($url))
  434. return app('json')->fail(400305);
  435. $this->services->replaceSiteUrl($url);
  436. return app('json')->success(400306);
  437. }
  438. }