停车场管理系统
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.
 
 

86 lines
2.3 KiB

<?php
namespace App\Services;
use App\Models\ParkingCameraSendLog;
use App\Models\ParkingSpaceCamera;
class HikParkingCameraService
{
/**
* 创建变更设备信息
* @param $camera_ip
* @param $color_occupy
* @param $color_vacant
* @param $is_flicker
* @return void
*/
public static function setBody($camera_ip, $color_occupy, $color_vacant, $is_flicker)
{
$body = [
'camera_ip' => $camera_ip,
'color_occupy' => $color_occupy,
'color_vacant' => $color_vacant,
'is_flicker' => $is_flicker ? 1 : 0,
];
$exists = ParkingCameraSendLog::query()->where($body)->where(
'status',
0
)->value('id');
if (!$exists) {
$body['created_at'] = date("Y-m-d H:i:s", time());
ParkingCameraSendLog::query()->create($body);
} else {
$body['updated_at'] = date("Y-m-d H:i:s", time());
ParkingCameraSendLog::query()->where('id', $exists)->update($body);
}
}
/**
* 返回需要变更设备信息
* @return array
*/
public static function getBody(): array
{
$columns = [
'id',
'camera_ip as ip',
'color_occupy',
'color_vacant',
'is_flicker',
];
$body = ParkingCameraSendLog::query()->where('status', 0)->select(
$columns
)->get()->each(function ($item) {
$item['is_flicker'] = (bool)$item['is_flicker'] == 1;
return $item;
})->toArray();
if (!$body) {
return [];
} else {
foreach ($body as $key => $value) {
if ($value['ip']) {
// 不在线不推送
if (!ParkingSpaceCamera::isOnlineCamera($value['ip'])) {
unset($body[$key]);
};
}
}
}
return ['list' => $body];
}
/**
* 变更成功回调
* @param $id
* @return void
*/
public static function sendSuccessful($id): void
{
$model = ParkingCameraSendLog::query()->find($id);
$model->update([
'status' => 1,
'updated_at' => get_datetime()
]);
}
}