|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 |
- <?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' => '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;//站点列表
- $distance_list = isset($param['distance_list']) ? trim($param['distance_list']) : false;//站点列表
- $user_id = $this->user_id;
- $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'];
- }
- return $json;
- }
-
- /**
- * 单一线路详情
- * @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;
- }
- $sql = "SELECT
- 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
- 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['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;
- }
-
- /**
- * 获取线路列表配置信息
- * @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;
- 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;
- $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'];
- 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 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' => 'empty'), $param);
- if (!$valid['status']) {
- $result['code'] = (string)$valid['status'];
- $result['info'] = $valid['info'];
- return $result;
- }
- $user_id = $this->user_id;
- $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'] . "')";
- 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;
- }
-
- /**
- * 单一线路启用
- * @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;
- }
-
- }
|