AutoExpireInviteJob.php 763 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\Invite;
  5. use Log;
  6. class AutoExpireInviteJob extends Command
  7. {
  8. protected $signature = 'command:autoExpireInviteJob';
  9. protected $description = '邀请码过期自动置无效';
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. public function handle()
  15. {
  16. $inviteList = Invite::query()->where('status', 0)->where('dateline', '<=', date('Y-m-d H:i:s'))->get();
  17. if (!$inviteList->isEmpty()) {
  18. foreach ($inviteList as $invite) {
  19. Invite::query()->where('id', $invite->id)->update(['status' => 2]);
  20. }
  21. }
  22. Log::info('定时任务:' . $this->description);
  23. }
  24. }