|
|
@ -5,13 +5,19 @@ namespace App\Http\Controllers\Admin; |
|
|
use App\Exceptions\CustomException; |
|
|
use App\Exceptions\CustomException; |
|
|
use App\Exports\ParkingSpaceRepairTemplateExport; |
|
|
use App\Exports\ParkingSpaceRepairTemplateExport; |
|
|
use App\Imports\ParkingSpaceRepairImport; |
|
|
use App\Imports\ParkingSpaceRepairImport; |
|
|
|
|
|
use App\Models\AdminConfigs; |
|
|
use App\Models\AdminFloor; |
|
|
use App\Models\AdminFloor; |
|
|
use App\Models\AdminUsers; |
|
|
use App\Models\AdminUsers; |
|
|
use App\Models\Parking; |
|
|
use App\Models\Parking; |
|
|
use App\Models\ParkingSpace; |
|
|
use App\Models\ParkingSpace; |
|
|
|
|
|
use App\Models\ParkingSpaceAttributes; |
|
|
use App\Models\ParkingSpaceRepair; |
|
|
use App\Models\ParkingSpaceRepair; |
|
|
|
|
|
use App\Models\ParkingSpaceType; |
|
|
|
|
|
use App\Models\ParkingSpaceTypeAttr; |
|
|
use App\Services\ApiResponseService; |
|
|
use App\Services\ApiResponseService; |
|
|
|
|
|
use App\Services\OperationLogService; |
|
|
use App\Services\ParkingSpaceRepairService; |
|
|
use App\Services\ParkingSpaceRepairService; |
|
|
|
|
|
use App\Services\ParkingSpaceTypeService; |
|
|
use Exception; |
|
|
use Exception; |
|
|
use Illuminate\Http\JsonResponse; |
|
|
use Illuminate\Http\JsonResponse; |
|
|
use Illuminate\Http\Request; |
|
|
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') |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|