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

178 lines
4.7 KiB

<?php
namespace App\Services;
use App\Models\ParkingAlarmInformation;
use Exception;
use Illuminate\Support\Facades\DB;
class ParkingAlarmInformationService extends BaseService
{
public array $typeArr
= [
1 => 'scene',
2 => 'notice'
];
public array $noticeTypeArr
= [
1 => 'info_notice',
2 => 'support_notice'
];
public array $levelArr
= [
1 => 'urgent',
2 => 'high',
3 => 'middle',
4 => 'low',
5 => 'info'
];
public array $handlerUserArr
= [
1 => 'handler1',
2 => 'handler2',
3 => 'handler3',
4 => 'handler4'
];
protected string $menuTitle = 'alarm_information';
public function getItem($item)
{
$item['name'] = AdminTranslationService::getTranslationTypeName(
$item['id'],
100,
$item['name']
);
$typeArr = $this->getTypeArr();
$item['type_str'] = $typeArr[$item['type']];
$noticeTypeArr = $this->getNoticeTypeArr();
$item['notice_type_str'] = $noticeTypeArr[$item['notice_type']];
$levelArr = $this->getLevelArr();
$item['level_str'] = $levelArr[$item['level']];
$item['condition'] = AdminTranslationService::getTranslationTypeName(
$item['id'],
101,
$item['condition']
);
$item['content'] = AdminTranslationService::getTranslationTypeName(
$item['id'],
102,
$item['content']
);
$item['remark'] = AdminTranslationService::getTranslationTypeName(
$item['id'],
103,
$item['remark']
);
$handlerUserArr = $this->getHandlerUserArr();
$item['handler_username'] = $handlerUserArr[$item['handler_user']] ?? '';
$item['handler_remark']
= AdminTranslationService::getTranslationTypeName(
$item['id'],
104,
$item['handler_remark']
);
return $item;
}
/**
* @return array|string[]
*/
public function getTypeArr(): array
{
$typeArr = $this->typeArr;
foreach ($typeArr as $key => $value) {
$typeArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $typeArr;
}
/**
* @return array|string[]
*/
public function getNoticeTypeArr(): array
{
$noticeTypeArr = $this->noticeTypeArr;
foreach ($noticeTypeArr as $key => $value) {
$noticeTypeArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $noticeTypeArr;
}
/**
* @return array|string[]
*/
public function getLevelArr(): array
{
$levelArr = $this->levelArr;
foreach ($levelArr as $key => $value) {
$levelArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $levelArr;
}
/**
* @return array|string[]
*/
public function getHandlerUserArr(): array
{
$handlerUserArr = $this->handlerUserArr;
foreach ($handlerUserArr as $key => $value) {
$handlerUserArr[$key] = __service($this->menuTitle . '.' . $value);
}
return $handlerUserArr;
}
public function allocation($id, $handler_user)
{
try {
DB::beginTransaction();
$model = ParkingAlarmInformation::query()->findOrFail($id);
$oldValue = $model->toArray();
$model->update([
'handler_user' => $handler_user,
'updated_at' => get_datetime()
]);
$this->logService->logUpdated(
$model,
$oldValue,
$this->menuTitle . '.allocation_user'
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
public function editRemark($id, $remark)
{
try {
DB::beginTransaction();
$model = ParkingAlarmInformation::query()->findOrFail($id);
$oldValue = $model->toArray();
$model->update([
'handler_remark' => $remark,
'updated_at' => get_datetime()
]);
$this->logService->logUpdated(
$model,
$oldValue,
$this->menuTitle . '.edit_remark'
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
}