You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

225 lines
7.9 KiB

  1. <?php
  2. //所有的线路数组
  3. $line = array();
  4. //所有的票种数组
  5. $ticket = array();
  6. //所有线路-票种数组
  7. $line_ticket = array();
  8. //地点,站点数组
  9. $area_id = array();
  10. $area_name = array();
  11. $res_id = array();
  12. $res_name = array();
  13. //线路-属性数组
  14. $line_property = array();
  15. //线路id数组
  16. $line_id = array();
  17. //线路属性数组
  18. $dict_type = array(
  19. 112 => 'start_res',
  20. 113 => 'end_res',
  21. 125 => 'start_area',
  22. 126 => 'end_area',
  23. 124 => 'line_no',
  24. 285 => 'is_fx');
  25. //票种属性属性数组
  26. $ticket_mark = array(
  27. 0 => 'go',
  28. 1 => 'go',
  29. 2 => 'back',
  30. 3 => 'back'
  31. );
  32. //辅助数组
  33. $line_nav = array();
  34. $final_nav = array();
  35. //终极数组
  36. $final = array();
  37. $sql = "SELECT
  38. a.prod_id,
  39. a.prod_name,
  40. a.bus_type,
  41. b.type_id,
  42. b.property
  43. FROM
  44. opera_product AS a,
  45. opera_product_property AS b
  46. WHERE
  47. a.prod_id = b.prod_id
  48. AND a.prod_type = 81
  49. AND a.is_onsale = 1
  50. AND a.cancel_flag = 0
  51. GROUP BY
  52. a.prod_id,
  53. b.type_id";
  54. $result=$pdo->query($sql);
  55. $line = $result->fetchAll(PDO::FETCH_ASSOC);
  56. writeLog($sql);
  57. foreach($line as $line_info){
  58. $line_id[$line_info['prod_id']] = $line_info['prod_id'];
  59. if(array_key_exists($line_info['type_id'],$dict_type)){
  60. $line_property[$line_info['prod_id']]['prod_name'] = $line_info['prod_name'];
  61. 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'])){
  62. $line_property[$line_info['prod_id']]['prod_id'] = $line_info['prod_id'];
  63. $line_property[$line_info['prod_id']]['prod_name'] = $line_info['prod_name'];
  64. $line_property[$line_info['prod_id']]['bus_type'] = $line_info['bus_type'];
  65. }
  66. $line_property[$line_info['prod_id']][$dict_type[$line_info['type_id']]] = $line_info['property'];
  67. }
  68. }
  69. //print_r(implode(",",$line_id));
  70. $sql = "SELECT
  71. a.prod_id,
  72. a.ticket_mark,
  73. a.parent_id,
  74. b.type_id,
  75. b.property,
  76. c.prod_price,
  77. c.cus_price
  78. FROM
  79. opera_product AS a,
  80. opera_product_property AS b,
  81. opera_product_price AS c
  82. WHERE
  83. a.prod_id = b.prod_id
  84. AND a.prod_id = c.prod_id
  85. AND a.prod_type = 82
  86. AND a.is_onsale = 1
  87. AND a.cancel_flag = 0
  88. AND c.cancel_flag = 0
  89. and a.parent_id in (" . implode(",",$line_id) . ")
  90. GROUP BY
  91. a.prod_id,
  92. b.type_id";
  93. $result=$pdo->query($sql);
  94. $ticket = $result->fetchAll(PDO::FETCH_ASSOC);
  95. writeLog($sql);
  96. foreach($ticket as $ticket_info){
  97. if(array_key_exists($ticket_info['type_id'],$dict_type)){
  98. 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'])){
  99. $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_id'] = $ticket_info['prod_id'];
  100. $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['ticket_mark'] = $ticket_info['ticket_mark'];
  101. $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['prod_price'] = $ticket_info['prod_price'];
  102. $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']]['cus_price'] = $ticket_info['cus_price'];
  103. }
  104. $line_ticket[$ticket_info['parent_id']][$ticket_info['prod_id']][$dict_type[$ticket_info['type_id']]] = $ticket_info['property'];
  105. }
  106. }
  107. // echo count($line_property);
  108. // echo count($line_ticket);
  109. //print_r($line_property);
  110. foreach($line_property as $line_info){
  111. if(!isset($area_id[$line_info['start_area']])){
  112. $area_id[$line_info['start_area']] = $line_info['start_area'];
  113. }
  114. if(!isset($area_id[$line_info['end_area']])){
  115. $area_id[$line_info['end_area']] = $line_info['end_area'];
  116. }
  117. }
  118. //print_r($line_ticket);
  119. foreach($line_ticket as $line_info){
  120. foreach($line_info as $ticket_info){
  121. if(!isset($area_id[$ticket_info['start_area']])){
  122. $area_id[$ticket_info['start_area']] = $ticket_info['start_area'];
  123. }
  124. if(!isset($area_id[$ticket_info['end_area']])){
  125. $area_id[$ticket_info['end_area']] = $ticket_info['end_area'];
  126. }
  127. if(!isset($area_id[$ticket_info['start_res']])){
  128. $res_id[$ticket_info['start_res']] = $ticket_info['start_res'];
  129. }
  130. if(!isset($area_id[$ticket_info['end_res']])){
  131. $res_id[$ticket_info['end_res']] = $ticket_info['end_res'];
  132. }
  133. }
  134. }
  135. ksort($area_id);
  136. ksort($res_id);
  137. $sql = "SELECT
  138. id,
  139. area_name
  140. FROM
  141. base_area
  142. WHERE
  143. id IN (" . implode(",",$area_id) . ")";
  144. $result=$pdo->query($sql);
  145. $area_id = $result->fetchAll(PDO::FETCH_ASSOC);
  146. $sql = "SELECT
  147. res_id,
  148. res_name
  149. FROM
  150. base_resource
  151. WHERE
  152. id IN (" . implode(",",$res_id) . ")";
  153. $result=$pdo->query($sql);
  154. $res_id = $result->fetchAll(PDO::FETCH_ASSOC);
  155. //print_r($area_id);print_r($res_id);
  156. foreach($area_id as $area_info){
  157. $area_name[$area_info['id']] = $area_info['area_name'];
  158. }
  159. foreach($res_id as $res_info){
  160. $res_name[$res_info['res_id']] = $res_info['res_name'];
  161. }
  162. //print_r($area_name);print_r($res_name);
  163. //print_r($line_ticket);print_r($line_property);
  164. foreach($line_property as $key => $value){
  165. $value['start_area_name'] = $area_name[$value['start_area']];
  166. $value['end_area_name'] = $area_name[$value['end_area']];
  167. if(isset($line_ticket[$key])){
  168. $line_nav = $line_ticket[$key];
  169. $final_nav = array();
  170. foreach($line_nav as $nav_k => $nav_v){
  171. $nav_v['start_area_name'] = $area_name[$nav_v['start_area']];
  172. $nav_v['end_area_name'] = $area_name[$nav_v['end_area']];
  173. $nav_v['start_res_name'] = $res_name[$nav_v['start_res']];
  174. $nav_v['end_res_name'] = $res_name[$nav_v['end_res']];
  175. //$final_ticket_key = $nav_v['prod_id'].'-'.$nav_v['start_area'].'-'.$nav_v['start_res'].'-'.$nav_v['end_area'].'-'.$nav_v['end_res'];
  176. //$final_nav[$ticket_mark[$nav_v['ticket_mark']]][$final_ticket_key] = $nav_v;
  177. $final_nav[$ticket_mark[$nav_v['ticket_mark']]][$nav_k] = $nav_v;
  178. }
  179. }
  180. if($value['bus_type'] == 0 || $value['bus_type'] == 255){
  181. $final[255][$key]['line_info'] = $value;
  182. $final[255][$key]['ticket_info'] = $final_nav;
  183. }else{
  184. $final[256][$key]['line_info'] = $value;
  185. $final[256][$key]['ticket_info'] = $final_nav;
  186. }
  187. }
  188. $line_final = $final;
  189. //echo count($final[255]);echo count($final[256]);
  190. ?>