CreateOwnerAreaReport.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\OwnerAreaReport;
  4. use App\Services\OwnerService;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. class CreateOwnerAreaReport extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'createOwnerAreaReport';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'create owner area report';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * TODO 25号生成盘点面积记录,记录留空由人工填写
  32. *
  33. * @return void
  34. */
  35. public function handle()
  36. {
  37. /** @var OwnerService $ownerService */
  38. $ownerService = app('OwnerService');
  39. $chunks = ($ownerService->get([],["ownerStoragePriceModels"],false,true))->chunk(50);
  40. $month = date('Y-m-d');
  41. foreach ($chunks as $owners){
  42. $date = date('Y-m-d H:i:s');
  43. $createOwnerAreaReport = [];
  44. foreach ($owners as $owner){
  45. if (!$owner->ownerStoragePriceModels)continue;
  46. foreach ($owner->ownerStoragePriceModels as $model){
  47. $createOwnerAreaReport[] = [
  48. "owner_id" => $owner->id,
  49. "counting_month" => $month,
  50. "user_owner_group_id" => $owner->user_owner_group_id,
  51. "created_at" => $date,
  52. "owner_storage_price_model_id" => $model->id,
  53. ];
  54. }
  55. }
  56. DB::table("owner_area_reports")->insert($createOwnerAreaReport);
  57. }
  58. }
  59. }