select("*")->from($sqlName) ->where('cmd')->eq(6901) ->andWhere('zoneid')->eq($zoneid) ->andWhere('uid')->eq($uid) ->fetchAll(); $lastItem = null; $dic = new stdClass(); $list = array(); $index = 1; $num = 0; foreach ($arr as $item) { if ($lastItem != null) { $list[] = $lastItem; if (strtotime($item->ts) - strtotime($lastItem->ts) > 20 * 60) { $timeDic = new stdClass(); $timeDic->startTs = strtotime($list[0]->ts); $timeDic->endTs = strtotime($list[count($list) - 1]->ts); $timeDic->durationTs = strtotime($list[count($list) - 1]->ts) - strtotime($list[0]->ts); $dic->$index = $timeDic; $index += 1; $list = array(); } } $num+=1; $lastItem = $item; if(count($arr)==$num){ $list[] = $item; $timeDic = new stdClass(); $timeDic->startTs = strtotime($list[0]->ts); $timeDic->endTs = strtotime($list[count($list) - 1]->ts); $timeDic->durationTs = strtotime($list[count($list) - 1]->ts) - strtotime($list[0]->ts); $dic->$index = $timeDic; break; } } $result = new stdClass(); $result->data = $dic; echo Resp::ret($result);