ClearMerchantData.php 1.9 KB

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