<?php

namespace App\Console\Commands;

use App\Http\Service\MessageService;
use App\Models\GoodsSku;
use App\Services\Business\MiaoXuan\Goods;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class InitSaleStock extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'init:sale_stock {ids?}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化在售库存';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $ids = $this->argument('ids');
        if(!empty($ids)){
            $ids = explode(',',$ids);
        }
        GoodsSku::query()->where("stock",'>',0)->when($ids,function($query)use($ids){
            $query->whereIn('id',$ids);
        })->update(['sale_stock' => DB::raw('stock')]);

    }
}