'start_res', 113 => 'end_res', 125 => 'start_area', 126 => 'end_area', 124 => 'line_no', 285 => 'is_fx'); //票种属性属性数组 $ticket_mark = array( 0 => 'go', 1 => 'go', 2 => 'back', 3 => 'back' ); //辅助数组 $line_nav = array(); $final_nav = array(); //终极数组 $final = array(); $sql = "SELECT a.prod_id, a.prod_name, a.bus_type, b.type_id, b.property FROM opera_product AS a, opera_product_property AS b WHERE a.prod_id = b.prod_id AND a.prod_type = 81 AND a.is_onsale = 1 AND a.cancel_flag = 0 GROUP BY a.prod_id, b.type_id"; $result=$pdo->query($sql); $line = $result->fetchAll(PDO::FETCH_ASSOC); writeLog($sql); foreach($line as $line_info){ $line_id[$line_info['prod_id']] = $line_info['prod_id']; if(array_key_exists($line_info['type_id'],$dict_type)){ $line_property[$line_info['prod_id']]['prod_name'] = $line_info['prod_name']; if(!isset($line_property[$line_info['prod_id']]['prod_id']) || !isset($line_property[$line_info['prod_id']]['prod_name']) || !isset($line_property[$line_info['prod_id']]['bus_type'])){ $line_property[$line_info['prod_id']]['prod_id'] = $line_info['prod_id']; $line_property[$line_info['prod_id']]['prod_name'] = $line_info['prod_name']; $line_property[$line_info['prod_id']]['bus_type'] = $line_info['bus_type']; } $line_property[$line_info['prod_id']][$dict_type[$line_info['type_id']]] = $line_info['property']; } } //print_r(implode(",",$line_id)); $sql = "SELECT a.prod_id, a.ticket_mark, a.parent_id, b.type_id, b.property, c.prod_price, c.cus_price FROM opera_product AS a, opera_product_property AS b, opera_product_price AS c WHERE a.prod_id = b.prod_id AND a.prod_id = c.prod_id AND a.prod_type = 82 AND a.is_onsale = 1 AND a.cancel_flag = 0 AND c.cancel_flag = 0 and a.parent_id in (" . implode(",",$line_id) . ") GROUP BY a.prod_id, b.type_id"; $result=$pdo->query($sql); $ticket = $result->fetchAll(PDO::FETCH_ASSOC); writeLog($sql); foreach($ticket as $ticket_info){ if(array_key_exists($ticket_info['type_id'],$dict_type)){ if(!isset($line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_id']) || !isset($line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_price']) || !isset($line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['cus_price']) || !isset($line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['ticket_mark'])){ $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_id'] = $ticket_info['prod_id']; $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['ticket_mark'] = $ticket_info['ticket_mark']; $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_price'] = $ticket_info['prod_price']; $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['cus_price'] = $ticket_info['cus_price']; } $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']][$dict_type[$ticket_info['type_id']]] = $ticket_info['property']; } } // echo count($line_property); // echo count($line_ticket); //print_r($line_property); foreach($line_property as $line_info){ if(!isset($area_id[$line_info['start_area']])){ $area_id[$line_info['start_area']] = $line_info['start_area']; } if(!isset($area_id[$line_info['end_area']])){ $area_id[$line_info['end_area']] = $line_info['end_area']; } } //print_r($line_ticket); foreach($line_ticket as $line_info){ foreach($line_info as $ticket_info){ if(!isset($area_id[$ticket_info['start_area']])){ $area_id[$ticket_info['start_area']] = $ticket_info['start_area']; } if(!isset($area_id[$ticket_info['end_area']])){ $area_id[$ticket_info['end_area']] = $ticket_info['end_area']; } if(!isset($area_id[$ticket_info['start_res']])){ $res_id[$ticket_info['start_res']] = $ticket_info['start_res']; } if(!isset($area_id[$ticket_info['end_res']])){ $res_id[$ticket_info['end_res']] = $ticket_info['end_res']; } } } ksort($area_id); ksort($res_id); $sql = "SELECT id, area_name FROM base_area WHERE id IN (" . implode(",",$area_id) . ")"; $result=$pdo->query($sql); $area_id = $result->fetchAll(PDO::FETCH_ASSOC); $sql = "SELECT res_id, res_name FROM base_resource WHERE id IN (" . implode(",",$res_id) . ")"; $result=$pdo->query($sql); $res_id = $result->fetchAll(PDO::FETCH_ASSOC); //print_r($area_id);print_r($res_id); foreach($area_id as $area_info){ $area_name[$area_info['id']] = $area_info['area_name']; } foreach($res_id as $res_info){ $res_name[$res_info['res_id']] = $res_info['res_name']; } //print_r($area_name);print_r($res_name); //print_r($line_ticket);print_r($line_property); foreach($line_property as $key => $value){ $value['start_area_name'] = $area_name[$value['start_area']]; $value['end_area_name'] = $area_name[$value['end_area']]; if(isset($line_ticket[$key])){ $line_nav = $line_ticket[$key]; $final_nav = array(); foreach($line_nav as $nav_k => $nav_v){ $nav_v['start_area_name'] = $area_name[$nav_v['start_area']]; $nav_v['end_area_name'] = $area_name[$nav_v['end_area']]; $nav_v['start_res_name'] = $res_name[$nav_v['start_res']]; $nav_v['end_res_name'] = $res_name[$nav_v['end_res']]; //$final_ticket_key = $nav_v['prod_id'].'-'.$nav_v['start_area'].'-'.$nav_v['start_res'].'-'.$nav_v['end_area'].'-'.$nav_v['end_res']; //$final_nav[$ticket_mark[$nav_v['ticket_mark']]][$final_ticket_key] = $nav_v; $final_nav[$ticket_mark[$nav_v['ticket_mark']]][$nav_k] = $nav_v; } } if($value['bus_type'] == 0 || $value['bus_type'] == 255){ $final[255][$key]['line_info'] = $value; $final[255][$key]['ticket_info'] = $final_nav; }else{ $final[256][$key]['line_info'] = $value; $final[256][$key]['ticket_info'] = $final_nav; } } $line_final = $final; //echo count($final[255]);echo count($final[256]); ?>