ExportChannel.php 1.7 KB

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