|
- <?php
- /**
- *
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 张帅
- * PhpStorm RunMain.php
- * Create By 2016/11/16 17:11 $
- */
-
- namespace Order\Model;
-
-
- use Base\Tool\DbTable;
- use Util\Util\Util;
-
- class RunMain extends DbTable
- {
- public $db = 'CST';
- public $tab = 'run_main';
-
- /**
- * Function Description:获取班次详情
- * Function Name: getRunDetail
- * @param $run_id
- *
- * @return mixed
- *
- * @author 张帅
- */
- public function getRunDetail($run_id)
- {
- $sql = '' . 'SELECT
- r.run_id,r.run_date,r.run_time,l.line_name,l.line_code,l.line_id
- FROM
- run_main AS r,
- opera_line AS l
- WHERE
- r.prod_id = l.line_id
- AND r.run_id = ' . $run_id . '
- AND l.cancel_flag = 0
- AND l.is_onsale = 1
- AND l.if_disabled = 0
- AND r.run_status = 138
- LIMIT 1';
- $result = $this->fetchRow($sql);
- if (count($result) > 0) {
- return Util::returnArrSu('', $result);
- } else {
- return Util::returnArrEr('数据库错误');
- }
- }
-
- /**
- * Function Description:获取上车站点
- * Function Name: getStartStation
- * @param $run_id
- * @param $start_area_id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getStartStation($run_id, $start_area_id)
- {
- $sql = '' . 'SELECT
- start_station_res_id as res_id,
- (SELECT res_name FROM base_resource WHERE res_id = start_station_res_id LIMIT 1) as res_name,
- (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
- FROM
- run_prod
- WHERE
- run_id = ' . $run_id . '
- AND start_station_area_id = ' . $start_area_id . '
- AND cancel_flag = 0
-
- AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
- GROUP BY start_station_res_id
- having res_time
- order by res_time';
-
- $result = $this->fetchAll($sql);
- if ($result !== false || count($result) > 0) {
- return Util::returnArrSu('', $result);
- } else {
- return Util::returnArrEr('数据库错误');
- }
- }
-
- /**
- * Function Description:获取下车站点
- * Function Name: getEndStation
- * @param $run_id
- * @param $start_res_id
- * @param $end_area_id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getEndStation($run_id, $start_res_id, $end_area_id)
- {
- $sql = '' . 'SELECT
- end_station_res_id as res_id,
- (SELECT res_name FROM base_resource WHERE res_id = end_station_res_id LIMIT 1) as res_name,
- (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
- FROM
- run_prod
- WHERE
- run_id = ' . $run_id . '
- AND end_station_area_id = ' . $end_area_id . '
- AND cancel_flag = 0
- AND start_station_res_id = ' . $start_res_id . '
- AND (SELECT ticket_type FROM opera_tickets WHERE ticket_id = run_prod.prod_id AND cancel_flag = 0) = 1
- GROUP BY end_station_res_id
- having res_time
- order by res_time';
- $result = $this->fetchAll($sql);
- if ($result !== false || count($result) > 0) {
- return Util::returnArrSu('', $result);
- } else {
- return Util::returnArrEr('数据库错误');
- }
- }
-
- /**
- * Function Description:获取票种信息
- * Function Name: getTicketInfo
- * @param $run_id
- * @param $start_res_id
- * @param $end_res_id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getTicketInfo($run_id, $start_res_id, $end_res_id)
- {
- $sql = '' . 'SELECT
- ticket_id,
- cus_price as price,
- line_id,
- (SELECT start_time from run_station where run_id = ' . $run_id . ' and station_res_id = ' . $start_res_id . ' LIMIT 1) as start_time,
- (SELECT start_time from run_station where run_id = ' . $run_id . ' and station_res_id = ' . $end_res_id . ' LIMIT 1) as end_time,
- (
- SELECT
- min(total_count - saled_count)
- FROM
- run_stock
- WHERE
- run_id = ' . $run_id . '
- AND cancel_flag = 0
- 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)
- 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)
- AND seat_type = t.seat_type
- ) AS stock,
- (
- SELECT
- SUM(distance) as total_distance
- FROM
- opera_station
- WHERE
- line_id = t.line_id
- AND cancel_flag = 0
- 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)
- 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)
- ) as total_distance
- FROM
- opera_tickets as t
- WHERE
- ticket_type = 1
- AND human_type in(0,159,334)
- AND ticket_id IN (
- SELECT
- prod_id
- FROM
- run_prod
- WHERE
- run_id = ' . $run_id . '
- AND start_station_res_id = ' . $start_res_id . '
- AND end_station_res_id = ' . $end_res_id . '
- )
- LIMIT 1';
- $result = $this->fetchRow($sql);
- if (count($result) > 0) {
- return Util::returnArrSu('', $result);
- } else {
- return Util::returnArrEr('数据库错误');
- }
- }
-
- /**
- * Function Description:获取单票种优惠价格
- * Function Name: getDiscountPrice
- * @param $ticket_id
- * @param $channel_id
- *
- * @return array
- *
- * @author 张帅
- */
- public function getDiscountPrice($ticket_id, $channel_id)
- {
- $sql = '' . 'SELECT
- off_value
- FROM
- opera_tickets_discount
- WHERE
- ticket_id = ' . $ticket_id . '
- AND supplier_id = ' . $channel_id . '
- AND is_onsale = 1
- AND cancel_flag = 0
- AND discount_type = 332
- AND discount_day_type = 0
- GROUP BY ticket_id
- LIMIT 1';
- $result = $this->fetchRow($sql);
- if ($result !== false) {
- return Util::returnArrSu('', $result);
- } else {
- return Util::returnArrEr('数据库错误');
- }
- }
-
- }
|