getDateFromRange($starttime,$endtime); //获取指定日期之间的日期 $times = $this -> getDate($starttime,$endtime); $data['times'] = $weeks; $start = ' 00:00:00'; $end = ' 23:59:59'; for($i=0;$i= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end)); $event = get_var($sql_event); $data['event'][] = $event; //能耗统计 $data['plc'][] = 0; } break; case 'month': // 获取当前日期 $endtime = date('Y-m-d'); $starttime = date("Y-m-01"); //获取指定日期之间的日期 $times = $this -> getDate($starttime,$endtime); $data['times'] = $times; $start = ' 00:00:00'; $end = ' 23:59:59'; for($i=0;$i= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end)); $event = get_var($sql_event); $data['event'][] = $event; //能耗统计 $data['plc'][] = 0; } break; case 'year': // 获取当前日期 $endtime = date('Y-01-01'); $starttime = date("Y-12-31"); $yearmonth = $this -> getYearDate(); //获取指定日期之间的日期 // $times = $this -> getYearDate($starttime,$endtime); $data['times'] = $yearmonth; $start = ' 00:00:00'; $end = ' 23:59:59'; for($k=0;$k<12;$k++){ $firstday = date($yearmonth[$k].'-01', strtotime($date)); $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day")); $created_at_start = $firstday.$start; $created_at_end = $lastday.$end; //调控次数 $sql_event = prepare("select (main_sewage_pump_count+standby_sewage_pump_count+main_rain_pump_count+gate_up_count+gate_down_count) as control_count from data where device_id = (select id from device where terminal_id = ?i limit 1) and created_at >= ?s and created_at <= ?s order by id desc limit 1",array($id,$created_at_start,$created_at_end)); $event = get_var($sql_event); $data['event'][] = $event; //能耗统计 $data['plc'][] = 0; } break; } $data['time'] = $time; return self::send_resu($data); } //获取指定日期是星期几 public function getDateFromRange($startdate, $enddate){ $stimestamp = strtotime($startdate); $etimestamp = strtotime($enddate); $days = ($etimestamp-$stimestamp)/86400+1;//计算日期段内有多少天 //保存每天日期 $weekArray = array("日","一","二","三","四","五","六"); for($i = 0; $i < $days; $i++){ // $currentDate = date('m月d', $stimestamp+(86400*$i)); $currentDate_1 = date('Y-m-d', $stimestamp+(86400*$i)); $currentWeek = "周".$weekArray[date("w",strtotime($currentDate_1))]; $date[] = $currentWeek; } return $date; } // 获取指定日期之间的所有日期 public function getDate($startdate,$enddate){ $stimestamp = strtotime($startdate); $etimestamp = strtotime($enddate); // 计算日期段内有多少天 $days = ($etimestamp-$stimestamp)/86400+1; // 保存每天日期 $date = array(); for($i=0; $i<$days; $i++){ $date[] = date('Y-m-d', $stimestamp+(86400*$i)); } return $date; } /** * 获取本年的12个月 */ public function getYearDate() { for ($i=1; $i < 13; $i++) { $month = date("Y",time())."-".$i; $array[] = date("Y-m",strtotime($month)); } return $array; } }