|
- <?php
-
- /**
- * Created by PhpStorm.
- * User: 张帅
- * Date: 2016/10/12
- * Time: 14:30
- */
- class singleLine extends base
- {
- /**
- * @param line_id 线路id
- * @param line_name 线路名称
- * @param line_code 线路代码
- * @param line_type 线路类型1
- * @param line_sub_type 线路类型2
- * @param time_type 时间类型
- * @param time_info 时间
- * @param supply_id 供应商id
- * @param station_list 线路id 格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
- * @return array|null
- * User: Steven
- */
- function addLine($param)
- {
- $valid = zzcsUtils::validateParams(array('line_name,line_code,line_type,line_sub_type,time_type,time_info,supply_id,station_list,allow_selected_seat' => 'empty'), $param);
- if (!$valid['status']) {
- $result['code'] = (string)$valid['status'];
- $result['info'] = $valid['info'];
- return $result;
- }
- $line_name = isset($param['line_name']) ? trim($param['line_name']) : false;//线路名称
- $line_code = isset($param['line_code']) ? trim($param['line_code']) : false;//线路代码
- $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型1
- $line_sub_type = isset($param['line_sub_type']) ? trim($param['line_sub_type']) : false;//线路类型2
- $time_type = isset($param['time_type']) ? trim($param['time_type']) : false;//时间类型
- $time_info = isset($param['time_info']) ? trim($param['time_info']) : false;//时间
- $supply_id = isset($param['supply_id']) ? trim($param['supply_id']) : false;//供应商id
- //格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
- $station_list = isset($param['station_list']) ? trim($param['station_list']) : false;//站点列表
- $allow_selected_seat = isset($param['allow_selected_seat']) ? trim($param['allow_selected_seat']) : false;//是否支持换座
- $user_id = $this->user_id;
- $data = [
- 'user_id'=>$user_id,
- 'line_name'=>$line_name,
- 'line_code'=>$line_code,
- 'line_type'=>$line_type,
- 'line_sub_type'=>$line_sub_type,
- 'time_type'=>$time_type,
- 'time_info'=>$time_info,
- 'supply_id'=>$supply_id,
- 'station_list'=>$station_list,
- 'allow_selected_seat'=>$allow_selected_seat,
- ];
- $result=$this->httpRequest('http://'.CS1_DOMAIN.'/api/run-edit/add-line',$data);
- // $sql_check = 'SELECT line_id count from opera_line WHERE line_code = \'' . $line_code . '\' AND cancel_flag = 0';
- // $res_check = $this->query($sql_check);
- // if (count($res_check) > 0) {
- // $result['code'] = '3';
- // $result['info'] = "线路编号已存在";
- // return $result;
- // }
- // $sql = "CALL sp_add_line_station_xm(" . $user_id . ",'" . $line_name . "','" . $line_code . "'," . $line_type . "," . $line_sub_type . "," . $time_type . ",'" . $time_info . "'," . $supply_id . ",'" . $station_list . "')";
- // zzcsUtils::writeLog($sql);
- // $result = $this->procQuery($sql);
- // if ($result['code'] == 0) {
- // $json['code'] = '0';
- // $json['info'] = '添加线路成功';
- // $json['line_id'] = $result['data'][0][0]['line_id'];
- // $json['line_type'] = $line_type;
- // } else {
- // $json['code'] = $result['code'];
- // $json['info'] = $result['info'];
- // }
- // echo json_encode($json);
- return json_decode($result);
- }
-
- function httpRequest($url, $data = null)
- {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- if (!empty($data)) {
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- }
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $output = curl_exec($ch);
- curl_close($ch);
- return $output;
- }
-
- /**
- * 单一线路详情
- * @param $param
- */
- function getLineDetail($param)
- {
- $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;//线路id
- if (!$line_id) {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $data = array(
- 'line_id' => $line_id
- );
- $json = $this->httpRequest('http://' . CS1_DOMAIN . '/api/run-edit/get-line-detail', $data);
- // $sql = "SELECT
- // l.tailor_flag,l.line_id,l.line_name,l.line_code,l.line_type,l.org_id,l.sale_expired_type,l.sale_expired_time,s.order_id,s.res_id,s.start_minutes,s.inout_type,s.checkport_res_id,s.area_id,s.distance,l.allow_select_seat
- // FROM
- // opera_line AS l,
- // opera_station AS s
- // WHERE
- // l.line_id = s.line_id
- // AND l.cancel_flag = 0
- // AND s.cancel_flag = 0
- // AND l.line_id = " . $line_id;
- // $line_info = $this->query($sql);
- // if (count($line_info) == 0) {
- // $json['code'] = '1';
- // $json['info'] = '该线路配置不全';
- // return $json;
- // }
- // foreach ($line_info as $k => $v) {
- // if (!isset($line_base_info)) {
- // $line_base_info['tailor_flag'] = $v['tailor_flag'];
- // $line_base_info['line_id'] = $v['line_id'];
- // $line_base_info['line_name'] = $v['line_name'];
- // $line_base_info['line_code'] = $v['line_code'];
- // $line_base_info['line_type'] = $v['line_type'];
- // $line_base_info['org_id'] = $v['org_id'];
- // $line_base_info['sale_expired_type'] = $v['sale_expired_type'];
- // $line_base_info['sale_expired_time'] = $v['sale_expired_time'];
- // }
- // $res_base_info[$v['order_id']]['res_id'] = $v['res_id'];
- // $res_base_info[$v['order_id']]['inout_type'] = $v['inout_type'];
- // $res_base_info[$v['order_id']]['checkport_res_id'] = $v['checkport_res_id'];
- // $res_base_info[$v['order_id']]['area_id'] = $v['area_id'];
- // $res_base_info[$v['order_id']]['start_minutes'] = $v['start_minutes'];
- // $res_base_info[$v['order_id']]['distance'] = $v['distance'];
- // }
- // ksort($res_base_info);
- // foreach ($res_base_info as $order_id => $res_v) {
- // $res_detail_info = $this->getStationInfo(array('res_id' => $res_v['res_id']));
- // if ($res_detail_info['code'] != '0') {
- // $json['code'] = '1';
- // $json['info'] = '站点信息有误';
- // return $json;
- // }
- // $res_detail_info = $res_detail_info['res_info'];
- // foreach ($res_detail_info['parent_area'] as $k => $v) {
- // if ($v['id'] == $res_v['area_id']) {
- // $res_detail_info['parent_area'][$k]['checked'] = '1';
- // } else {
- // $res_detail_info['parent_area'][$k]['checked'] = '0';
- // }
- // }
- // foreach ($res_detail_info['inout_type'] as $k => $v) {
- // if ($v['id'] == $res_v['inout_type']) {
- // $res_detail_info['inout_type'][$k]['checked'] = '1';
- // } else {
- // $res_detail_info['inout_type'][$k]['checked'] = '0';
- // }
- // }
- // foreach ($res_detail_info['check_port'] as $k => $v) {
- // if ($v['id'] == $res_v['checkport_res_id']) {
- // $res_detail_info['check_port'][$k]['checked'] = '1';
- // } else {
- // $res_detail_info['check_port'][$k]['checked'] = '0';
- // }
- // }
- // $res_detail_info['start_minutes'] = $res_v['start_minutes'];
- // $res_detail_info['distance'] = $res_v['distance'];
- // $res_array[$order_id] = $res_detail_info;
- // }
- // $json['code'] = '0';
- // $json['info'] = '返回数据成功';
- // $json['line_info'] = $line_base_info;
- // $json['station_info'] = array_merge($res_array);
- return json_decode($json);
- }
-
- /**
- * 获取线路列表配置信息
- * @return mixed
- */
- function getLineListBase()
- {
- $res = $this->productLine(); //获取产品线
- $supply = $this->getSupply();
- $json['code'] = '0';
- $json['info'] = '获取供应商列表成功';
- $json['product_list'] = $res;
- $json['supply_list'] = $supply;
- return $json;
- }
-
- /**
- * 单一线路列表
- * @param $param
- */
- function getLineList($post)
- {
- $page_size = isset($post['page_size']) ? trim($post['page_size']) : false;
- $current_page = isset($post['current_page']) ? trim($post['current_page']) : false;
- $line_code = isset($post['line_code']) ? (empty($post['line_code']) ? "''" : "'" . trim($post['line_code']) . "'") : false;
- $supply_id = isset($post['supply_id']) ? trim($post['supply_id']) : false;
- $line_status = isset($post['line_status']) ? trim($post['line_status']) : false;
- $line_type = isset($post['line_type']) ? trim($post['line_type']) : false;
- $tailor_type = isset($post['tailor_type']) ? $post['tailor_type'] : 0;
- if (!$page_size || !$current_page || !$line_code || !$supply_id || !$line_type) {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $where['line_type'] = $line_type;
- $where['line_code'] = $line_code;
- $where['supply_id'] = $supply_id;
- $where['line_status'] = $line_status;
- $where['tailor_type'] = $tailor_type;
- $start_row = ($current_page - 1) * $page_size;
-
- $extra_sql = "";
- if (isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0) {
- $extra_sql .= ' AND ORG_ID IN( ' . $_COOKIE["opera_org_id"] . ' ) ';
- }
- if (isset($_COOKIE["user_main_corp"]) && mb_strlen($_COOKIE["user_main_corp"]) > 0 && $_COOKIE["user_main_corp"] > 0) {
- $extra_sql .= ' AND MAIN_CORP_ID IN( ' . $_COOKIE["user_main_corp"] . ' ) ';
- }
-
- $search_line_type = "l.line_type = " . $where['line_type'] . ' AND l.tailor_type = ' . $where['tailor_type'];
-
- if ($where['line_type'] == 255) {
- $search_line_type = "l.line_type IN (255,368) ";//一日游线路
- }
- $sql = "SELECT
- l.line_id,l.line_code,l.line_name,
- IFNULL((SELECT type_name FROM dict_type WHERE id = l.line_sub_type),'') AS line_sub_type,
- IFNULL((SELECT supplier_name FROM base_supplier WHERE id = l.org_id ), '' ) AS org_name,
- CASE l.if_disabled WHEN 0 THEN '启用' ELSE '停用' END AS disabled_status,
- count(t.id) AS cnt
- FROM
- opera_line AS l LEFT JOIN
- (SELECT id,line_id FROM opera_tickets_group WHERE cancel_flag = 0) AS t
- ON l.line_id = t.line_id
- WHERE
- l.cancel_flag = 0
- AND {$search_line_type}
- AND IF(TRIM(" . $where['line_code'] . ")='',0=0,(l.line_code LIKE CONCAT('%'," . $where['line_code'] . ",'%') OR l.line_name LIKE CONCAT('%'," . $where['line_code'] . ",'%')))
- AND IF(TRIM(" . $where['supply_id'] . ")=-1,0=0,l.org_id = " . $where['supply_id'] . ")
- AND IF(TRIM(" . $where['line_status'] . ")=-1,0=0,l.if_disabled = " . $where['line_status'] . ")" . $extra_sql . "
- GROUP BY
- l.line_id,l.line_code,l.line_name,l.line_sub_type,l.org_id,l.if_disabled
- ORDER BY
- l.line_id DESC
- LIMIT " . $start_row . "," . $page_size;
- $line_list = $this->query($sql);
- if (count($line_list) == 0) {
- $json['code'] = '0';
- $json['info'] = '没有符合的线路';
- $json['line_list'] = array();
- $json['page']['page_size'] = $page_size;
- $json['page']['current_page'] = $current_page;
- $json['page']['total_count'] = '0';
- $json['page']['total_page'] = '0';
- return $json;
- }
-
- $count_sql = "SELECT
- count(line_id) as total_count
- FROM
- opera_line as l
- WHERE
- cancel_flag = 0
- AND {$search_line_type}
- AND IF(TRIM(" . $where['line_code'] . ")='',0=0,(line_code LIKE CONCAT('%'," . $where['line_code'] . ",'%') OR line_name LIKE CONCAT('%'," . $where['line_code'] . ",'%')))
- AND IF(TRIM(" . $where['supply_id'] . ")=-1,0=0,org_id = " . $where['supply_id'] . ")
- AND IF(TRIM(" . $where['line_status'] . ")=-1,0=0,if_disabled = " . $where['line_status'] . ") " . $extra_sql;
- $total_count = $this->query($count_sql);
- $total_count = $total_count[0]['total_count'];
- $total_page = ceil($total_count / $page_size);
- $json['code'] = '0';
- $json['info'] = '返回线路列表成功符合的线路';
- $json['line_list'] = $line_list;
- $json['page']['page_size'] = $page_size;
- $json['page']['current_page'] = $current_page;
- $json['page']['total_count'] = $total_count;
- $json['page']['total_page'] = $total_page;
- return $json;
- }
-
- /**
- * @param tailor_flag 接驳flag
- * @param line_id 线路id
- * @param line_name 线路名称
- * @param line_code 线路代码
- * @param line_type 线路类型1
- * @param line_sub_type 线路类型2
- * @param time_type 时间类型
- * @param time_info 时间
- * @param supply_id 供应商id
- * @param station_list 线路id 格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
- * @return array|null
- * User: Steven
- */
- function lineUpdate($param)
- {
- $valid = zzcsUtils::validateParams(array('line_id,line_name,line_code,line_type,line_sub_type,time_type,time_info,supply_id,station_list,allow_selected_seat' => 'empty'), $param);
- if (!$valid['status']) {
- $result['code'] = (string)$valid['status'];
- $result['info'] = $valid['info'];
- return $result;
- }
- $user_id = $this->user_id;
- $data = [
- 'user_id'=>$this->user_id,
- 'line_code'=>$param['line_code'],
- 'line_id'=>$param['line_id'],
- 'line_name'=>$param['line_name'],
- 'line_type'=>$param['line_type'],
- 'line_sub_type'=>$param['line_sub_type'],
- 'time_type'=>$param['time_type'],
- 'time_info'=>$param['time_info'],
- 'supply_id'=>$param['supply_id'],
- 'station_list'=>$param['station_list'],
- 'tailor_flag'=>$param['tailor_flag'],
- 'allow_selected_seat'=>$param['allow_selected_seat']
-
- ];
- $result=$this->httpRequest('http://'.CS1_DOMAIN.'/api/run-edit/upt-line',$data);
- // $sql_check = 'SELECT line_id count FROM opera_line WHERE cancel_flag = 0 AND line_code = \'' . $param['line_code'] . '\' AND line_id != ' . $param['line_id'];
- // $res_check = $this->query($sql_check);
- // if (count($res_check) > 0) {
- // $result['code'] = '3';
- // $result['info'] = "线路编号已存在";
- // return $result;
- // }
- // $sql = "CALL sp_update_line_station_xm(" . $user_id . "," . $param['line_id'] . ",'" . $param['line_name'] . "','" . $param['line_code'] . "'," . $param['line_type'] . "," . $param['line_sub_type'] . "," . $param['time_type'] . ",'" . $param['time_info'] . "'," . $param['supply_id'] . ",'" . $param['station_list'] . "'," . $param['tailor_flag'] . "," . $param['allow_selected_seat'] . ")";
- // zzcsUtils::writeLog($sql);
- // $result = $this->procQuery($sql);
- // if ($result['code'] == 0) {
- // $json['code'] = '0';
- // $json['info'] = '修改线路成功';
- // $json['line_id'] = $param['line_id'];
- // $json['line_type'] = $param['line_type'];
- // } else {
- // $json['code'] = $result['code'];
- // $json['info'] = $result['info'];
- // }
- return json_decode($result);
- }
-
- /**
- * 单一线路启用
- * @param $param
- */
- function lineStart($param)
- {
- //hyk
- $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;
- if (!$line_id) {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $update_time = date('Y-m-d h:i:s');//更新时间
- $sql = "UPDATE opera_line SET if_disabled= 0 ,update_user_id=" . $this->user_id . " , update_time= '" . $update_time . "' WHERE line_id IN(" . $line_id . ") AND cancel_flag =0";
- $result = $this->exec($sql);
- if ($result === false) {
- $json['code'] = '1';
- $json['info'] = '数据库异常';
- return $json;
- } else {
- $json['code'] = '0';
- $json['info'] = '更新成功';
- return $json;
-
- }
- }
-
- /**
- * 单一线路停用
- * @param $param
- */
- function lineStop($param)
- {
- //hyk
- $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;
- if (!$line_id) {
- $json['code'] = '2';
- $json['info'] = '缺少必要参数';
- return $json;
- }
- $update_time = date('Y-m-d h:i:s');//更新时间
- $sql = "UPDATE opera_line SET if_disabled= 1,update_user_id=" . $this->user_id . " , update_time= '" . $update_time . "' WHERE line_id IN(" . $line_id . ") AND cancel_flag =0";
- $result = $this->exec($sql);
- if ($result === false) {
- $json['code'] = '1';
- $json['info'] = '数据库异常';
- return $json;
- } else {
- $json['code'] = '0';
- $json['info'] = '更新成功';
- return $json;
-
- }
- }
-
- /**
- * 获取添加线路的基础信息
- * @param $param OK
- */
- function getBaseManager()
- {
- //1.售卖情况时间列表
- $time_type = $this->getTimeType();
- //2.巴士类型表
- $bus_type = $this->getBusType();
- //3.供应商列表
- $supply_list = $this->getSupply();
- $json['code'] = '0';
- $json['info'] = '返回数据成功';
- $json['bus_type'] = $bus_type;
- $json['supply_list'] = $supply_list;
- $json['time_type'] = $time_type;
- return $json;
- }
-
- /**
- * 获取全部站点
- * @param $param
- */
- function getLineStation($post)
- {
- $res_name = trim($post['res_name']);//输入框输入的站点信息
- $sql = "SELECT
- res_id,
- res_name
- FROM
- base_resource
- WHERE
- res_type_id = 24
- AND cancel_flag = 0
- AND res_name LIKE '%" . $res_name . "%'";
- $res_list = $this->query($sql);//场站列表
- $json['code'] = '0';
- $json['info'] = '返回数据成功';
- $json['res_list'] = $res_list;
- return $json;
- }
-
- /**
- * 获取站点详情
- * @param $param
- */
- function getStationInfo($post)
- {
- $res_id = trim($post['res_id']);//站点id
- $check_area = "SELECT
- ifnull(area_id, 0) AS area_id
- FROM
- base_resource
- WHERE
- res_id = " . $res_id;
- $area = $this->query($check_area);//场站列表
- if ($area[0]['area_id'] == 0) {
- $json['code'] = '1';
- $json['info'] = '该站点无应用POI,请先配置应用POI!';
- return $json;
- }
-
- //获取站点信息详情
- $station_info = "SELECT
- a.res_id,
- a.res_name,
- IFNULL(concat(b.parent_area_id_list,'{',b.area_id,'}'),'') AS parent_area_id_list,
- IFNULL(concat(b.parent_area_name_list,'{',b.area_name,'}'),'') AS parent_area_name_list,
- IFNULL(
- (
- SELECT
- group_concat(res_id)
- FROM
- base_resource
- WHERE
- res_type_id = 79
- AND cancel_flag = 0
- AND parent_id = a.res_id
- ),
- 0
- ) AS checkport_res_id,
- IFNULL(
- (
- SELECT
- group_concat(res_name)
- FROM
- base_resource
- WHERE
- res_type_id = 79
- AND cancel_flag = 0
- AND parent_id = a.res_id
- ),
- ''
- ) AS checkport_res_name
- FROM
- base_resource a
- LEFT JOIN base_area_view b ON a.area_id = b.area_id
- WHERE
- a.cancel_flag = 0
- AND a.res_id = " . $res_id;
- $res_info = $this->query($station_info);//场站详情
- $res_info = $res_info[0];
- $res_info['parent_area_id_list'] = substr($res_info['parent_area_id_list'], 1, -1);
- $res_info['parent_area_name_list'] = substr($res_info['parent_area_name_list'], 1, -1);
- $res_info['parent_area_id_list'] = explode("}{", $res_info['parent_area_id_list']);//应用POI站点id数组
- $res_info['parent_area_name_list'] = explode("}{", $res_info['parent_area_name_list']);//应用POI站点name数组
- $res_info['checkport_res_id'] = explode(",", $res_info['checkport_res_id']);//检票口id数组
- $res_info['checkport_res_name'] = explode(",", $res_info['checkport_res_name']);//检票口name数组
- //规整返回前端的站点数据
- $res = array();
- $res['res_id'] = $res_info['res_id'];
- $res['res_name'] = $res_info['res_name'];
- foreach ($res_info['parent_area_id_list'] as $k => $v) {
- $res['parent_area'][$k]['id'] = $v;
- $res['parent_area'][$k]['name'] = $res_info['parent_area_name_list'][$k];
- }
- foreach ($res_info['checkport_res_id'] as $k => $v) {
- $res['check_port'][$k]['id'] = $v;
- $res['check_port'][$k]['name'] = $res_info['checkport_res_name'][$k];
- }
- $res['inout_type'] = array(
- 0 => array(
- 'id' => '108',
- 'name' => '上'
- ),
- 1 => array(
- 'id' => '109',
- 'name' => '上下'
- ),
- 2 => array(
- 'id' => '110',
- 'name' => '下'
- )
- );
-
- $json['code'] = '0';
- $json['info'] = '返回数据成功';
- $json['res_info'] = $res;
- return $json;
- }
-
- }
|