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.
80 lines
2.2 KiB
80 lines
2.2 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\AdminNotice;
|
|
use App\Models\ParkingCamera;
|
|
use App\Services\AdminNoticeService;
|
|
use Exception;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class ScheduledMessageDelivery extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
* @var string
|
|
*/
|
|
protected $signature = 'run:scheduled-message-delivery';
|
|
|
|
/**
|
|
* The console command description.
|
|
* @var string
|
|
*/
|
|
protected $description = 'Command description';
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 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 = [
|
|
'alarm_type' => 2,
|
|
'msg_type' => 3,
|
|
'is_notice' => 1
|
|
];
|
|
$list = AdminNotice::query()->where($where)->select()->get();
|
|
foreach ($list as $item) {
|
|
$updated_at = $item['updated_at'];
|
|
$updated_times = strtotime($updated_at);
|
|
$diff_times = $now_times - $updated_times;
|
|
$camera_status = ParkingCamera::query()->where(
|
|
'id',
|
|
$item['camera_id']
|
|
)->value('status');
|
|
|
|
$updated = [
|
|
'updated_at' => $now_time
|
|
];
|
|
if ($camera_status) {
|
|
$updated['is_notice'] = 0;
|
|
AdminNotice::query()->where('id', $item['id'])->update(
|
|
$updated
|
|
);
|
|
} elseif ($diff_times >= 300) {
|
|
AdminNoticeService::eventInfo(
|
|
$item['id'],
|
|
2,
|
|
3,
|
|
$item['alarm_time']
|
|
);
|
|
AdminNotice::query()->where('id', $item['id'])->update(
|
|
$updated
|
|
);
|
|
}
|
|
}
|
|
DB::commit();
|
|
} catch (Exception $e) {
|
|
DB::rollBack();
|
|
}
|
|
}
|
|
}
|
|
|