Browse Source

岗亭管理

master
wanghongjun 2 weeks ago
parent
commit
b06e101e34
  1. 227
      app/Http/Controllers/Admin/GuardBoothManagementController.php
  2. 4
      app/Http/Controllers/Admin/ParkingChannelController.php
  3. 4
      app/Http/Controllers/Admin/RegionalManagementController.php
  4. 136
      app/Services/ParkingGuardBoothService.php
  5. 5
      resources/lang/en/log.php
  6. 3
      resources/lang/en/service.php
  7. 3
      resources/lang/en/validation.php
  8. 5
      resources/lang/zh-CN/log.php
  9. 3
      resources/lang/zh-CN/service.php
  10. 3
      resources/lang/zh-CN/validation.php
  11. 5
      resources/lang/zh-TW/log.php
  12. 3
      resources/lang/zh-TW/service.php
  13. 3
      resources/lang/zh-TW/validation.php
  14. 8
      routes/admin/api.php

227
app/Http/Controllers/Admin/GuardBoothManagementController.php

@ -0,0 +1,227 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Exceptions\CustomException;
use App\Models\ParkingGuardBooth;
use App\Services\AdminTranslationService;
use App\Services\ApiResponseService;
use App\Services\ParkingGuardBoothService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
class GuardBoothManagementController extends BaseController
{
protected string $menuUri = 'guardBoothManagement';
/**
* @var ParkingGuardBoothService
*/
protected ParkingGuardBoothService $service;
/**
* 构造函数
* @param ApiResponseService $responseService
* @param ParkingGuardBoothService $service
*/
public function __construct(
ApiResponseService $responseService,
ParkingGuardBoothService $service
) {
parent::__construct($responseService);
$this->service = $service;
}
/**
* @param Request $request
* @return JsonResponse
*/
public function index(Request $request): JsonResponse
{
try {
$query = ParkingGuardBooth::query();
if ($request->has('name')) {
$name = $request->input('name');
if ($name) {
$query->where('name', 'like', "%{$name}%");
}
}
if ($request->has('create_start_time')
&& $request->has(
'create_end_time'
)
) {
$create_start_time = $request->input('create_start_time');
$create_end_time = $request->input('create_end_time');
if ($create_start_time && $create_end_time) {
$query->whereBetween('created_at', [
$create_start_time . ' 00:00:00',
$create_end_time . ' 23:59:59'
]);
}
}
// 分页
$page = $request->input('page', 1);
$perPage = $request->input('per_page', 10);
$total = $query->count();
$items = $query->latest()->forPage($page, $perPage)->get()->each(
function ($item) {
$item['name']
= AdminTranslationService::getTranslationTypeName(
$item['id'],
7,
$item['name']
);
return $item;
}
);
return $this->responseService->success([
'items' => $items,
'total' => $total,
'page' => $page,
'per_page' => $perPage,
'last_page' => ceil($total / $perPage),
]);
} catch (Exception $e) {
$m_prefix = __('exception.exception_handler.resource');
return $this->responseService->systemError(
$m_prefix . ':' . $e->getMessage()
);
}
}
/**
* @param Request $request
* @return JsonResponse
* @throws CustomException
* @throws ValidationException
*/
public function store(Request $request): JsonResponse
{
try {
$this->saveValidator($request->all());
$this->service->createModel($request->all());
return $this->responseService->success(
null,
__('admin.save_succeeded')
);
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(
__('admin.operation_failed') . ':'
. $e->getMessage()
);
}
}
/**
* @param array $data
* @param int $id
* @return void
* @throws ValidationException
*/
protected function saveValidator(array $data, int $id = 0): void
{
$rules = [
'name' => 'required'
];
$messages = [
'name.required' => __(
'validation.guard_booth_management.n_empty'
)
];
if ($id) {
$this->validateId($id, ParkingGuardBooth::class);
}
$validator = Validator::make($data, $rules, $messages);
if ($validator->fails()) {
throw new ValidationException($validator);
}
}
/**
* @param string $id
* @return JsonResponse
*/
public function edit(string $id): JsonResponse
{
try {
$this->validateId($id, ParkingGuardBooth::class);
$data = [
'item' => ParkingGuardBooth::query()->find($id)
];
$Translation = AdminTranslationService::getTranslation(
$data['item']['id'],
7
);
$data['item']['en_name'] = $Translation['en'] ?? '';
$data['item']['tw_name'] = $Translation['zh_tw'] ?? '';
return $this->responseService->success($data);
} catch (Exception $e) {
return $this->responseService->systemError(
__('exception.get_data_failed') . ':' . $e->getMessage()
);
}
}
/**
* @param Request $request
* @param string $id
* @return JsonResponse
* @throws CustomException
* @throws ValidationException
*/
public function update(Request $request, string $id): JsonResponse
{
try {
$this->saveValidator($request->all(), $id);
$this->service->updateModel($request->all(), $id);
return $this->responseService->success(
null,
__('admin.update_succeeded')
);
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(
__('admin.operation_failed') . ':'
. $e->getMessage()
);
}
}
/**
* @param string $id
* @return JsonResponse
* @throws CustomException
* @throws ValidationException
*/
public function destroy(string $id): JsonResponse
{
try {
$this->validateId($id, ParkingGuardBooth::class);
$this->service->deleteModel($id);
return $this->responseService->success(
null,
__('admin.delete_succeeded')
);
} catch (ValidationException|CustomException $e) {
throw $e;
} catch (Exception $e) {
return $this->responseService->systemError(
__('exception.admin_floor.destroy_failed') . ':'
. $e->getMessage()
);
}
}
}

4
app/Http/Controllers/Admin/ParkingChannelController.php

@ -174,7 +174,7 @@ class ParkingChannelController extends BaseController
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.admin_floor.create_failed') . ':' __('admin.operation_failed') . ':'
. $e->getMessage() . $e->getMessage()
); );
} }
@ -275,7 +275,7 @@ class ParkingChannelController extends BaseController
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.admin_floor.update_failed') . ':' __('admin.operation_failed') . ':'
. $e->getMessage() . $e->getMessage()
); );
} }

4
app/Http/Controllers/Admin/RegionalManagementController.php

@ -179,7 +179,7 @@ class RegionalManagementController extends BaseController
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.admin_floor.create_failed') . ':' __('admin.operation_failed') . ':'
. $e->getMessage() . $e->getMessage()
); );
} }
@ -275,7 +275,7 @@ class RegionalManagementController extends BaseController
throw $e; throw $e;
} catch (Exception $e) { } catch (Exception $e) {
return $this->responseService->systemError( return $this->responseService->systemError(
__('exception.admin_floor.update_failed') . ':' __('admin.operation_failed') . ':'
. $e->getMessage() . $e->getMessage()
); );
} }

136
app/Services/ParkingGuardBoothService.php

@ -0,0 +1,136 @@
<?php
namespace App\Services;
use App\Models\ParkingGuardBooth;
use Exception;
use Illuminate\Support\Facades\DB;
class ParkingGuardBoothService extends BaseService
{
protected string $menuTitle = 'guard_booth_management';
/**
* @param array $data
* @throws Exception
*/
public function createModel(array $data)
{
try {
DB::beginTransaction();
$existsWhere = [
['name', '=', $data['name']]
];
if (ParkingGuardBooth::query()->where($existsWhere)->exists()) {
throw new Exception(
__('service.guard_booth_management.name_exists')
);
}
$model = ParkingGuardBooth::query()->create([
'name' => $data['name'],
'remake' => $data['remake'] ?? '',
'created_at' => get_datetime()
]);
$this->logService->logCreated(
$model,
'guard_booth_management.create'
);
AdminTranslationService::saveTranslation(
$data['name'],
$data['en_name'] ?? '',
$data['tw_name'] ?? '',
$model->id,
7
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
/**
* @param array $data
* @param int $id
* @throws Exception
*/
public function updateModel(array $data, int $id)
{
try {
DB::beginTransaction();
// 验证
$existsWhere = [
['name', '=', $data['name']],
['id', '<>', $id]
];
if (ParkingGuardBooth::query()->where($existsWhere)->exists()) {
throw new Exception(
__('service.guard_booth_management.name_exists')
);
}
// 更新
$model = ParkingGuardBooth::query()->findOrFail($id);
$oldValues = $model->toArray();
$model->update([
'name' => $data['name'],
'remake' => $data['remake'] ?? '',
'updated_at' => get_datetime()
]);
$this->logService->logUpdated(
$model,
$oldValues,
'guard_booth_management.update'
);
AdminTranslationService::saveTranslation(
$data['name'],
$data['en_name'] ?? '',
$data['tw_name'] ?? '',
$id,
7
);
DB::commit();
return $model;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
/**
* @param $id
* @return bool
* @throws Exception
*/
public function deleteModel($id): bool
{
try {
DB::beginTransaction();
$model = ParkingGuardBooth::query()->findOrFail($id);
$this->logService->logDeleted($model, 'guard_booth_management.delete');
$model->delete();
AdminTranslationService::syncDelete($id, 7);
DB::commit();
return true;
} catch (Exception $e) {
DB::rollBack();
throw $e;
}
}
}

5
resources/lang/en/log.php

@ -106,5 +106,10 @@ return [
'create' => 'Create channel', 'create' => 'Create channel',
'update' => 'Update channel', 'update' => 'Update channel',
'delete' => 'Delete channel' 'delete' => 'Delete channel'
],
'guard_booth_management' => [
'create' => 'Create a booth',
'update' => 'Update the booth',
'delete' => 'Delete the booth'
] ]
]; ];

3
resources/lang/en/service.php

@ -104,5 +104,8 @@ return [
'on-site' => 'on-site', 'on-site' => 'on-site',
'off-site' => 'off-site', 'off-site' => 'off-site',
'name_exists' => 'The channel name already exists' 'name_exists' => 'The channel name already exists'
],
'guard_booth_management' => [
'name_exists' => 'The booth name already exists'
] ]
]; ];

3
resources/lang/en/validation.php

@ -143,5 +143,8 @@ return [
'po_empty' => 'The channel position cannot be empty', 'po_empty' => 'The channel position cannot be empty',
'pa_empty' => 'The affiliated parking lot cannot be empty', 'pa_empty' => 'The affiliated parking lot cannot be empty',
'g_empty' => 'The affiliated booth cannot be empty' 'g_empty' => 'The affiliated booth cannot be empty'
],
'guard_booth_management' => [
'n_empty' => 'The booth name cannot be empty',
] ]
]; ];

5
resources/lang/zh-CN/log.php

@ -106,5 +106,10 @@ return [
'create' => '创建通道', 'create' => '创建通道',
'update' => '更新通道', 'update' => '更新通道',
'delete' => '删除通道' 'delete' => '删除通道'
],
'guard_booth_management' => [
'create' => '创建岗亭',
'update' => '更新岗亭',
'delete' => '删除岗亭'
] ]
]; ];

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

@ -104,5 +104,8 @@ return [
'on-site' => '场内', 'on-site' => '场内',
'off-site' => '场外', 'off-site' => '场外',
'name_exists' => '通道名称已存在' 'name_exists' => '通道名称已存在'
],
'guard_booth_management' => [
'name_exists' => '岗亭名称已存在'
] ]
]; ];

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

@ -143,5 +143,8 @@ return [
'po_empty' => '通道位置不能为空', 'po_empty' => '通道位置不能为空',
'pa_empty' => '所属车场不能为空', 'pa_empty' => '所属车场不能为空',
'g_empty' => '所属岗亭不能为空' 'g_empty' => '所属岗亭不能为空'
],
'guard_booth_management' => [
'n_empty' => '岗亭名称不能为空',
] ]
]; ];

5
resources/lang/zh-TW/log.php

@ -106,5 +106,10 @@ return [
'create' => '創建通道', 'create' => '創建通道',
'update' => '更新通道', 'update' => '更新通道',
'delete' => '删除通道' 'delete' => '删除通道'
],
'guard_booth_management' => [
'create' => '創建崗亭',
'update' => '更新崗亭',
'delete' => '删除崗亭'
] ]
]; ];

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

@ -104,5 +104,8 @@ return [
'on-site' => '場內', 'on-site' => '場內',
'off-site' => '場外', 'off-site' => '場外',
'name_exists' => '通道名稱已存在' 'name_exists' => '通道名稱已存在'
],
'guard_booth_management' => [
'name_exists' => '崗亭名稱已存在'
] ]
]; ];

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

@ -143,5 +143,8 @@ return [
'po_empty' => '通道位置不能為空', 'po_empty' => '通道位置不能為空',
'pa_empty' => '所屬車場不能為空', 'pa_empty' => '所屬車場不能為空',
'g_empty' => '所屬崗亭不能為空' 'g_empty' => '所屬崗亭不能為空'
],
'guard_booth_management' => [
'n_empty' => '崗亭名稱不能為空',
] ]
]; ];

8
routes/admin/api.php

@ -32,6 +32,7 @@ use App\Http\Controllers\Admin\ParkingManagementListController;
use App\Http\Controllers\Admin\ParkingAttendantController; use App\Http\Controllers\Admin\ParkingAttendantController;
use App\Http\Controllers\Admin\RegionalManagementController; use App\Http\Controllers\Admin\RegionalManagementController;
use App\Http\Controllers\Admin\ParkingChannelController; use App\Http\Controllers\Admin\ParkingChannelController;
use App\Http\Controllers\Admin\GuardBoothManagementController;
Route::group(['prefix' => 'admin'], function () { Route::group(['prefix' => 'admin'], function () {
@ -248,6 +249,13 @@ Route::group(['prefix' => 'admin'], function () {
Route::delete('/channelManagement/{id}', [ParkingChannelController::class, 'destroy']); Route::delete('/channelManagement/{id}', [ParkingChannelController::class, 'destroy']);
Route::get('/channelManagement/rule', [ParkingChannelController::class, 'rule']); Route::get('/channelManagement/rule', [ParkingChannelController::class, 'rule']);
Route::get('/channelManagement/search', [ParkingChannelController::class, 'search']); Route::get('/channelManagement/search', [ParkingChannelController::class, 'search']);
// 岗亭管理
Route::get('/guardBoothManagement', [GuardBoothManagementController::class, 'index']);
Route::post('/guardBoothManagement', [GuardBoothManagementController::class, 'store']);
Route::get('/guardBoothManagement/edit/{id}', [GuardBoothManagementController::class, 'edit']);
Route::put('/guardBoothManagement/{id}', [GuardBoothManagementController::class, 'update']);
Route::delete('/guardBoothManagement/{id}', [GuardBoothManagementController::class, 'destroy']);
Route::get('/guardBoothManagement/rule', [GuardBoothManagementController::class, 'rule']);
// 角色 // 角色
Route::get('/roles', [RolesController::class, 'index']); Route::get('/roles', [RolesController::class, 'index']);
Route::get('/roles/create', [RolesController::class, 'create']); Route::get('/roles/create', [RolesController::class, 'create']);

Loading…
Cancel
Save