1,按日查询
public static function getOrderDaysListByUserId($id, $limit, $offset) { $sql = "SELECT FROM_UNIXTIME(`created`, '%Y-%m-%d') as `days`, "; $sql .= "count(*) as day_num "; $sql .= "FROM `serve_order` `order` "; $sql .= "WHERE `id`=" . $id . " "; $sql .= "AND `status`=" . $search['status'] . " "; $sql .= "GROUP BY `days` "; $sql .= "ORDER BY `days` DESC "; // $sql .= "LIMIT {$offset}, {$limit}"; $data = System_Model_ServeOrder::dataAccess() ->nativeSql($sql, array()); if (empty($data)) { return array(); } return $data; }
2.按月查询
public static function getOrderMonthsListByUserId($search, $limit, $offset) { $sql = "SELECT FROM_UNIXTIME(`created`, '%Y-%m') as `months`, "; $sql .= "count(*) as month_num "; $sql .= "FROM `serve_order` `order` "; $sql .= "WHERE `id`=" . $search['id'] . " "; $sql .= "AND `status`=" . $search['status'] . " "; $sql .= "GROUP BY `months` "; $sql .= "ORDER BY `months` DESC "; // $sql .= "LIMIT {$offset}, {$limit}"; $data = System_Model_ServeOrder::dataAccess() ->nativeSql($sql, array()); if (empty($data)) { return array(); } return $data; }