= '" . $conditions['activate_start_time'] . "' "; } if($conditions['activate_end_time']){ $where .= "AND c.service_end_at <= '" . $conditions['activate_end_time'] . "' "; } if($conditions['renewal_start_time']){ $where .= "AND p.service_start_at >= '" . $conditions['renewal_start_time'] . "' "; } if($conditions['renewal_start_time']){ $where .= "AND p.service_start_at >= '" . $conditions['renewal_start_time'] . "' "; } $sql = $sql . $where . $group; $data = DB::select($sql); if(!$data){ return []; } foreach ($data as &$item) { $item = (array)$item; $item['company_name'] = CompanyService::load($item['company_id'])['name']; $item['ratio'] = $item['activates'] == 0 ? 0 : $item['renewals']/$item['activates']; $item['ratio'] = sprintf('%.02f', $item['ratio']); } return $data; } }