| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 | <?phpif (!defined('BASEPATH'))exit('No direct script access allowed');include_once(FCPATH . 'application/models/Base_model.php');class Statistics_model extends Base_model {    protected $table = 'statistics';    public function __construct() {        parent::__construct();    }    public function get_data($ids, $date, $type){    	if (empty($ids)) return array();    	if (is_array($ids)) {    		$where = 'lampid in ('.implode(',', $ids).')';    	}else{    		$where = 'lampid = '.$ids;    	}    	if ($type == 'power') {    			$field = 't1.dayGeneration,t1.dayConsumption,t1.totalGeneration,t1.totalConsumption,t1.monthGeneration,t1.monthConsumption,t1.yearGeneration,t1.yearConsumption,t1.updatetime';            }elseif ($type == 'current') {            	$field = 't1.dayCharMaxCurr,t1.dayDischarMaxCurr,t1.monthCharMaxCurr,t1.monthDischarMaxCurr,t1.yearCharMaxCurr,t1.yearDischarMaxCurr,t1.updatetime';            }elseif ($type == 'temper') {            	$field = 't1.dayMinTemper,t1.dayMaxTemper,t1.monthMinTemper,t1.monthMaxTemper,t1.yearMinTemper,t1.yearMaxTemper,t1.updatetime';            }elseif ($type == 'capacity') {            	$field = 't1.dayCharMaxPower,t1.dayDischarMaxPower,t1.monthCharMaxPower,t1.monthDischarMaxPower,t1.yearCharMaxPower,t1.yearDischarMaxPower,t1.updatetime';            }else{            	$field = 't1.dayMinVoltage,t1.dayMaxVoltage,t1.monthMinVoltage,t1.monthMaxVoltage,t1.yearMinVoltage,t1.yearMaxVoltage,t1.updatetime';            }        $field .= ',t1.lampid';    	$sql = 'SELECT '.$field.' from new_statistics AS t1 JOIN (SELECT lampid,max(updatetime) as maxTime from new_statistics WHERE updatetime <= "'.$date.'" AND '.$where.' group by lampid) AS t2 on t1.lampid = t2.lampid AND t1.updatetime = t2.maxTime';    	$query = $this->db->query($sql);    	$temp = $query->result_array();    	$res = [];    	foreach ($temp as $v) {    		$res[$v['lampid']] = $v;    	}    	return $res;    }}
 |