StatisticsNissaya.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Channel;
  5. use App\Models\Sentence;
  6. use Illuminate\Support\Facades\Storage;
  7. class StatisticsNissaya extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'statistics:nissaya';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '统计nissaya 每日录入进度';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. $nissaya_channel = Channel::where('type','nissaya')->select('uid')->get();
  38. $channels = [];
  39. foreach ($nissaya_channel as $key => $value) {
  40. # code...
  41. $channels[] = $value->uid;
  42. }
  43. $this->info('channel:'.count($channels));
  44. $maxDay = 300;
  45. $file = "public/export/nissaya-daily.csv";
  46. Storage::disk('local')->put($file, "");
  47. #按天获取数据
  48. for($i = 1; $i <= $maxDay; $i++){
  49. $day = strtotime("today -{$i} day");
  50. $date = date("Y-m-d",$day);
  51. $strlen = Sentence::whereIn('channel_uid',$channels)
  52. ->whereDate('created_at','=',$date)
  53. ->sum('strlen');
  54. $editor = Sentence::whereIn('channel_uid',$channels)
  55. ->whereDate('created_at','=',$date)
  56. ->groupBy('editor_uid')
  57. ->select('editor_uid')->get();
  58. $this->info($date.','.$strlen.','.count($editor));
  59. Storage::disk('local')->append($file, $date.','.$strlen.','.count($editor));
  60. }
  61. return 0;
  62. }
  63. }