Browse Source

停车场占用率图标排序优化3

master
wanghongjun 4 hours ago
parent
commit
139d4282dd
  1. 16
      app/Http/Controllers/Admin/OccupancyRateController.php
  2. 12
      app/Services/ParkingOccupancyRateService.php

16
app/Http/Controllers/Admin/OccupancyRateController.php

@ -94,12 +94,17 @@ class OccupancyRateController extends BaseController
$list = $query->groupBy(['time', 'time_type'])->select( $list = $query->groupBy(['time', 'time_type'])->select(
['time', 'time_type'] ['time', 'time_type']
)->get(); )->get();
$ParkingSpaceType = array_column( $ParkingSpaceType = $this->service->getColorSpaceTypeList();
ParkingSpaceType::getData(), $spaceTypeName = array_column(
$ParkingSpaceType,
'name', 'name',
'id' 'id'
); );
$colorArr = $this->service->colorArr; $spaceTypeColor = array_column(
$ParkingSpaceType,
'color',
'id'
);
foreach ($list as $index => &$item) { foreach ($list as $index => &$item) {
$time = $item['time']; $time = $item['time'];
$time_type = $item['time_type']; $time_type = $item['time_type'];
@ -119,11 +124,12 @@ class OccupancyRateController extends BaseController
)->get()->toArray(); )->get()->toArray();
foreach ($space_type_list as $key => $value) { foreach ($space_type_list as $key => $value) {
$space_type_list[$key]['space_type_name'] $space_type_list[$key]['space_type_name']
= $ParkingSpaceType[$value['space_type_id']]; = $spaceTypeName[$value['space_type_id']];
$space_type_list[$key]['color']
= $spaceTypeColor[$value['space_type_id']];
unset($space_type_list[$key]['space_type_id']); unset($space_type_list[$key]['space_type_id']);
} }
$item['space_type_list'] = $space_type_list; $item['space_type_list'] = $space_type_list;
$item['color'] = $colorArr[$index];
unset($item['time_type'], $item['floor_id']); unset($item['time_type'], $item['floor_id']);
} }
return $this->responseService->success($list); return $this->responseService->success($list);

12
app/Services/ParkingOccupancyRateService.php

@ -5,17 +5,27 @@ namespace App\Services;
use App\Models\AdminFloor; use App\Models\AdminFloor;
use App\Models\ParkingOccupancyRate; use App\Models\ParkingOccupancyRate;
use App\Models\ParkingOccupancyRateInfo; use App\Models\ParkingOccupancyRateInfo;
use App\Models\ParkingSpaceType;
class ParkingOccupancyRateService extends BaseService class ParkingOccupancyRateService extends BaseService
{ {
protected string $menuTitle = 'occupancy_rate'; protected string $menuTitle = 'occupancy_rate';
public array $colorArr = [ protected array $colorArr = [
'#73c0de', '#fac858', '#5470c6', '#67c23a', '#ff0000', '#349c32', '#73c0de', '#fac858', '#5470c6', '#67c23a', '#ff0000', '#349c32',
'#ffff00', '#0000ff', '#00ffff', '#ca00c9', '#ce4478', '#31dc21', '#ffff00', '#0000ff', '#00ffff', '#ca00c9', '#ce4478', '#31dc21',
'#f9d1c1', '#5e4439', '#21375f', '#63beef', '#60c6ad', '#a7a7a7', '#f9d1c1', '#5e4439', '#21375f', '#63beef', '#60c6ad', '#a7a7a7',
]; ];
public function getColorSpaceTypeList()
{
$ParkingSpaceType = ParkingSpaceType::getData();
foreach ($ParkingSpaceType as $key => &$item) {
$item['color'] = $this->colorArr[$key];
}
return $ParkingSpaceType;
}
public static function createData( public static function createData(
$space_type_id, $space_type_id,
$floor_id, $floor_id,

Loading…
Cancel
Save