PowerManage.php 1.55 KB
<?php

namespace App\Console\Commands;

use App\Modules\Models\Power\Power;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class PowerManage extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'PowerManage {--day=}';

    /**
     * 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()
    {
        //

//        $re =  DB::select('select p.id,p.power_no,p.has_power,p.status,m.mac_no,p.hatch_no,pr.is_return from power p
//                    left join
//                    (select pr2.power_no, pr2.is_return from (select * from production pr1 order by id desc) pr2 group by pr2.power_no, pr2.is_return ) pr
//                    on p.power_no = pr.power_no
//                    left join machine m on p.machine_id= m.id
//                    where p.status in (1, 2, 3) and pr.is_return = 1');

        $re =  DB::select('select p.id from power p where p.status in (1, 2, 3)');

        $ids = array_column($re,'id');

        $res = Power::whereIn('id', $ids)->update(['status'=>1, 'machine_id'=>null, 'hatch_no'=>null]);

        Log::info('共维护'.$res.'个讲解器。'.date('Y-m-d'));
    }
}