AutoExpireCouponJob.php 747 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Http\Models\Coupon;
  5. use Log;
  6. class AutoExpireCouponJob extends Command
  7. {
  8. protected $signature = 'autoExpireCouponJob';
  9. protected $description = '优惠券到期自动置无效';
  10. public function __construct()
  11. {
  12. parent::__construct();
  13. }
  14. public function handle()
  15. {
  16. $couponList = Coupon::query()->where('status', 0)->where('available_end', '<=', time())->get();
  17. if (!$couponList->isEmpty()) {
  18. foreach ($couponList as $coupon) {
  19. Coupon::query()->where('id', $coupon->id)->update(['status' => 2]);
  20. }
  21. }
  22. Log::info('定时任务:' . $this->description);
  23. }
  24. }