BackupInterface.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Support\Facades\Storage;
  6. use Symfony\Component\Process\Process;
  7. class BackupInterface extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'tty:backupInterface';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '备份数据库';
  21. protected $process;
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return int
  35. */
  36. public function handle()
  37. {
  38. $this->exportData();
  39. return 0;
  40. }
  41. private function exportData()
  42. {
  43. $list = DB::table('dep_interface')->get();
  44. foreach ($list as $row) {
  45. $row = get_object_vars($row);
  46. $websiteId = $row['website_id'];
  47. $row['request_settings'] = json_decode($row['request_settings'], true);
  48. $row['condition_settings'] = json_decode($row['condition_settings'], true);
  49. $row['sort_settings'] = json_decode($row['sort_settings'], true);
  50. $row['result_settings'] = json_decode($row['result_settings'], true);
  51. $row['conditions'] = json_decode($row['conditions'], true);
  52. unset($row['id']);
  53. unset($row['mid']);
  54. unset($row['weight']);
  55. unset($row['is_delete']);
  56. unset($row['created_at']);
  57. unset($row['updated_at']);
  58. $assemble_id = $row['assemble_id'];
  59. $assembleInfo = DB::table('sys_assemble')->where('id', $assemble_id)->first();
  60. if ($assembleInfo) {
  61. $row['assemble_id'] = $assembleInfo->schema;
  62. } else {
  63. $row['assemble_id'] = 0;
  64. }
  65. if (!file_exists(storage_path('interface/' . $websiteId))) {
  66. mkdir(storage_path('interface/' . $websiteId), "0777", true);
  67. }
  68. file_put_contents(storage_path('interface/' . $websiteId . '/' . $row['en_alias'] . '.js'), 'return ' . json_encode($row));
  69. }
  70. }
  71. }