PowerManage.php
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?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'));
}
}