mirror of
https://gitee.com/ShopeX/OMS
synced 2026-03-23 02:45:33 +08:00
69 lines
2.8 KiB
PHP
69 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Copyright 2012-2026 ShopeX (https://www.shopex.cn)
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
|
|
class eccommon_analysis_base
|
|
{
|
|
/**
|
|
* fetch_graph_data
|
|
* @param mixed $params 参数
|
|
* @return mixed 返回值
|
|
*/
|
|
public function fetch_graph_data($params)
|
|
{
|
|
$analysis_info = app::get('eccommon')->model('analysis')->select()->columns('*')->where('service = ?', $params['service'])->instance()->fetch_row();
|
|
if(empty($analysis_info)) return array('categories'=>array(), 'data'=>array());
|
|
$obj = app::get('eccommon')->model('analysis_logs')->select()->columns('target, flag, value, time')->where('analysis_id = ?', $analysis_info['id']);
|
|
$obj->where('target = ?', $params['target']);
|
|
$obj->where('time >= ?', strtotime(sprintf('%s 00:00:00', $params['time_from'])));
|
|
$obj->where('time <= ?', strtotime(sprintf('%s 23:59:59', $params['time_to'])));
|
|
if(isset($this->_params['type'])) $obj->where('type = ?', $params['type']);
|
|
$rows = $obj->instance()->fetch_all();
|
|
$time_range = [];
|
|
for($i=strtotime($params['time_from']); $i<=strtotime($params['time_to']); $i+=($analysis_info['interval'] == 'day')?86400:3600){
|
|
$time_range[] = ($analysis_info['interval'] == 'day') ? date("Y-m-d", $i) : date("Y-m-d H", $i);
|
|
}
|
|
|
|
$logs_options = kernel::single($params['service'])->logs_options;
|
|
$target = $logs_options[$params['target']];
|
|
if(is_array($target['flag']) && count($target['flag'])){
|
|
foreach($target['flag'] AS $k=>$v){
|
|
foreach($time_range AS $date){
|
|
$data[$v][$date] = 0;
|
|
}
|
|
}
|
|
}else{
|
|
foreach($time_range AS $date){
|
|
$data['全部'][$date] = 0;
|
|
}
|
|
}
|
|
|
|
foreach($rows AS $row){
|
|
$date = ($analysis_info['interval'] == 'day') ? date("Y-m-d", $row['time']) : date("Y-m-d H", $row['time']);
|
|
$flag_name = $target['flag'][$row['flag']];
|
|
if($flag_name){
|
|
$data[$flag_name][$date] = $row['value'];
|
|
}else{
|
|
$data['全部'][$date] = $row['value'];
|
|
}
|
|
}
|
|
|
|
return array('categories'=>$time_range, 'data'=>$data);
|
|
}//End Function
|
|
|
|
}//End Class
|