BeforeCreateOwnerReport.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\OwnerReport;
  4. use App\Services\OwnerService;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Cache;
  7. class BeforeCreateOwnerReport extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'beforeCreateOwnerReport';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Create owner report in advance and build cache';
  21. /**
  22. * Execute the console command.
  23. *
  24. */
  25. public function handle()
  26. {
  27. /** @var OwnerService $ownerService */
  28. $ownerService = app('OwnerService');
  29. $chunks = ($ownerService->get([],["ownerStoragePriceModels"],false,true))->chunk(50);
  30. foreach ($chunks as $owners){
  31. $insert = [];
  32. $date = date("Y-m-d");
  33. foreach ($owners as $owner){
  34. $insert[] = [
  35. "owner_id" => $owner->id,
  36. "counting_month" => date("Y-m-d"),
  37. "created_at" => $date
  38. ];
  39. //B:business C:customer D:date
  40. Cache::put(date("Y-m")."|B|".$owner->id,0,2764800);
  41. Cache::put(date("Y-m")."|C|".$owner->id,0,2764800);
  42. Cache::put(date("Y-m")."|D|".$owner->id,time(),2764800);
  43. }
  44. OwnerReport::query()->insert($insert);
  45. }
  46. }
  47. }