OrderCountingRecordTask.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Services\LogService;
  4. use App\Services\NewOrderCountingRecordService;
  5. use Illuminate\Console\Command;
  6. class OrderCountingRecordTask extends Command
  7. {
  8. /**
  9. * @var NewOrderCountingRecordService $service
  10. */
  11. public $service;
  12. /**
  13. * The name and signature of the console command.
  14. *
  15. * @var string
  16. */
  17. protected $signature = 'orderCountingRecordTask';
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = 'Command description';
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33. /**
  34. * Execute the console command.
  35. *
  36. * @throws \Exception
  37. */
  38. public function handle()
  39. {
  40. LogService::log(OrderCountingRecordTask::class, "订单量统计", '');
  41. ini_set('memory_limit', '2226M');
  42. $this->service = app('NewOrderCountingRecordService');
  43. if (now()->toDateString() == now()->startOfMonth()->toDateString()) {//是否为月初
  44. //统计上月的数据
  45. $this->service->recordOrder(now()->subMonth()->startOfMonth()->toDateString(), now()->subMonth()->endOfMonth()->toDateString(), '月');
  46. }
  47. if (now()->toDateString() == now()->startOfYear()->toDateString()) {//是否为年初
  48. //统计上年的数据
  49. $this->service->recordOrder(now()->subYear()->startofYear()->toDateString(), now()->subYear()->endOfYear()->toDateString(), '年');
  50. }
  51. //统计前一天的数据
  52. $this->service->recordOrder(now()->subDay()->toDateString(), now()->subDay()->toDateString(), '日');
  53. }
  54. }