Browse Source

维修同步车位安排

master
wanghongjun 3 weeks ago
parent
commit
22c9ae8a19
  1. 51
      app/Http/Controllers/Admin/ParkingSpaceRepairController.php
  2. 53
      app/Services/ParkingSpaceRepairService.php
  3. 3
      resources/lang/en/service.php
  4. 3
      resources/lang/zh-CN/service.php
  5. 3
      resources/lang/zh-TW/service.php

51
app/Http/Controllers/Admin/ParkingSpaceRepairController.php

@ -292,13 +292,7 @@ class ParkingSpaceRepairController extends BaseController
} }
$validator = Validator::make($data, $rules, $messages); $validator = Validator::make($data, $rules, $messages);
$start_at_times = strtotime($data['start_at']); $this->validateDate($data['start_at'], $data['end_at']);
$end_at_times = strtotime($data['end_at']);
if ($start_at_times >= $end_at_times) {
throw new CustomException(
__validation('parking_repair_list.date_error')
);
}
if ($validator->fails()) { if ($validator->fails()) {
throw new ValidationException($validator); throw new ValidationException($validator);
@ -462,13 +456,54 @@ class ParkingSpaceRepairController extends BaseController
} }
/** /**
* 维修开始时间不能大于结束时间
* @param $start_at
* @param $end_at
* @return void
* @throws CustomException
*/
protected function validateDate($start_at, $end_at): void
{
$start_at_times = strtotime($start_at);
$end_at_times = strtotime($end_at);
if ($start_at_times >= $end_at_times) {
throw new CustomException(
__validation('parking_repair_list.date_error')
);
}
}
/**
* @param Request $request
* @return JsonResponse * @return JsonResponse
* @throws CustomException * @throws CustomException
* @throws ValidationException * @throws ValidationException
*/ */
public function synchronizeList(): JsonResponse public function synchronizeList(Request $request): JsonResponse
{ {
try { try {
$data = $request->all();
$rules = [
'start_at' => 'required',
'end_at' => 'required'
];
$messages = [
'start_at.required' => __validation(
'parking_repair_list.s_empty'
),
'end_at.required' => __validation(
'parking_repair_list.e_empty'
)
];
$validator = Validator::make($data, $rules, $messages);
if ($validator->fails()) {
throw new ValidationException($validator);
}
$this->validateDate($data['start_at'], $data['end_at']);
$this->service->synchronize($data);
return $this->responseService->success( return $this->responseService->success(
null, null,
__('admin.operation_successful') __('admin.operation_successful')

53
app/Services/ParkingSpaceRepairService.php

@ -209,4 +209,57 @@ class ParkingSpaceRepairService extends BaseService
throw $e; throw $e;
} }
} }
/**
* @param $data
* @return bool
* @throws CustomException
*/
public function synchronize($data): bool
{
try {
DB::beginTransaction();
$start_at_times = strtotime($data['start_at']);
$start_at = get_datetime('datetime', $start_at_times);
$end_at_times = strtotime($data['end_at']);
$end_at = get_datetime('datetime', $end_at_times);
$newValues = $oldValues = ParkingSpaceRepair::query()->where(
function ($query) use ($start_at, $end_at) {
$query->orWhereRaw("'{$start_at}' BETWEEN start_at AND end_at");
$query->orWhereRaw("'{$end_at}' BETWEEN start_at AND end_at");
}
)->where('sync_status', 0)->select()->get()->toArray();
if (!$oldValues) {
throw new CustomException(__service($this->menuTitle . '.not_send'));//目前暂无可发送的维修车位信息
}
$ids = array_column($oldValues, 'id');
ParkingSpaceRepair::query()->whereIn('id', $ids)->update([
'start_at' => $start_at,
'end_at' => $end_at,
'sync_status' => 1,
'sync_at' => $start_at,
'updated_at' => get_datetime()
]);
$newValues['start_at'] = $start_at;
$newValues['end_at'] = $end_at;
$newValues['sync_status'] = 1;
$newValues['sync_at'] = $start_at;
$this->logService->logUpdatedData(
new ParkingSpaceRepair(),
$oldValues,
$this->menuTitle . '.update',
$newValues
);
DB::commit();
return true;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
} }

3
resources/lang/en/service.php

@ -171,7 +171,8 @@ return [
'parking_repair_list' => [ 'parking_repair_list' => [
'not_synced' => 'Not synced', 'not_synced' => 'Not synced',
'synced' => 'Synchronized', 'synced' => 'Synchronized',
'space_not_exists' => 'The parking number does not exist' 'space_not_exists' => 'The parking number does not exist',
'not_send' => 'There is currently no information available for sending maintenance parking space information.'
], ],
'gate_control' => [ 'gate_control' => [
'automatic' => 'Automatic entry', 'automatic' => 'Automatic entry',

3
resources/lang/zh-CN/service.php

@ -171,7 +171,8 @@ return [
'parking_repair_list' => [ 'parking_repair_list' => [
'not_synced' => '未同步', 'not_synced' => '未同步',
'synced' => '已同步', 'synced' => '已同步',
'space_not_exists' => '車位號不存在' 'space_not_exists' => '车位号不存在',
'not_send' => '目前暂无可发送的维修车位信息'
], ],
'gate_control' => [ 'gate_control' => [
'automatic' => '自动入场', 'automatic' => '自动入场',

3
resources/lang/zh-TW/service.php

@ -171,7 +171,8 @@ return [
'parking_repair_list' => [ 'parking_repair_list' => [
'not_synced' => '未同步', 'not_synced' => '未同步',
'synced' => '已同步', 'synced' => '已同步',
'space_not_exists' => '车位号不存在' 'space_not_exists' => '車位號不存在',
'not_send' => '目前暫無可發送的維修車位信息'
], ],
'gate_control' => [ 'gate_control' => [
'automatic' => '自動入場', 'automatic' => '自動入場',

Loading…
Cancel
Save