BeforeCreateOwnerReport.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. const TTL = 2764800;
  22. /**
  23. * Execute the console command.
  24. *
  25. */
  26. public function handle()
  27. {
  28. /** @var OwnerService $ownerService */
  29. $ownerService = app('OwnerService');
  30. $chunks = ($ownerService->get([],["ownerStoragePriceModels"],false,true))->chunk(50);
  31. foreach ($chunks as $owners){
  32. $insert = [];
  33. $date = date("Y-m-d");
  34. foreach ($owners as $owner){
  35. $insert[] = [
  36. "owner_id" => $owner->id,
  37. "counting_month" => date("Y-m-d"),
  38. "created_at" => $date
  39. ];
  40. //A:件 B:business C:customer D:date
  41. Cache::put(date("Y-m")."|B|".$owner->id,0,self::TTL);
  42. Cache::put(date("Y-m")."|C|".$owner->id,0,self::TTL);
  43. Cache::put(date("Y-m")."|D|".$owner->id,time(),self::TTL);
  44. Cache::put(date("Y-m")."|A|".$owner->id,0,self::TTL);
  45. }
  46. OwnerReport::query()->insert($insert);
  47. }
  48. }
  49. }