ClearMerchantData.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\command;
  12. use think\console\Command;
  13. use think\console\Input;
  14. use think\console\Output;
  15. use think\facade\Db;
  16. class ClearMerchantData extends Command
  17. {
  18. protected function configure()
  19. {
  20. // 指令配置
  21. $this->setName('clear:merchant')
  22. ->setDescription('清空数据(除系统配置以外的所有数据)');
  23. }
  24. protected function execute(Input $input, Output $output)
  25. {
  26. $flag = $output->confirm($input, '清空数据前务必做好数据库的备份,防止数据被误删 !!!', false);
  27. if (!$flag) return;
  28. $tables = Db::query('SHOW TABLES FROM ' . env('database.database', ''));
  29. $pre = env('database.prefix', '');
  30. $bakTables = [
  31. $pre . 'page_link',
  32. $pre . 'page_category',
  33. $pre . 'diy',
  34. $pre . 'city_area',
  35. $pre . 'express',
  36. $pre . 'system_admin',
  37. $pre . 'system_city',
  38. $pre . 'system_config',
  39. $pre . 'system_config_classify',
  40. $pre . 'system_config_value',
  41. $pre . 'system_group',
  42. $pre . 'system_group_data',
  43. $pre . 'system_menu',
  44. $pre . 'system_role',
  45. $pre . 'template_message',
  46. $pre . 'system_notice_config',
  47. $pre . 'cache',
  48. ];
  49. foreach ($tables as $table) {
  50. $name = array_values($table)[0];
  51. if (!in_array($name, $bakTables)) {
  52. Db::table($name)->delete(true);
  53. }
  54. }
  55. Db::table( $pre . 'cache')->whereNotIn('key','copyright_context,copyright_image,copyright_status')->delete(true);
  56. $output->info('删除成功');
  57. }
  58. }