StatSendOrderByDate.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Console\Commands\SendOrder;
  3. use App\Modules\SendOrder\Services\SendOrderChargeStatService;
  4. use Illuminate\Console\Command;
  5. class StatSendOrderByDate extends Command
  6. {
  7. /**
  8. * 执行命令 php artisan send_order:generate_day_stat
  9. *
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'send_order_recharge_stat {--start_date=} {--end_date=}';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '派单充值数据统计';
  21. /**
  22. * @return bool
  23. */
  24. public function handle(): bool
  25. {
  26. $date = date('Y-m-d', strtotime('-1 days'));
  27. $start_date = $this->option('start_date');
  28. $end_date = $this->option('end_date');
  29. // 根据参数判断
  30. if ($start_date && $end_date && $start_date <= $end_date) {
  31. while (strtotime($start_date) <= strtotime($end_date)) {
  32. var_dump($start_date);
  33. // 删除旧数据
  34. SendOrderChargeStatService::deleteSendOrderStatsByDate($start_date);
  35. // 执行
  36. SendOrderChargeStatService::getOrdersByDate($start_date);
  37. // 自增1天
  38. $start_date = date('Y-m-d', strtotime('+1 days', strtotime($start_date)));
  39. }
  40. } else {
  41. // 删除旧数据
  42. SendOrderChargeStatService::deleteSendOrderStatsByDate($date);
  43. // 执行
  44. SendOrderChargeStatService::getOrdersByDate($date);
  45. }
  46. return true;
  47. }
  48. }