CreateOwnerAreaReport.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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([],null,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. $createOwnerAreaReport[] = [
  46. "owner_id" => $owner->id,
  47. "counting_month" => $month,
  48. "user_owner_group_id" => $owner->user_owner_group_id,
  49. "created_at" => $date,
  50. ];
  51. }
  52. DB::table("owner_area_reports")->insert($createOwnerAreaReport);
  53. }
  54. }
  55. }