SetMemberDatas.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. class SetMemberDatas extends Command
  5. {
  6. /**
  7. * The name and signature of the console command.
  8. *
  9. * @var string
  10. */
  11. protected $signature = 'update:data';
  12. /**
  13. * The console command description.
  14. *
  15. * @var string
  16. */
  17. protected $description = 'Update member data';
  18. /**
  19. * Execute the console command.
  20. *
  21. * @return int
  22. */
  23. public function handle()
  24. {
  25. $members = \App\Models\Member::all();
  26. foreach($members as $member)
  27. {
  28. $status = $member->getStatus();
  29. $status = $status["status"];
  30. $has_certificate = $member->hasCertificate();
  31. $certificate = 0;
  32. $certificate_date = null;
  33. if($has_certificate["date"] != '')
  34. {
  35. if($has_certificate["date"] < date("Y-m-d"))
  36. $certificate = 0;
  37. if($has_certificate["date"] >= date("Y-m-d") && $has_certificate["date"] < date("Y-m-d", strtotime("+1 month")))
  38. $certificate = 1;
  39. if($has_certificate["date"] >= date("Y-m-d", strtotime("+1 month")))
  40. $certificate = 2;
  41. $certificate_date = $has_certificate["date"] != '' ? $has_certificate["date"] : null;
  42. }
  43. $member->current_status = $status;
  44. $member->certificate = $certificate;
  45. $member->certificate_date = $certificate_date;
  46. $member->save();
  47. }
  48. return Command::SUCCESS;
  49. }
  50. }