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.
 
 
 
 

234 lines
8.2 KiB

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