StatisticsNissaya.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 = 360;
  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. $info = $date.','.$strlen.','.count($editor);
  59. $this->info($info);
  60. Storage::disk('local')->append($file, $info);
  61. }
  62. $file = "public/export/nissaya-week.csv";
  63. Storage::disk('local')->put($file, "");
  64. for($i = 1; $i <= $maxDay; $i=$i+7){
  65. $day1 = strtotime("today -{$i} day");
  66. $date1 = date("Y-m-d",$day1);
  67. $j = $i - 7;
  68. $date2 = date("Y-m-d",strtotime("today -{$j} day"));
  69. $editor = Sentence::whereIn('channel_uid',$channels)
  70. ->whereDate('created_at','>',$date1)
  71. ->whereDate('created_at','<=',$date2)
  72. ->groupBy('editor_uid')
  73. ->select('editor_uid')->get();
  74. $info = $date2.','.$date1.','.count($editor);
  75. $this->info($info);
  76. Storage::disk('local')->append($file, $info);
  77. }
  78. return 0;
  79. }
  80. }