2
0

ExportChannel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * 导出离线用的channel数据
  4. */
  5. namespace App\Console\Commands;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Support\Facades\Storage;
  8. use App\Models\Channel;
  9. class ExportChannel extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'export:channel';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '导出离线用的channel数据';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return int
  36. */
  37. public function handle()
  38. {
  39. $filename = "public/export/offline/channel.csv";
  40. Storage::disk('local')->put($filename, "");
  41. $file = fopen(storage_path("app/{$filename}"),"w");
  42. fputcsv($file,['id','name','type','language','summary','owner_id','setting','created_at']);
  43. $bar = $this->output->createProgressBar(Channel::where('status',30)->count());
  44. foreach (Channel::where('status',30)->select(['uid','name','type','lang','summary','owner_uid','setting','created_at'])->cursor() as $chapter) {
  45. fputcsv($file,[
  46. $chapter->uid,
  47. $chapter->name,
  48. $chapter->type,
  49. $chapter->lang,
  50. $chapter->summary,
  51. $chapter->owner_uid,
  52. $chapter->setting,
  53. $chapter->created_at,
  54. ]);
  55. $bar->advance();
  56. }
  57. fclose($file);
  58. $bar->finish();
  59. return 0;
  60. }
  61. }