= a.start_order_id and seq_id < a.end_order_id and seat_type = a.seat_type) as stock FROM ( SELECT DISTINCT m.run_id, p.line_id, m.run_date, r.start_station_area_id as start_area_id, r.end_station_area_id as end_area_id, r.seat_type, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id) as start_order_id, (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) as end_order_id, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as min_start_time, (SELECT max(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as max_start_time, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id ) as min_end_time, (SELECT max(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id ) as max_end_time, (SELECT min(cus_price) FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) as price, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as run_time FROM opera_line p, run_main m, run_prod r WHERE p.line_id = m.prod_id AND p.org_id ' . $siteContantsConfig['show_line_org'] . ' AND m.run_id = r.run_id AND p.line_id = r.parent_prod_id AND m.run_date = \'' . $run_date . '\' AND p.cancel_flag = 0 AND r.seat_type = 72 AND r.human_type in(0,159,334) AND r.start_station_area_id in(' . $start_area_id . ') AND r.end_station_area_id in(' . $end_area_id . ') AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1 ' . $sql_str . ' AND p.line_type in(255,256) AND (p.line_id < 451023 OR p.line_id > 451028) AND p.line_id not in(451188,451237,449887,451180) AND p.is_onsale = 1 AND p.if_disabled = 0 and m.run_status = 138 and m.run_date >= \'' . $now_date . '\' AND case p.sale_expired_type when 321 then if(date_add(date_add(m.run_date,interval -1 day), interval (substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute) > now(),0=0,0=1) when 322 then if(date_add(m.run_date, interval m.run_minutes -(substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute)>= now(),0=0,0=1) else 0=0 end GROUP BY m.run_id,r.start_station_area_id,r.end_station_area_id, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id), (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) ) as a GROUP BY a.run_id,a.start_area_id,a.end_area_id ORDER BY a.run_time'; $result = $this->fetchAll($sql); if ($result !== false) { return Util::returnArrSu('', $result); } else { return Util::returnArrEr('数据库错误'); } } /** * Function Description:获取带分页的班次列表 * Function Name: getPageRunsList * @param $run_date * @param $start_area_id * @param $end_area_id * @param $page_size * @param $current_page * * @return array * * @author 张帅 */ public function getPageRunsList($run_date, $start_area_id, $end_area_id, $page_size, $current_page) { $now_date = date('Y-m-d', time()); $start_row = ($current_page - 1) * $page_size; $siteContantsConfig = Util::getSiteContantsConfig(); $sql = '' . 'SELECT a.run_id, a.line_id, a.run_time, a.start_area_id, (select area_name from base_area where id = a.start_area_id LIMIT 1) as start_area_name, a.end_area_id, (select area_name from base_area where id = a.end_area_id LIMIT 1) as end_area_name, a.run_date, ((HOUR(max_end_time)*60+MINUTE(max_end_time))-(HOUR(min_start_time)*60+MINUTE(min_start_time))+(HOUR(min_end_time)*60+MINUTE(min_end_time))-(HOUR(max_start_time)*60+MINUTE(max_start_time)))/2 as total_time, min(a.price) as price, (select min(total_count-saled_count) from run_stock where run_id = a.run_id and cancel_flag = 0 and seq_id >= a.start_order_id and seq_id < a.end_order_id and seat_type = a.seat_type) as stock FROM ( SELECT DISTINCT m.run_id, p.line_id, m.run_date, m.run_time, r.start_station_area_id as start_area_id, r.end_station_area_id as end_area_id, r.seat_type, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id) as start_order_id, (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) as end_order_id, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as min_start_time, (SELECT max(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as max_start_time, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id ) as min_end_time, (SELECT max(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id ) as max_end_time, (SELECT min(cus_price) FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) as price FROM opera_line p, run_main m, run_prod r WHERE p.line_id = m.prod_id AND p.org_id ' . $siteContantsConfig['show_line_org'] . ' AND m.run_id = r.run_id AND p.line_id = r.parent_prod_id AND m.run_date = \'' . $run_date . '\' AND p.cancel_flag = 0 AND r.seat_type = 72 AND r.human_type in(0,159,334) AND r.start_station_area_id in(' . $start_area_id . ') AND r.end_station_area_id in(' . $end_area_id . ') AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1 AND p.line_type in(255,256) AND (p.line_id < 451023 OR p.line_id > 451028) AND p.line_id not in(451188,451237,449887,451180) AND p.is_onsale = 1 AND p.if_disabled = 0 and m.run_status = 138 and m.run_date >= \'' . $now_date . '\' AND case p.sale_expired_type when 321 then if(date_add(date_add(m.run_date,interval -1 day), interval (substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute) > now(),0=0,0=1) when 322 then if(date_add(m.run_date, interval m.run_minutes -(substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute)>= now(),0=0,0=1) else 0=0 end GROUP BY m.run_id,r.start_station_area_id,r.end_station_area_id, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id), (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) ) as a GROUP BY a.run_id,a.start_area_id,a.end_area_id ORDER BY a.run_time LIMIT ' . $start_row . ',' . $page_size; $result = $this->fetchAll($sql); if ($result === false) { return Util::returnArrEr('数据库错误'); } if (count($result) == 0) { $json['common_list'] = $result; $json['page']['page_size'] = $page_size; $json['page']['current_page'] = "0"; $json['page']['total_count'] = "0"; $json['page']['total_page'] = "0"; return Util::returnArrSu('', $json); } $count_sql = '' . 'SELECT a.run_id FROM ( SELECT DISTINCT m.run_id, r.start_station_area_id as start_area_id, r.end_station_area_id as end_area_id, r.seat_type, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id) as start_order_id, (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) as end_order_id, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as min_start_time, (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id ) as min_end_time FROM opera_line p, run_main m, run_prod r WHERE p.line_id = m.prod_id AND p.org_id ' . $siteContantsConfig['show_line_org'] . ' AND m.run_id = r.run_id AND p.line_id = r.parent_prod_id AND m.run_date = \'' . $run_date . '\' AND p.cancel_flag = 0 AND r.seat_type = 72 AND r.human_type in(0,159,334) AND r.start_station_area_id in(' . $start_area_id . ') AND r.end_station_area_id in(' . $end_area_id . ') AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1 AND (p.line_id < 451023 OR p.line_id > 451028 AND p.line_id not in(451188,451237,449887,451180) AND p.is_onsale = 1 AND p.if_disabled = 0 and m.run_status = 138 and m.run_date >= \'' . $now_date . '\' AND case p.sale_expired_type when 321 then if(date_add(date_add(m.run_date,interval -1 day), interval (substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute) > now(),0=0,0=1) when 322 then if(date_add(m.run_date, interval m.run_minutes -(substring_index(p.sale_expired_time,\':\',1)*60 + substring_index(p.sale_expired_time,\':\',-1)) minute)>= now(),0=0,0=1) else 0=0 end GROUP BY m.run_id,r.start_station_area_id,r.end_station_area_id, (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id), (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id) ) as a GROUP BY a.run_id,a.start_area_id,a.end_area_id'; $total_count = $this->fetchAll($count_sql); $total_count = count($total_count); $total_page = ceil($total_count / $page_size); $json['common_list'] = $result; $json['page']['page_size'] = $page_size; $json['page']['current_page'] = $current_page; $json['page']['total_count'] = $total_count; $json['page']['total_page'] = $total_page; return Util::returnArrSu('', $json); } }