停车场管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

101 lines
3.0 KiB

<?php
namespace App\Console\Commands;
use App\Models\ParkingSpace;
use App\Models\ParkingSpaceRepair;
use App\Services\OperationLogService;
use App\Services\ParkingSpaceService;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class AutoChangeRepair extends Command
{
/**
* The name and signature of the console command.
* @var string
*/
protected $signature = 'run:auto-change-repair';
/**
* The console command description.
* @var string
*/
protected $description = 'Command description';
protected OperationLogService $logService;
protected int $user_id;
protected ParkingSpaceService $service;
public function __construct(OperationLogService $log)
{
parent::__construct();
$this->logService = $log;
$this->logService->menuTitle = 'cat_list';
// 默认超级管理员修改
$this->user_id = DB::table('admin_users')->where('username', 'Admin')
->value('id');
$this->service = new ParkingSpaceService($this->logService);
}
/**
* Execute the console command.
*/
public function handle()
{
try {
DB::beginTransaction();
$now_times = time();
$now_time = date("Y-m-d H:i:s", $now_times);
$where = [
['start_at', '<=', $now_time],
['end_at', '>=', $now_time]
];
$space_ids = ParkingSpaceRepair::query()->where($where)->pluck(
'space_id'
);
if ($space_ids) {
$update_ids = ParkingSpace::query()->where('status', '<>', 2)
->whereIn('id', $space_ids)->pluck('id');
// 更新为维修状态
foreach ($update_ids as $id) {
// 修改为类型的维修指定灯光
$this->service->updateRepairStatus($id, 2);
}
}
// 处理在维修的回复正常, 维修已结束的回复正常
$ParkingSpace = ParkingSpace::query();
$ParkingSpace->where('status', 2);
if ($space_ids) {
$ParkingSpace->whereNotIn('id', $space_ids);
}
$space_ids = $ParkingSpace->pluck('id');
if ($space_ids) {
// 维修车位已经 超过维修结束时间, 改为空置状态
$update_ids = ParkingSpaceRepair::query()->where(
'end_at',
'<',
$now_time
)->whereIn('space_id', $space_ids)->pluck(
'space_id'
);
if ($update_ids) {
// 更新为空置状态
foreach ($update_ids as $id) {
// 恢复正常类型灯光
$this->service->updateRepairStatus($id, 0);
}
}
}
DB::commit();
} catch (Exception $e) {
DB::rollBack();
}
}
}