&$item) { $item['color'] = $this->colorArr[$key]; } return $ParkingSpaceType; } public static function createData( $space_type_id, $floor_id, $time, $sum_count, $occupy_count, $time_type ) { $where = [ 'floor_id' => $floor_id, 'time' => $time, 'time_type' => $time_type ]; $id = ParkingOccupancyRate::query()->where($where)->value('id'); if (!$id) { $data = [ 'floor_id' => $floor_id, 'time' => $time, 'time_type' => $time_type, 'created_at' => date("Y-m-d H:i:s", time()), 'updated_at' => date("Y-m-d H:i:s", time()) ]; $model = ParkingOccupancyRate::query()->create($data); $id = $model->toArray()['id']; } $dataInfo = $whereInfo = [ 'occupancy_rate_id' => $id, 'space_type_id' => $space_type_id ]; if (ParkingOccupancyRateInfo::query()->where($whereInfo)->exists()) { return; } $dataInfo['sum_count'] = $sum_count; $dataInfo['occupy_count'] = $occupy_count; ParkingOccupancyRateInfo::query()->create($dataInfo); } public function queryList($param, $type_str = 'list') { $query = ParkingOccupancyRate::query(); $floor_id = ''; if (isset($param['floor_id']) && !empty($param['floor_id'])) { $floor_id = $param['floor_id']; $query->where('floor_id', $param['floor_id']); } if (isset($param['parking_id']) && !empty($param['parking_id']) && !$floor_id ) { $floor_ids = AdminFloor::getIdsParking($param['parking_id']); if ($floor_ids) { $query->whereIn('floor_id', $floor_ids); } } $start_time = $param['start_date'] ?? date("Y-m-d 00:00:00"); $end_time = $param['end_date'] ?? date("Y-m-d 23:59:59"); $start_date = date('Y-m-d', strtotime($start_time)); $end_date = date('Y-m-d', strtotime($end_time)); $time_type = 2; if ($start_date == $end_date) { $time_type = 1; } $query->where('time_type', $time_type); if ($start_time && strtotime($start_time)) { $start_time = date("Y-m-d H:i:s", strtotime($start_time)); if ($start_time) { $query->where('time', '>=', $start_time); } } if ($end_time && strtotime($end_time)) { $end_time = date("Y-m-d H:i:s", strtotime($end_time)); if ($end_time) { $query->where('time', '<=', $end_time); } } $direction = $type_str == 'list' ? 'DESC' : 'ASC'; $query->orderBy('time', $direction); return $query; } public function getItem($item, $parkingSpaceType) { $item['floor'] = AdminFloor::getName($item['floor_id']); if ($item['time_type'] == 1) { $format = 'Y-m-d H:i'; } else { $format = 'Y-m-d'; } $item['time'] = date($format, strtotime($item['time'])); foreach ($parkingSpaceType as $spaceType) { $type_id = $spaceType['id']; $key = 'type' . $type_id; $item[$key]['sum_count'] = 0; $item[$key]['occupy_count'] = 0; $res = ParkingOccupancyRateInfo::getTypeCount( $item['id'], $type_id ); if ($res) { $item[$key]['sum_count'] = $res['sum_count']; $item[$key]['occupy_count'] = $res['occupy_count']; } } unset($item['floor_id'], $item['time_type']); return $item; } }