ClearDataCommand.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. class ClearDataCommand extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'clear:data';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '清理数据';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. if (!$this->confirm("您确定要清空数据吗?")) {
  36. return true;
  37. }
  38. DB::table('advertisements')->truncate();
  39. DB::table('announcements')->truncate();
  40. DB::table('card_riding_orders')->truncate();
  41. DB::table('card_riding_use_logs')->truncate();
  42. DB::table('card_riding_user_bags')->truncate();
  43. DB::table('user_phone_details')->truncate();
  44. DB::table('users')->truncate();
  45. DB::table('auth')->truncate();
  46. DB::table('refund_logs')->truncate();
  47. DB::table('recharge_orders')->truncate();
  48. DB::table('questions')->truncate();
  49. DB::table('parkings')->truncate();
  50. DB::table('orders')->truncate();
  51. DB::table('rent_orders')->truncate();
  52. DB::table('rent_order_bike_operates')->truncate();
  53. DB::table('order_bike_operates')->truncate();
  54. DB::table('deposit_orders')->truncate();
  55. DB::table('location_logs')->truncate();
  56. DB::table('bike_troubles')->truncate();
  57. DB::table('statistics')->truncate();
  58. DB::table('troubles')->truncate();
  59. DB::table('work_orders')->truncate();
  60. DB::table('worker_bike_operates')->truncate();
  61. DB::table('wallet_logs')->truncate();
  62. DB::table('bikes')->truncate();
  63. DB::table('box_binding')->truncate();
  64. DB::table('workers')->truncate();
  65. DB::table('warning_logs')->truncate();
  66. DB::connection('mongodb')->collection('location_logs')->delete();
  67. DB::table('area_settings')->truncate();
  68. DB::table('areas')->truncate();
  69. DB::table('telescope_entries')->delete();
  70. DB::table('apply_parkings')->truncate();
  71. DB::table('card_riding')->truncate();
  72. DB::table('card_riding_area')->truncate();
  73. DB::table('card_riding_orders')->truncate();
  74. DB::table('card_riding_use_logs')->truncate();
  75. DB::table('card_riding_user_bags')->truncate();
  76. DB::table('coupons')->truncate();
  77. DB::table('coupons_user_bags')->truncate();
  78. DB::table('deposit_card_orders')->truncate();
  79. DB::table('deposit_cards')->truncate();
  80. DB::table('form_ids')->truncate();
  81. DB::table('group_send_smss')->truncate();
  82. DB::table('h5')->truncate();
  83. DB::table('invite_new_users')->truncate();
  84. DB::table('invite_new_users_configs')->truncate();
  85. DB::table('invite_new_users_give_gift_logs')->truncate();
  86. DB::table('punishment_orders')->truncate();
  87. DB::table('recharge_configuration')->truncate();
  88. DB::table('refund_balance_orders')->truncate();
  89. DB::table('uploads')->truncate();
  90. if ($this->confirm('是否清除用户信息?', false)) {
  91. DB::table('admin_users')->truncate();
  92. //创建用户
  93. DB::table('admin_users')->insert([
  94. 'job_number' => '10001',
  95. 'name' => '超级管理员',
  96. 'account' => 'admin',
  97. 'phone' => '15225006562',
  98. 'password' => '$2y$10$Q8rl3Esl4Gjjp/GFTHa/MeWTdUq/PU15LnmlM7NXjwqKN5X30fGA6',
  99. 'type' => 1,
  100. 'pid' => 0,
  101. 'status' => 1,
  102. 'admin_id' => 0,
  103. 'area_id' => 0,
  104. 'is_login_app' => 1,
  105. ]);
  106. DB::table('admin_area')->truncate();
  107. DB::table('admin_area')->insert([
  108. 'admin_id' => 1,
  109. 'area_id' => 99999,
  110. ]);
  111. DB::table('admin_user_role')->truncate();
  112. DB::table('admin_user_role')->insert([
  113. 'user_id' => 1,
  114. 'role_id' => 1,
  115. ]);
  116. }
  117. $this->line('ok');
  118. }
  119. }