CreateOwnerAreaReport.php 1.9 KB

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