VipOutTime.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\User;
  4. use App\Models\UserVipLogModel;
  5. use Illuminate\Console\Command;
  6. class VipOutTime extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'chenglu:vip_out_time';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = '定期检查用户会员是否过期';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. //定期检查用户VIP是否过期
  37. $data = UserVipLogModel::query()->where(['status'=>1])->orderBy('end_day','asc')->get();
  38. $data = $data->toArray();
  39. foreach ($data as $k=>$v){
  40. if($v['end_day']<date('Y-m-d H:i:s')){
  41. //已经过期
  42. UserVipLogModel::query()->where('id',$v['id'])->update(['status'=>0,'updated_at'=>date('Y-m-d H:i:s')]);
  43. User::query()->where('id',$v['user_id'])->update(['is_vip'=>0]);
  44. }else{
  45. break;
  46. }
  47. }
  48. }
  49. }