diff --git a/app/Http/Controllers/Admin/ParkingSpaceRepairController.php b/app/Http/Controllers/Admin/ParkingSpaceRepairController.php index 3ffb61d..fc1c316 100644 --- a/app/Http/Controllers/Admin/ParkingSpaceRepairController.php +++ b/app/Http/Controllers/Admin/ParkingSpaceRepairController.php @@ -5,13 +5,19 @@ namespace App\Http\Controllers\Admin; use App\Exceptions\CustomException; use App\Exports\ParkingSpaceRepairTemplateExport; use App\Imports\ParkingSpaceRepairImport; +use App\Models\AdminConfigs; use App\Models\AdminFloor; use App\Models\AdminUsers; use App\Models\Parking; use App\Models\ParkingSpace; +use App\Models\ParkingSpaceAttributes; use App\Models\ParkingSpaceRepair; +use App\Models\ParkingSpaceType; +use App\Models\ParkingSpaceTypeAttr; use App\Services\ApiResponseService; +use App\Services\OperationLogService; use App\Services\ParkingSpaceRepairService; +use App\Services\ParkingSpaceTypeService; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -517,4 +523,173 @@ class ParkingSpaceRepairController extends BaseController ); } } + + public function getConfig(): JsonResponse + { + try { + $color = AdminConfigs::getRepairColor(); + $color_arr = (new ParkingSpaceTypeService( + new OperationLogService() + ))->color; + $color_data = []; + $color_temp = []; + $color_hue = ParkingSpaceTypeService::$colorArr; + + foreach ($color_arr as $val) { + $type_str = __service('parking_repair_list.not_color'); + $type_list = []; + $spaceType = ParkingSpaceType::query()->where( + function ($query) use ($val) { + $query->orWhere('default_color_occupy', $val); + $query->orWhere('default_color_vacant', $val); + $query->orWhere('default_color_warning', $val); + } + )->select()->get()->toArray(); + foreach ($spaceType as $temp) { + $type_list[$temp['id']]['space_type_name'] + = ParkingSpaceType::getName($temp['id']); + $space_attr_list = []; + if ($temp['default_color_occupy'] == $val) { + $space_attr_list['occupy'][] + = ParkingSpaceAttributes::getDefaultAttr(); + } + if ($temp['default_color_vacant'] == $val) { + $space_attr_list['vacant'][] + = ParkingSpaceAttributes::getDefaultAttr(); + } + if ($temp['default_color_warning'] == $val) { + $space_attr_list['warning'][] + = ParkingSpaceAttributes::getDefaultAttr(); + } + $type_list[$temp['id']]['space_attr_list'] + = $space_attr_list; + } + + $spaceTypeAttr = ParkingSpaceTypeAttr::query()->where( + function ($query) use ($val) { + $query->orWhere('color_occupy', $val); + $query->orWhere('color_vacant', $val); + $query->orWhere('color_warning', $val); + } + )->select()->get()->toArray(); + + foreach ($spaceTypeAttr as $temp) { + if (!isset($type_list[$temp['space_type_id']]['space_type_name'])) { + $type_list[$temp['space_type_id']]['space_type_name'] + = ParkingSpaceType::getName($temp['space_type_id']); + } + $space_attr_list = []; + if ($temp['color_occupy'] == $val) { + $space_attr_list['occupy'][] + = ParkingSpaceAttributes::getAttr( + $temp['space_attr_id'] + ); + } + if ($temp['color_vacant'] == $val) { + $space_attr_list['vacant'][] + = ParkingSpaceAttributes::getAttr( + $temp['space_attr_id'] + ); + } + if ($temp['color_warning'] == $val) { + $space_attr_list['warning'][] + = ParkingSpaceAttributes::getAttr( + $temp['space_attr_id'] + ); + } + $type_list[$temp['space_type_id']]['space_attr_list'] + = $space_attr_list; + } + + if (empty($type_list)) { + $color_temp[] = $val; + } else { + $type_arr = []; + foreach ($type_list as $t_item) { + if (count($type_arr) >= 2) { + break; + } + $type_arr[] = $t_item['space_type_name']; + } + if ($type_arr) { + $type_str = implode('、', $type_arr); + } + } + + $color_data[] = [ + 'color' => __service('space_type.' . $val), + 'color_hue' => $color_hue[$val] ?? '', + 'type_str' => $type_str, + 'type_list' => $type_list + ]; + } + if (!$color_temp) { + $color_temp = $color_arr; + } + + $color_list = get_select_data($color_temp); + + $data = [ + 'color' => $color, + 'color_data' => $color_data, + 'color_list' => $color_list + ]; + return $this->responseService->success($data); + } catch (Exception $e) { + return $this->responseService->systemError( + __('exception.get_data_failed') + ); + } + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ValidationException + */ + public function setConfig(Request $request): JsonResponse + { + try { + $data = $request->all(); + $rules = [ + 'color' => 'required' + ]; + $messages = [ + 'color.required' => __validation( + 'parking_repair_list.color_empty' + ) + ]; + $validator = Validator::make($data, $rules, $messages); + + if ($validator->fails()) { + throw new ValidationException($validator); + } + $color = $data['color']; + $model = AdminConfigs::query()->where( + 'name', + 'parking_repair' + )->first(); + $oldValue = $model->toArray(); + $content = $oldValue['content'] ?? []; + $content['color'] = $color; + $model->update([ + 'content' => $content, + 'user_id' => $this->adminUserId, + 'updated_at' => get_datetime() + ]); + $logService = new OperationLogService(); + $logService->menuTitle = 'total_configuration'; + $logService->logUpdated($model, $oldValue, 'config.update'); + return $this->responseService->success( + null, + __('admin.operation_successful') + ); + } catch (ValidationException $e) { + throw $e; + } catch (Exception $e) { + return $this->responseService->systemError( + __('admin.operation_failed') + ); + } + } } diff --git a/app/Models/AdminConfigs.php b/app/Models/AdminConfigs.php index c7afc8f..181df93 100644 --- a/app/Models/AdminConfigs.php +++ b/app/Models/AdminConfigs.php @@ -23,4 +23,16 @@ class AdminConfigs extends Model protected $casts = [ 'content' => 'json' ]; + + public static function getRepairColor() + { + $content = AdminConfigs::query()->where( + 'name', + 'parking_repair' + )->value('content'); + if ($content && isset($content['color'])) { + return $content['color']; + } + return ''; + } } diff --git a/app/Models/ParkingSpaceAttributes.php b/app/Models/ParkingSpaceAttributes.php index 619cbb1..a77cb59 100644 --- a/app/Models/ParkingSpaceAttributes.php +++ b/app/Models/ParkingSpaceAttributes.php @@ -74,4 +74,18 @@ class ParkingSpaceAttributes extends Model } )->toArray() ?? []; } + + public static function getDefaultAttr() + { + $model = ParkingSpaceAttributes::query()->where('is_default', 1)->first( + ['id', 'attributes'] + ); + return !$model + ? '' + : AdminTranslationService::getTranslationTypeName( + $model['id'], + 2, + $model['attributes'] + ); + } } diff --git a/app/Services/ParkingSpaceService.php b/app/Services/ParkingSpaceService.php index ebf4f2b..c7714f7 100644 --- a/app/Services/ParkingSpaceService.php +++ b/app/Services/ParkingSpaceService.php @@ -3,6 +3,7 @@ namespace App\Services; use App\Exceptions\CustomException; +use App\Models\AdminConfigs; use App\Models\AdminFloor; use App\Models\Parking; use App\Models\ParkingLicensePlate; @@ -470,8 +471,9 @@ class ParkingSpaceService extends BaseService } // 维修灯 if ($is_repair) { - $color_occupy = $SpaceType['repair_light']; - $color_vacant = $SpaceType['repair_light']; + $repair_light_color = AdminConfigs::getRepairColor(); + $color_occupy = $repair_light_color ?? 'clear'; + $color_vacant = $repair_light_color ?? 'clear'; $is_flicker = false; } diff --git a/app/Services/ParkingSpaceTypeService.php b/app/Services/ParkingSpaceTypeService.php index bae96dc..d1a8bb5 100644 --- a/app/Services/ParkingSpaceTypeService.php +++ b/app/Services/ParkingSpaceTypeService.php @@ -15,7 +15,7 @@ class ParkingSpaceTypeService /** * @var array|string[] */ - protected array $color + public array $color = [ 'red', 'green', diff --git a/database/seeders/AdminConfigSeeder.php b/database/seeders/AdminConfigSeeder.php index 156c4a0..1738aca 100644 --- a/database/seeders/AdminConfigSeeder.php +++ b/database/seeders/AdminConfigSeeder.php @@ -122,6 +122,15 @@ class AdminConfigSeeder extends Seeder ]), 'status' => 1, 'created_at' => $created_at + ], + [ + 'title' => '维修状态配置', + 'name' => 'parking_repair', + 'content' => json_encode([ + 'color' => '', + ]), + 'status' => 1, + 'created_at' => $created_at ] ]; } diff --git a/resources/lang/en/service.php b/resources/lang/en/service.php index b956207..bc4854d 100644 --- a/resources/lang/en/service.php +++ b/resources/lang/en/service.php @@ -173,7 +173,8 @@ return [ 'synced' => 'Synchronized', 'space_not_exists' => 'The parking number does not exist', 'not_send' => 'There is currently no information available for sending maintenance parking space information.', - 'space_exists' => 'Parking space under repair' + 'space_exists' => 'Parking space under repair', + 'not_color' => 'None Available' ], 'gate_control' => [ 'automatic' => 'Automatic entry', diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index e4ddd2c..4ce60f2 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -184,7 +184,8 @@ return [ 'e_empty' => 'The repair end time cannot be empty', 'ids_empty' => 'Please select the data to be deleted', 'ids_array' => 'The selected data must be an array', - 'date_error' => 'The start time cannot be greater than the end time' + 'date_error' => 'The start time cannot be greater than the end time', + 'color_empty' => 'The maintenance indicator light must not be empty.' ], 'gate_control' => [ 'n_empty' => 'Order number or license plate number cannot be empty', diff --git a/resources/lang/zh-CN/service.php b/resources/lang/zh-CN/service.php index 65ccc4f..23331a3 100644 --- a/resources/lang/zh-CN/service.php +++ b/resources/lang/zh-CN/service.php @@ -173,7 +173,8 @@ return [ 'synced' => '已同步', 'space_not_exists' => '车位号不存在', 'not_send' => '目前暂无可发送的维修车位信息', - 'space_exists' => '车位维修中' + 'space_exists' => '车位维修中', + 'not_color' => '暂无' ], 'gate_control' => [ 'automatic' => '自动入场', diff --git a/resources/lang/zh-CN/validation.php b/resources/lang/zh-CN/validation.php index 06acde4..829d586 100644 --- a/resources/lang/zh-CN/validation.php +++ b/resources/lang/zh-CN/validation.php @@ -184,7 +184,8 @@ return [ 'e_empty' => '维修结束时间不能为空', 'ids_empty' => '请选择要删除的数据', 'ids_array' => '所选数据必须是数组', - 'date_error' => '开始时间不能大于结束时间' + 'date_error' => '开始时间不能大于结束时间', + 'color_empty' => '维修指示灯颜色不能为空' ], 'gate_control' => [ 'n_empty' => '订单号码或车牌号码不能为空', diff --git a/resources/lang/zh-TW/service.php b/resources/lang/zh-TW/service.php index 8827ec0..6e147e4 100644 --- a/resources/lang/zh-TW/service.php +++ b/resources/lang/zh-TW/service.php @@ -173,7 +173,8 @@ return [ 'synced' => '已同步', 'space_not_exists' => '車位號不存在', 'not_send' => '目前暫無可發送的維修車位信息', - 'space_exists' => '車位維修中' + 'space_exists' => '車位維修中', + 'not_color' => '暫無' ], 'gate_control' => [ 'automatic' => '自動入場', diff --git a/resources/lang/zh-TW/validation.php b/resources/lang/zh-TW/validation.php index 69b0f7f..b28f1f6 100644 --- a/resources/lang/zh-TW/validation.php +++ b/resources/lang/zh-TW/validation.php @@ -184,7 +184,8 @@ return [ 'e_empty' => '維修結束時間不能為空', 'ids_empty' => '請選擇要删除的數據', 'ids_array' => '所選數據必須是數組', - 'date_error' => '開始時間不能大於結束時間' + 'date_error' => '開始時間不能大於結束時間', + 'color_empty' => '維修指示燈顏色不能為空' ], 'gate_control' => [ 'n_empty' => '訂單號碼或車牌號碼不能為空', diff --git a/routes/admin/api.php b/routes/admin/api.php index 9b3be2c..7a3b958 100644 --- a/routes/admin/api.php +++ b/routes/admin/api.php @@ -191,6 +191,8 @@ Route::group(['prefix' => 'admin'], function () { Route::get('/parkingRepair/search', [ParkingSpaceRepairController::class, 'search']); Route::get('/parkingRepair/rule', [ParkingSpaceRepairController::class, 'rule']); Route::get('/parkingRepair/downloadTemplate', [ParkingSpaceRepairController::class, 'downloadTemplate']); + Route::get('/parkingRepair/config', [ParkingSpaceRepairController::class, 'getConfig']); + Route::post('/parkingRepair/config', [ParkingSpaceRepairController::class, 'setConfig']); // VIP名单 Route::get('/vipList', [VipListController::class, 'index']);