<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

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

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // 修改已过期的店铺状态
        $find_shop = DB::table('shop')
            ->where('shop_state', 1)
            ->get()->toArray();
        if (!empty($find_shop)) {
            foreach ($find_shop as $key => $value) {
                if ($value->shop_opening_type == 1) {
                    if (strtotime($value->shop_on_trial_end_time)<= time()) {//已过期的试用店铺
                        $update_data['shop_state'] = 2;
                    }
                } elseif ($value->shop_opening_type == 2) {
                    if (strtotime($value->shop_opening_end_time)<= time()) {//已过期的正式店铺
                        $update_data['shop_state'] = 2;
                    }
                } else {
                    $update_data['shop_opening_type'] = 1;
                    $update_data['shop_state'] = 2;
                }
                $update_data['shop_update_time'] = date('Y-m-d H:i:s');
                $update_data_res = DB::table('shop')
                    ->where('shop_id', $value->shop_id)
                    ->update($update_data);
            }
        }
    }
}
