where($where) ->when(isset($time['timeKey']), function ($query) use ($time, $str, $group) { $query->whereBetweenTime($group, $time['timeKey']['start_time'], $time['timeKey']['end_time']); if ($time['timeKey']['days'] == 1) { $timeUinx = "%H"; } elseif ($time['timeKey']['days'] == 30) { $timeUinx = "%Y-%m-%d"; } elseif ($time['timeKey']['days'] == 365) { $timeUinx = "%Y-%m"; } elseif ($time['timeKey']['days'] > 1 && $time['timeKey']['days'] < 30) { $timeUinx = "%Y-%m-%d"; } elseif ($time['timeKey']['days'] > 30 && $time['timeKey']['days'] < 365) { $timeUinx = "%Y-%m"; } else { $timeUinx = "%Y-%m"; } $query->field("$str as number,FROM_UNIXTIME($group, '$timeUinx') as time"); $query->group("FROM_UNIXTIME($group, '$timeUinx')"); }) ->order("$group ASC")->select()->toArray(); } }