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.
 
 
 
 
 

293 lines
8.6 KiB

  1. <?php
  2. date_default_timezone_set('GMT');
  3. $run_id = trim($_POST['run_id']);
  4. $ticket_id= trim($_POST['ticket_id']);
  5. $price_type = 1;
  6. //$line_id = 152248;
  7. $line_id = '';//线路ID
  8. $run_date = '';//出发时间
  9. $price_name = '';//分销价或零售价
  10. //巴士类型
  11. $bus_type = '';
  12. $ticket_type = '';
  13. //班次站点信息
  14. $run_station = array();
  15. //顺序站点
  16. $res_station_seq = array();
  17. //余票信息
  18. $ticket_over = array();
  19. $ticket_over_array = array();
  20. $ticket_over_id = array();
  21. //线路可选的票种数组
  22. $line_ticket_id = array();
  23. $line_ticket_info = array();
  24. //票种信息
  25. $ticket_info = array();
  26. $ticket = array();
  27. //上车站数组
  28. $start_res_array = array();
  29. //下车站数组
  30. $end_res_array = array();
  31. //站点数组
  32. $res_array = array();
  33. $res_id_array = array();
  34. //终极数组
  35. $final = array();
  36. //上车站-下车站信息
  37. $start_area = '';
  38. $start_res = '';
  39. $end_area = '';
  40. $end_res = '';
  41. if($price_type ==1){
  42. $price_name = "cus_price";
  43. }else{
  44. $price_name = "prod_price";
  45. }
  46. $sql = "select ticket_mark from opera_product where prod_id = " . $ticket_id;
  47. $result=$pdo->query($sql);
  48. $ticket_type = $result->fetchAll(PDO::FETCH_ASSOC);
  49. writeLog($sql);
  50. if($ticket_type[0]['ticket_mark'] == 0 || $ticket_type[0]['ticket_mark'] == 1){
  51. $ticket_type = 'go';
  52. }else{
  53. $ticket_type = 'back';
  54. }
  55. $sql = "SELECT
  56. a.run_id,
  57. a.run_status,
  58. a.run_date,
  59. a.prod_id,
  60. b.start_time,
  61. b.station_order_id,
  62. b.station_res_id,
  63. b.station_inout_type,
  64. b.area_id
  65. FROM
  66. run_main AS a,
  67. run_station AS b
  68. WHERE
  69. a.run_id = b.run_id
  70. AND a.run_id = " . $run_id . "
  71. AND a.run_status = 138
  72. ORDER BY
  73. a.run_id,
  74. b.station_order_id ";
  75. $result=$pdo->query($sql);
  76. $run_station = $result->fetchAll(PDO::FETCH_ASSOC);
  77. writeLog($sql);
  78. $run_date = $run_station[0]['run_date'];
  79. $line_id = $run_station[0]['prod_id'];
  80. $ticket_info = $line_array[$line_id]['ticket_info'][$ticket_type][$ticket_id];
  81. $start_area = $ticket_info['start_area'];
  82. $start_res = $ticket_info['start_res'];
  83. $end_area = $ticket_info['end_area'];
  84. $end_res = $ticket_info['end_res'];
  85. $bus_type = $line_array[$line_id]['line_info']['bus_type'];
  86. if($bus_type == 0 || $bus_type == 255 ){
  87. $bus_type = 255;
  88. }else{
  89. $bus_type = 256;
  90. }
  91. if($ticket_type == 'back'){
  92. foreach($line_array[$line_id]['ticket_info']['go'] as $k => $v){
  93. if($v['start_area'] == $start_area && $v['start_res'] == $start_res && $v['end_area'] == $end_area && $v['end_res'] == $end_res){
  94. $ticket_info_go = $v;
  95. }
  96. }
  97. }
  98. $sql = "SELECT
  99. run_id,
  100. res_id,
  101. seq_id,
  102. prod_id,
  103. total_count,
  104. saled_count
  105. FROM
  106. run_stock
  107. WHERE
  108. run_id = " . $run_id . "
  109. AND seat_type = 72
  110. ORDER BY
  111. run_id ASC,
  112. seq_id ASC";
  113. $result=$pdo->query($sql);
  114. $ticket_over_id = $result->fetchAll(PDO::FETCH_ASSOC);
  115. writeLog($sql);
  116. foreach($ticket_over_id as $k => $v){
  117. $ticket_over[$v['res_id']] = $v['total_count'] - $v['saled_count'];
  118. }
  119. $sql = "select prod_id from run_prod where run_id = " . $run_id;
  120. $result=$pdo->query($sql);
  121. $line_ticket_id = $result->fetchAll(PDO::FETCH_ASSOC);
  122. writeLog($sql);
  123. foreach($line_ticket_id as $k => $v){
  124. $line_ticket_info[$v['prod_id']] = $v['prod_id'];
  125. }
  126. foreach($line_array[$line_id]['ticket_info']['go'] as $k => $v){
  127. if(in_array($k,$line_ticket_info) && $v['start_area'] == $start_area && $v['end_area'] == $end_area){
  128. $start_res_array[$v['start_res']]['res_id'] = $v['start_res'];
  129. $start_res_array[$v['start_res']]['res_name'] = $v['start_res_name'];
  130. $end_res_array[$v['end_res']]['res_id'] = $v['end_res'];
  131. $end_res_array[$v['end_res']]['res_name'] = $v['end_res_name'];
  132. }else{
  133. unset($line_array[$line_id]['ticket_info']['go'][$k]);
  134. }
  135. }
  136. foreach($run_station as $k => $v){
  137. $res_id_array[$v['station_res_id']] = $v['station_res_id'];
  138. $res_station_seq[$v['station_res_id']] = $v['station_order_id'];
  139. if(isset($start_res_array[$v['station_res_id']]) && ($v['station_inout_type'] == 108 || $v['station_inout_type'] == 109)){
  140. $start_res_array[$v['station_res_id']]['start_time'] = $v['start_time'];
  141. }elseif(isset($start_res_array[$v['station_res_id']])){
  142. unset($start_res_array[$v['station_res_id']]);
  143. }
  144. if(isset($end_res_array[$v['station_res_id']]) && ($v['station_inout_type'] == 110 || $v['station_inout_type'] == 109)){
  145. $end_res_array[$v['station_res_id']]['start_time'] = $v['start_time'];
  146. }elseif(isset($end_res_array[$v['station_res_id']])){
  147. unset($end_res_array[$v['station_res_id']]);
  148. }
  149. }
  150. $sql = "SELECT
  151. res_id,
  152. res_name
  153. FROM
  154. base_resource
  155. WHERE
  156. id IN (" . implode(",",$res_id_array) . ")";
  157. $result=$pdo->query($sql);
  158. $res_id_array = $result->fetchAll(PDO::FETCH_ASSOC);
  159. writeLog($sql);
  160. foreach($res_id_array as $k => $v){
  161. $res_array1[$res_station_seq[$v['res_id']]]['res_id'] = $v['res_id'];
  162. $res_array1[$res_station_seq[$v['res_id']]]['res_name'] = $v['res_name'];
  163. }
  164. ksort($res_array1);
  165. foreach($res_array1 as $k => $v){
  166. $res_array[$v['res_id']] = $v['res_name'];
  167. }
  168. //echo $run_date.$line_id;
  169. foreach($start_res_array as $k => $v){
  170. $start_res_array[$k]['res_name'] = $res_array[$k];
  171. }
  172. foreach($end_res_array as $k => $v){
  173. $end_res_array[$k]['res_name'] = $res_array[$k];
  174. }
  175. //将基本数据放入数组中
  176. $final['run_date'] = $run_date;
  177. $final['run_id'] = $run_id;
  178. $final['line_id'] = $line_id;
  179. $final['bus_type'] = $bus_type;
  180. $final['start_area_id'] = $start_area;
  181. $final['start_area_name'] = $ticket_info['start_area_name'];
  182. $final['start_res_id'] = $start_res;
  183. $final['start_res_name'] = $ticket_info['start_res_name'];
  184. $final['end_area_id'] = $end_area;
  185. $final['end_area_name'] = $ticket_info['end_area_name'];
  186. $final['end_res_id'] = $end_res;
  187. $final['end_res_name'] = $ticket_info['end_res_name'];
  188. $final['start_time'] = $start_res_array[$final['start_res_id']]['start_time'];
  189. $final['end_time'] = $end_res_array[$final['end_res_id']]['start_time'];
  190. $final['start_res_array']['area_name'] = $final['start_area_name'];
  191. $final['start_res_array']['station'] = array_merge($start_res_array);
  192. $final['end_res_array']['area_name'] = $final['end_area_name'];
  193. $final['end_res_array']['station'] = array_merge($end_res_array);
  194. //print_r($ticket_go);print_r($ticket_back);
  195. $tick_over_status = 0;
  196. foreach($ticket_over as $k => $v){
  197. if($k == $final['end_res_id']){
  198. break;
  199. }
  200. if($k == $final['start_res_id'] || $tick_over_status > 0){
  201. $ticket_over_array[] = $v;
  202. $tick_over_status++;
  203. }
  204. }
  205. asort($ticket_over_array);
  206. $ticket_over_array = array_values($ticket_over_array);
  207. $ticket['ticket_id'] = $ticket_id;
  208. $ticket['ticket_type'] = $ticket_type;
  209. $setcookie_go = $_COOKIE['go_price_go'];
  210. $setcookie_back = $_COOKIE['go_price_back'];
  211. $ticket['go_price'] = (string)$ticket_info_go[$price_name];
  212. if($ticket_type == 'back'){
  213. $ticket['price'] = (string)(ceil($ticket_info[$price_name]+$setcookie_back-$setcookie_go));
  214. $ticket['discount_price'] = (string)(ceil($setcookie_go-$ticket['price']));
  215. }else{
  216. $ticket['discount_price'] = '0';
  217. $ticket['price'] = $ticket_info[$price_name];
  218. }
  219. $ticket['ticket_over'] = (string)$ticket_over_array[0];
  220. $final['ticket'] = $ticket;
  221. $final['ticket']['site'] = "普通座";
  222. $final['ticket']['run_type'] = "往返";
  223. $json = array();
  224. $json['code'] = '0';
  225. $json['info'] = "返回数据成功";
  226. $json['list'] = $final;
  227. echo json_encode($json);
  228. ?>