VipOutTime.php 1.5 KB

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