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.
 
 
 
 
 
 

273 lines
16 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm OperaLine.php
  13. * Create By 2016/11/15 11:55 $
  14. */
  15. namespace Trip\Model;
  16. use Base\Tool\DbTable;
  17. use Util\Util\Util;
  18. class OperaLine extends DbTable
  19. {
  20. public $db = 'CST';
  21. public $tab = 'opera_line';
  22. /**
  23. * Function Description:获取不要分页的班次列表
  24. * Function Name: getRunsList
  25. * @param $run_date
  26. * @param $start_area_id
  27. * @param $end_area_id
  28. *
  29. * @return array
  30. *
  31. * @author 张帅
  32. */
  33. public function getRunsList($run_date, $start_area_id, $end_area_id)
  34. {
  35. $start_area_id_arr = explode(',', $start_area_id);
  36. $end_area_id_arr = explode(',', $end_area_id);
  37. $siteContantsConfig = Util::getSiteContantsConfig();
  38. if (count($start_area_id_arr) == 1 || count($end_area_id_arr) == 1) {
  39. $sql_str = '';
  40. } else {
  41. $sql_str = ' AND (r.start_station_area_id != ' . $start_area_id_arr[0] . ' OR r.end_station_area_id != ' . $end_area_id_arr[0] . ') ';
  42. }
  43. $now_date = date('Y-m-d', time());
  44. $sql = '' . 'SELECT
  45. a.run_id,
  46. a.line_id,
  47. a.run_time,
  48. a.start_area_id,
  49. (select area_name from base_area where id = a.start_area_id LIMIT 1) as start_area_name,
  50. a.end_area_id,
  51. (select area_name from base_area where id = a.end_area_id LIMIT 1) as end_area_name,
  52. a.run_date,
  53. ((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,
  54. min(a.price) as price,
  55. (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
  56. FROM
  57. (
  58. SELECT DISTINCT
  59. m.run_id,
  60. p.line_id,
  61. m.run_date,
  62. r.start_station_area_id as start_area_id,
  63. r.end_station_area_id as end_area_id,
  64. r.seat_type,
  65. (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,
  66. (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,
  67. (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,
  68. (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,
  69. (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,
  70. (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,
  71. (SELECT min(cus_price) FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) as price,
  72. (SELECT min(start_time) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id ) as run_time
  73. FROM
  74. opera_line p, run_main m, run_prod r
  75. WHERE
  76. p.line_id = m.prod_id
  77. AND p.org_id ' . $siteContantsConfig['show_line_org'] . '
  78. AND m.run_id = r.run_id
  79. AND p.line_id = r.parent_prod_id
  80. AND m.run_date = \'' . $run_date . '\'
  81. AND p.cancel_flag = 0
  82. AND r.seat_type = 72
  83. AND r.human_type in(0,159,334)
  84. AND r.start_station_area_id in(' . $start_area_id . ')
  85. AND r.end_station_area_id in(' . $end_area_id . ')
  86. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1
  87. ' . $sql_str . '
  88. AND p.line_type in(255,256)
  89. AND (p.line_id < 451023 OR p.line_id > 451028)
  90. AND p.line_id not in(451188,451237,449887,451180)
  91. AND p.is_onsale = 1
  92. AND p.if_disabled = 0
  93. and m.run_status = 138
  94. and m.run_date >= \'' . $now_date . '\'
  95. AND case p.sale_expired_type
  96. 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)
  97. 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)
  98. else 0=0 end
  99. GROUP BY
  100. m.run_id,r.start_station_area_id,r.end_station_area_id,
  101. (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id),
  102. (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id)
  103. ) as a
  104. GROUP BY
  105. a.run_id,a.start_area_id,a.end_area_id
  106. ORDER BY
  107. a.run_time';
  108. $result = $this->fetchAll($sql);
  109. if ($result !== false) {
  110. return Util::returnArrSu('', $result);
  111. } else {
  112. return Util::returnArrEr('数据库错误');
  113. }
  114. }
  115. /**
  116. * Function Description:获取带分页的班次列表
  117. * Function Name: getPageRunsList
  118. * @param $run_date
  119. * @param $start_area_id
  120. * @param $end_area_id
  121. * @param $page_size
  122. * @param $current_page
  123. *
  124. * @return array
  125. *
  126. * @author 张帅
  127. */
  128. public function getPageRunsList($run_date, $start_area_id, $end_area_id, $page_size, $current_page)
  129. {
  130. $now_date = date('Y-m-d', time());
  131. $start_row = ($current_page - 1) * $page_size;
  132. $siteContantsConfig = Util::getSiteContantsConfig();
  133. $sql = '' . 'SELECT
  134. a.run_id,
  135. a.line_id,
  136. a.run_time,
  137. a.start_area_id,
  138. (select area_name from base_area where id = a.start_area_id LIMIT 1) as start_area_name,
  139. a.end_area_id,
  140. (select area_name from base_area where id = a.end_area_id LIMIT 1) as end_area_name,
  141. a.run_date,
  142. ((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,
  143. min(a.price) as price,
  144. (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
  145. FROM
  146. (
  147. SELECT DISTINCT
  148. m.run_id,
  149. p.line_id,
  150. m.run_date,
  151. m.run_time,
  152. r.start_station_area_id as start_area_id,
  153. r.end_station_area_id as end_area_id,
  154. r.seat_type,
  155. (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,
  156. (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,
  157. (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,
  158. (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,
  159. (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,
  160. (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,
  161. (SELECT min(cus_price) FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) as price
  162. FROM
  163. opera_line p, run_main m, run_prod r
  164. WHERE
  165. p.line_id = m.prod_id
  166. AND p.org_id ' . $siteContantsConfig['show_line_org'] . '
  167. AND m.run_id = r.run_id
  168. AND p.line_id = r.parent_prod_id
  169. AND m.run_date = \'' . $run_date . '\'
  170. AND p.cancel_flag = 0
  171. AND r.seat_type = 72
  172. AND r.human_type in(0,159,334)
  173. AND r.start_station_area_id in(' . $start_area_id . ')
  174. AND r.end_station_area_id in(' . $end_area_id . ')
  175. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1
  176. AND p.line_type in(255,256)
  177. AND (p.line_id < 451023 OR p.line_id > 451028)
  178. AND p.line_id not in(451188,451237,449887,451180)
  179. AND p.is_onsale = 1
  180. AND p.if_disabled = 0
  181. and m.run_status = 138
  182. and m.run_date >= \'' . $now_date . '\'
  183. AND case p.sale_expired_type
  184. 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)
  185. 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)
  186. else 0=0 end
  187. GROUP BY
  188. m.run_id,r.start_station_area_id,r.end_station_area_id,
  189. (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id),
  190. (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id)
  191. ) as a
  192. GROUP BY
  193. a.run_id,a.start_area_id,a.end_area_id
  194. ORDER BY
  195. a.run_time
  196. LIMIT ' . $start_row . ',' . $page_size;
  197. $result = $this->fetchAll($sql);
  198. if ($result === false) {
  199. return Util::returnArrEr('数据库错误');
  200. }
  201. if (count($result) == 0) {
  202. $json['common_list'] = $result;
  203. $json['page']['page_size'] = $page_size;
  204. $json['page']['current_page'] = "0";
  205. $json['page']['total_count'] = "0";
  206. $json['page']['total_page'] = "0";
  207. return Util::returnArrSu('', $json);
  208. }
  209. $count_sql = '' . 'SELECT
  210. a.run_id
  211. FROM
  212. (
  213. SELECT DISTINCT
  214. m.run_id,
  215. r.start_station_area_id as start_area_id,
  216. r.end_station_area_id as end_area_id,
  217. r.seat_type,
  218. (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,
  219. (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,
  220. (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,
  221. (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
  222. FROM
  223. opera_line p, run_main m, run_prod r
  224. WHERE
  225. p.line_id = m.prod_id
  226. AND p.org_id ' . $siteContantsConfig['show_line_org'] . '
  227. AND m.run_id = r.run_id
  228. AND p.line_id = r.parent_prod_id
  229. AND m.run_date = \'' . $run_date . '\'
  230. AND p.cancel_flag = 0
  231. AND r.seat_type = 72
  232. AND r.human_type in(0,159,334)
  233. AND r.start_station_area_id in(' . $start_area_id . ')
  234. AND r.end_station_area_id in(' . $end_area_id . ')
  235. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = r.prod_id AND cancel_flag = 0) = 1
  236. AND (p.line_id < 451023 OR p.line_id > 451028
  237. AND p.line_id not in(451188,451237,449887,451180)
  238. AND p.is_onsale = 1
  239. AND p.if_disabled = 0
  240. and m.run_status = 138
  241. and m.run_date >= \'' . $now_date . '\'
  242. AND case p.sale_expired_type
  243. 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)
  244. 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)
  245. else 0=0 end
  246. GROUP BY
  247. m.run_id,r.start_station_area_id,r.end_station_area_id,
  248. (SELECT min(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.start_station_area_id),
  249. (SELECT max(station_order_id) FROM run_station WHERE run_id = m.run_id AND area_id = r.end_station_area_id)
  250. ) as a
  251. GROUP BY
  252. a.run_id,a.start_area_id,a.end_area_id';
  253. $total_count = $this->fetchAll($count_sql);
  254. $total_count = count($total_count);
  255. $total_page = ceil($total_count / $page_size);
  256. $json['common_list'] = $result;
  257. $json['page']['page_size'] = $page_size;
  258. $json['page']['current_page'] = $current_page;
  259. $json['page']['total_count'] = $total_count;
  260. $json['page']['total_page'] = $total_page;
  261. return Util::returnArrSu('', $json);
  262. }
  263. }