<?php

namespace App\Console\Commands;

use App\Facades\CommonService;
use App\Models\MeetRoom;
use App\Models\MeetRoomReserve;
use App\Models\RestaurantDate;
use Illuminate\Console\Command;

class CreateRestaurantDate extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create:restaurant:date';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '提前生成订餐日历';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $date = date('Y-m-d'); // 当前日期
        $start_date = date('Y-m-01', strtotime('+1 month',strtotime($date)));
        $end_date = date('Y-m-d', strtotime("$start_date + 1 month -1 day"));
        $dailies = CommonService::daliy($start_date, $end_date);
        foreach ($dailies as $day){
            $status = 2;
//            $day_of_week = date('w', strtotime($day));
//            if($day_of_week == 0){
//                $status = 2;
//            }
            $exists = RestaurantDate::where('date',$day)->exists();
            if($exists){
                continue;
            }
            RestaurantDate::create(['date'=>$day,'status'=>$status]);
        }
        return Command::SUCCESS;
    }
}
