OfficialAccountBillsTask.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Modules\Trade\Services\OrderService;
  4. use DB;
  5. use Illuminate\Console\Command;
  6. class OfficialAccountBillsTask extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'official_account_bills_task {--start=} {--end=} {--day=}';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '服务号每日充值统计';
  20. public function handle()
  21. {
  22. $start = $this->option('start');
  23. $end = $this->option('end');
  24. $day = $this->option('day');
  25. if($start && $end){
  26. $this->start_scope($start,$end);
  27. }elseif($day){
  28. $this->start_day($day);
  29. }else{
  30. $this->start();
  31. }
  32. }
  33. private function start(){
  34. $yesterday = date('Y-m-d', strtotime(date("Y-m-d") . " -1 day"));
  35. //echo '$yesterday'.$yesterday.PHP_EOL;
  36. $data = OrderService::getRechargeAmountGroupByOfficial($yesterday);
  37. DB::table('official_account_bills')->insert($data);
  38. }
  39. private function start_scope($start,$end){
  40. if(strtotime($start) >= strtotime($end)){
  41. return false;
  42. }
  43. $temp_start = $start;
  44. while (true){
  45. $this->start_day($temp_start);
  46. if($temp_start == $end){
  47. break;
  48. }
  49. $temp_start = date('Y-m-d',strtotime($temp_start)+86400);
  50. }
  51. return 1;
  52. }
  53. private function start_day($day){
  54. //echo $day.PHP_EOL;
  55. $data = OrderService::getRechargeAmountGroupByOfficial($day);
  56. DB::table('official_account_bills')->insert($data);
  57. }
  58. }