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.
 
 
 
 
 
 

230 lines
8.4 KiB

  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 张帅
  12. * PhpStorm RunMain.php
  13. * Create By 2016/11/16 17:11 $
  14. */
  15. namespace Order\Model;
  16. use Base\Tool\DbTable;
  17. use Util\Util\Util;
  18. class RunMain extends DbTable
  19. {
  20. public $db = 'CST';
  21. public $tab = 'run_main';
  22. /**
  23. * Function Description:获取班次详情
  24. * Function Name: getRunDetail
  25. * @param $run_id
  26. *
  27. * @return mixed
  28. *
  29. * @author 张帅
  30. */
  31. public function getRunDetail($run_id)
  32. {
  33. $sql = '' . 'SELECT
  34. r.run_id,r.run_date,r.run_time,l.line_name,l.line_code,l.line_id
  35. FROM
  36. run_main AS r,
  37. opera_line AS l
  38. WHERE
  39. r.prod_id = l.line_id
  40. AND r.run_id = ' . $run_id . '
  41. AND l.cancel_flag = 0
  42. AND l.is_onsale = 1
  43. AND l.if_disabled = 0
  44. AND r.run_status = 138
  45. LIMIT 1';
  46. $result = $this->fetchRow($sql);
  47. if (count($result) > 0) {
  48. return Util::returnArrSu('', $result);
  49. } else {
  50. return Util::returnArrEr('数据库错误');
  51. }
  52. }
  53. /**
  54. * Function Description:获取上车站点
  55. * Function Name: getStartStation
  56. * @param $run_id
  57. * @param $start_area_id
  58. *
  59. * @return array
  60. *
  61. * @author 张帅
  62. */
  63. public function getStartStation($run_id, $start_area_id)
  64. {
  65. $sql = '' . 'SELECT
  66. start_station_res_id as res_id,
  67. (SELECT res_name FROM base_resource WHERE res_id = start_station_res_id LIMIT 1) as res_name,
  68. (SELECT start_time from run_station where run_id = run_prod.run_id and station_res_id = run_prod.start_station_res_id and station_inout_type !=114 limit 1) as res_time
  69. FROM
  70. run_prod
  71. WHERE
  72. run_id = ' . $run_id . '
  73. AND start_station_area_id = ' . $start_area_id . '
  74. AND cancel_flag = 0
  75. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
  76. GROUP BY start_station_res_id
  77. having res_time
  78. order by res_time';
  79. $result = $this->fetchAll($sql);
  80. if ($result !== false || count($result) > 0) {
  81. return Util::returnArrSu('', $result);
  82. } else {
  83. return Util::returnArrEr('数据库错误');
  84. }
  85. }
  86. /**
  87. * Function Description:获取下车站点
  88. * Function Name: getEndStation
  89. * @param $run_id
  90. * @param $start_res_id
  91. * @param $end_area_id
  92. *
  93. * @return array
  94. *
  95. * @author 张帅
  96. */
  97. public function getEndStation($run_id, $start_res_id, $end_area_id)
  98. {
  99. $sql = '' . 'SELECT
  100. end_station_res_id as res_id,
  101. (SELECT res_name FROM base_resource WHERE res_id = end_station_res_id LIMIT 1) as res_name,
  102. (SELECT start_time from run_station where run_id = run_prod.run_id and station_res_id = run_prod.end_station_res_id and station_inout_type != 114 LIMIT 1) as res_time
  103. FROM
  104. run_prod
  105. WHERE
  106. run_id = ' . $run_id . '
  107. AND end_station_area_id = ' . $end_area_id . '
  108. AND cancel_flag = 0
  109. AND start_station_res_id = ' . $start_res_id . '
  110. AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
  111. GROUP BY end_station_res_id
  112. having res_time
  113. order by res_time';
  114. $result = $this->fetchAll($sql);
  115. if ($result !== false || count($result) > 0) {
  116. return Util::returnArrSu('', $result);
  117. } else {
  118. return Util::returnArrEr('数据库错误');
  119. }
  120. }
  121. /**
  122. * Function Description:获取票种信息
  123. * Function Name: getTicketInfo
  124. * @param $run_id
  125. * @param $start_res_id
  126. * @param $end_res_id
  127. *
  128. * @return array
  129. *
  130. * @author 张帅
  131. */
  132. public function getTicketInfo($run_id, $start_res_id, $end_res_id)
  133. {
  134. $sql = '' . 'SELECT
  135. ticket_id,
  136. cus_price as price,
  137. line_id,
  138. (SELECT start_time from run_station where run_id = ' . $run_id . ' and station_res_id = ' . $start_res_id . ' LIMIT 1) as start_time,
  139. (SELECT start_time from run_station where run_id = ' . $run_id . ' and station_res_id = ' . $end_res_id . ' LIMIT 1) as end_time,
  140. (
  141. SELECT
  142. min(total_count - saled_count)
  143. FROM
  144. run_stock
  145. WHERE
  146. run_id = ' . $run_id . '
  147. AND cancel_flag = 0
  148. AND seq_id >= (SELECT seq_id FROM run_stock WHERE run_id = ' . $run_id . ' AND cancel_flag = 0 AND res_id = ' . $start_res_id . ' AND seat_type = t.seat_type limit 1)
  149. AND seq_id < (SELECT seq_id FROM run_stock WHERE run_id = ' . $run_id . ' AND cancel_flag = 0 AND res_id = ' . $end_res_id . ' AND seat_type = t.seat_type ORDER BY seq_id DESC limit 1)
  150. AND seat_type = t.seat_type
  151. ) AS stock,
  152. (
  153. SELECT
  154. SUM(distance) as total_distance
  155. FROM
  156. opera_station
  157. WHERE
  158. line_id = t.line_id
  159. AND cancel_flag = 0
  160. AND order_id > (SELECT order_id FROM opera_station WHERE line_id = t.line_id AND res_id = ' . $start_res_id . ' AND inout_type IN (108, 109) LIMIT 1)
  161. AND order_id <= (SELECT order_id FROM opera_station WHERE line_id = t.line_id AND res_id = ' . $end_res_id . ' AND inout_type IN (109, 110) ORDER BY order_id DESC LIMIT 1)
  162. ) as total_distance
  163. FROM
  164. opera_tickets as t
  165. WHERE
  166. ticket_type = 1
  167. AND human_type in(0,159,334)
  168. AND ticket_id IN (
  169. SELECT
  170. prod_id
  171. FROM
  172. run_prod
  173. WHERE
  174. run_id = ' . $run_id . '
  175. AND start_station_res_id = ' . $start_res_id . '
  176. AND end_station_res_id = ' . $end_res_id . '
  177. )
  178. LIMIT 1';
  179. $result = $this->fetchRow($sql);
  180. if (count($result) > 0) {
  181. return Util::returnArrSu('', $result);
  182. } else {
  183. return Util::returnArrEr('数据库错误');
  184. }
  185. }
  186. /**
  187. * Function Description:获取单票种优惠价格
  188. * Function Name: getDiscountPrice
  189. * @param $ticket_id
  190. * @param $channel_id
  191. *
  192. * @return array
  193. *
  194. * @author 张帅
  195. */
  196. public function getDiscountPrice($ticket_id, $channel_id)
  197. {
  198. $sql = '' . 'SELECT
  199. off_value
  200. FROM
  201. opera_tickets_discount
  202. WHERE
  203. ticket_id = ' . $ticket_id . '
  204. AND supplier_id = ' . $channel_id . '
  205. AND is_onsale = 1
  206. AND cancel_flag = 0
  207. AND discount_type = 332
  208. AND discount_day_type = 0
  209. GROUP BY ticket_id
  210. LIMIT 1';
  211. $result = $this->fetchRow($sql);
  212. if ($result !== false) {
  213. return Util::returnArrSu('', $result);
  214. } else {
  215. return Util::returnArrEr('数据库错误');
  216. }
  217. }
  218. }