|
- <?php
- /*
- Author:LB
- Compeny:Spiders Travel
- */
- require_once '../Common/Mysql.php';
- require_once '../Common/config_api.inc';
- if (ALLOW_ORIGIN)
- header("Access-Control-Allow-Origin:*");
- $method = isset($_GET['method']) ? $_GET['method'] : '';
- $USER_ID = getUserId();
- if ($USER_ID === false) {
- echo json_encode(array("code" => "1", "info" => "用户未登录"));
- exit;
- }
- $data = array();
- //$USER_ID=1;
- $pdo = conn();
- switch ($method) {
- case 'getBusList':
- $TYPE_ID = isset($_GET['type_id']) ? $_GET['type_id'] : 0;
- $SORT_ID = isset($_GET['sort_id']) ? $_GET['sort_id'] : 0;
- $PAGE = isset($_GET['currpage']) ? $_GET['currpage'] : 1;
- $PAGE_SIZE = isset($_GET['page_size']) ? $_GET['page_size'] : 10;
- $START_AREA = isset($_GET['start_area']) ? $_GET['start_area'] : '';
- $END_AREA = isset($_GET['end_area']) ? $_GET['end_area'] : '';
- $LINE = isset($_GET['line']) ? $_GET['line'] : '';
- $START_DATE = isset($_GET['start_date']) ? $_GET['start_date'] : '';
- $END_DATE = isset($_GET['end_date']) ? $_GET['end_date'] : '';
- $BUS_TYPE = isset($_GET['bus_type']) ? $_GET['bus_type'] : '0';
- $BUS_GROUP = isset($_GET['bus_group']) ? $_GET['bus_group'] : '0';
- $PROD_START_LIST = "";
- if ($BUS_GROUP != "0") {
- $sql = " SELECT id,group_name,prod_list,start_time_list FROM line_group_common WHERE id={$BUS_GROUP} ";
- $pdo1 = conn();
- $stmt1 = $pdo1->query($sql);
- if ($stmt1) {
- $rowset = $stmt1->fetchAll(PDO::FETCH_ASSOC);
- if ($rowset) {
- $bus_group_info = $rowset[0];
- $prod_array = explode("_", $bus_group_info["prod_list"]);
- $start_array = explode("_", $bus_group_info["start_time_list"]);
- $prod_start_array = array();
- foreach ($prod_array as $key => $prod_id) {
- $PROD_START_LIST .= $prod_id . "," . $start_array[$key] . "|";
- }
- }
- $stmt1->closeCursor();
- }
- }
-
- $sql = "CALL SP_GET_RUN_NO_LIST(" . $USER_ID . "," . $PAGE . "," . $PAGE_SIZE . ",'" . $START_AREA . "'
- ,'" . $END_AREA . "','" . $LINE . "','" . $START_DATE . "','" . $END_DATE . "'," . $TYPE_ID . "," . $BUS_TYPE . "," . $SORT_ID . ",'" . $PROD_START_LIST . "')";
- writeLog('班次调度 sql=' . $sql);
- if (is_object($pdo)) {
- $data['code'] = '0';
- $data['info'] = '';
- $data['run_no_list'] = array();
- $stmt = $pdo->query($sql);
- $i = 1;
- do {
- $rowset = $stmt->fetchAll(PDO::FETCH_ASSOC);
- //$stmt->closeCursor();
- if ($i == 1) {
- $data['currpage'] = $rowset[0]['currpage'];
- $data['total_page'] = $rowset[0]['total_page'];
- $data['total'] = $rowset[0]['total'];
- $data['page_size'] = $rowset[0]['page_size'];
- } else if ($i == 2) {
- // $temp_255=array();
- // $temp_256=array();
- // $temp_real=array();
- // foreach ($rowset as $v){
- // if($v['bus_type']=="255"){
- // array_unshift($temp_255,$v);
- // }
- // if($v['bus_type']=="256"){
- // array_unshift($temp_256,$v);
- // }
- // }
- // $temp_real=array_merge($temp_255,$temp_256);
- $data['run_no_list'] = $rowset;
- } else {
- }
- $i++;
- } while ($stmt->nextRowset());
- }
- $stmt->closeCursor();
- $pdo2 = conn();
- $sql = "CALL SP_GET_VEHICLE_LIST('" . $USER_ID . "','',0)";
- if (is_object($pdo2)) {
- $result = $pdo2->query($sql);
- $json = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if (count($json) > 0) {
- $data['vehicle_list'] = $json;
- } else {
- $data['vehicle_list'] = array();
- }
- }
- $sql = "CALL SP_GET_DRIVER_LIST('" . $USER_ID . "','',0)";
- if (is_object($pdo2)) {
- $result = $pdo2->query($sql);
- $json = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if (count($json) > 0) {
- $data['driver_list'] = $json;
- } else {
- $data['driver_list'] = array();
- }
- }
- $sql = " SELECT id AS group_id,group_name FROM line_group_common WHERE cancel_flag = 0 ";
- if (is_object($pdo2)) {
- $result = $pdo2->query($sql);
- $line_group = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if (count($line_group) > 0) {
- $data['bus_group_list'] = $line_group;
- } else {
- $data['bus_group_list'] = array();
- }
- }
- break;
- case 'vehicleDispatch':
- $BUS_ID = isset($_GET['bus_id']) ? $_GET['bus_id'] : '';//run_bus_id
- $RES_ID = isset($_GET['res_id']) ? $_GET['res_id'] : '';//车辆ID
- if (is_object($pdo)) {
- $url = 'http://' . CS1_DOMAIN . '/api/change-seat/change-bus-for-run-bus';
- $params = array(
- 'user_id' =>$USER_ID ,
- 'bus_id' => $RES_ID,
- 'run_bus_id' => $BUS_ID
- );
- $result = httpRequest($url, $params);
- $result = json_decode($result, true);
- if (!isset($result['code']) || $result['code'] != 0) {
- $data['code'] = "1";
- $data['info'] = empty($result['info']) ? '接口异常' : $result['info'];
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "0";
- $data['info'] = '派遣成功';
- }
- $sql_search = " SELECT RUN_ID,BUS_ORDER_ID FROM RUN_BUS WHERE ID={$BUS_ID} ";
- $pdo_search = conn();
- $result = $pdo_search->query($sql_search);
- if ($result == false) {
- break;
- }
- $run_bus_array = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if ($run_bus_array != false) {
- $run_id = $run_bus_array[0]["RUN_ID"];
- $bus_order_id = $run_bus_array[0]["BUS_ORDER_ID"];
- $sql_get_order = " SELECT DISTINCT(PARENT_ORDER_ID) as PARENT_ORDER_ID FROM order_main WHERE RUN_ID={$run_id} AND RUN_BUS_ORDER_ID={$bus_order_id} AND ORDER_STATUS = 146 AND CANCEL_FLAG = 0 AND PARENT_ORDER_ID <> 0 ";
- $result = $pdo_search->query($sql_get_order);
- if ($result == false) {
- break;
- }
- $set_order_array = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- if ($set_order_array == false) {
- break;
- }
- $order_id_array = array();
- foreach ($set_order_array as $set_order_info) {
- $order_id_array[] = $set_order_info["PARENT_ORDER_ID"];
- }
- $order_id_list = implode(",", $order_id_array);
- $post_data['order_id'] = "{$order_id_list}";
- $post_data['order_status'] = "454";
- send_post("http://" . CS_DOMAIN . "/st-xm/Api/add_order_status_log.php", $post_data);
- }
- }
- break;
- case 'driverDispatch':
- $BUS_ID = isset($_GET['bus_id']) ? $_GET['bus_id'] : '';
- $RES_ID = isset($_GET['res_id']) ? $_GET['res_id'] : '';
- $sql = "CALL SP_DRIVER_DISPATCH('" . $USER_ID . "','" . $BUS_ID . "','" . $RES_ID . "')";
- writeLog('driverDispatch sql===' . $sql);
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- if ($result) {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $data['code'] = isset($rowset[0]['errorcode']) ? $rowset[0]['errorcode'] : "500";
- $data['info'] = isset($rowset[0]['errorinfo']) ? $rowset[0]['errorinfo'] : "未从数据库获得返回值";
- $result->closeCursor();
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "499";
- $data['info'] = "数据库错误";
- echo json_encode($data);
- exit();
- }
- // if($result !== false){
- // $data['code']='0';
- // $data['info']='派遣成功';
- // }else{
- // $data['code']="1";
- // $data['info']='派遣失败';
- // }
- }
- break;
- case 'reset':
- $id_str = isset($_GET['idstr']) ? $_GET['idstr'] : '';
- $sql = "CALL SP_UPDATE_RUN_DISPATCH(" . $USER_ID . ",'" . $id_str . "')";
- writeLog(" reset----重置sql=" . $sql);
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- if ($result) {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $data['code'] = isset($rowset[0]['errorcode']) ? $rowset[0]['errorcode'] : "500";
- $data['info'] = isset($rowset[0]['errorinfo']) ? $rowset[0]['errorinfo'] : "未从数据库获得返回值";
- $result->closeCursor();
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "499";
- $data['info'] = "数据库错误";
- echo json_encode($data);
- exit();
- }
- } else {
- $data['code'] = "-1";
- $data['info'] = "重置发生未知错误";
- echo json_encode($data);
- exit();
- }
- break;
- case 'lock': //锁定 //..
- // $id_str=isset($_GET['idstr'])?$_GET['idstr']:'';
- // $sql="CALL ('".$USER_ID."','".$id_str."')";
- // writeLog("fhc update----锁定sql=".$sql);
- // if(is_object($pdo)){
- // $result=$pdo->query($sql);
- // $data['code']="0";
- // $data['info']="";
- // }else{
- // $data['code']="-1";
- // $data['info']="锁定发生未知错误";
- // }
- break;
- case 'unlock': //解锁 //..
- // $id_str=isset($_GET['idstr'])?$_GET['idstr']:'';
- // $sql="CALL ('".$USER_ID."','".$id_str."')";
- // writeLog("fhc update----解锁sql=".$sql);
- // if(is_object($pdo)){
- // $result=$pdo->query($sql);
- // $data['code']="0";
- // $data['info']="";
- // }else{
- // $data['code']="-1";
- // $data['info']="解锁发生未知错误";
- // }
- break;
- case 'getVehicleList':
- $keyword = isset($_GET['key_word']) ? $_GET['key_word'] : '';
- $company = isset($_GET['company']) ? (empty($_GET['company']) ? "0" : $_GET['company']) : "0";
- $sql = "CALL SP_GET_VEHICLE_LIST('" . $USER_ID . "','" . $keyword . "','" . $company . "')";
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- $json = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $data['code'] = "0";
- $data['info'] = "";
- if (count($json) > 0) {
- $data['vehicle_list'] = $json;
- } else {
- $data['vehicle_list'] = array();
- }
- }
- break;
- case 'getDriverList':
- $keyword = isset($_GET['key_word']) ? $_GET['key_word'] : '';
- $company = isset($_GET['company']) ? (empty($_GET['company']) ? "0" : $_GET['company']) : "0";
- $sql = "CALL SP_GET_DRIVER_LIST('" . $USER_ID . "','" . $keyword . "','" . $company . "')";
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- $json = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $data['code'] = "0";
- $data['info'] = "";
- if (count($json) > 0) {
- $data['driver_list'] = $json;
- } else {
- $data['driver_list'] = array();
- }
- }
- break;
- case 'getCompanyList':
-
- $opera_org_id_sql = "SELECT opera_org_id,main_corp_id FROM base_user WHERE id = " . $USER_ID . " AND cancel_flag = 0";
-
- $opera_org_id_result = $pdo->query($opera_org_id_sql);
- $rowset = $opera_org_id_result->fetchAll(PDO::FETCH_ASSOC);
-
- $opera_org_id = $rowset[0]['opera_org_id'];
- $main_corp_id = $rowset[0]['main_corp_id'];
-
- $and_sql = '';
- if ($opera_org_id != '') {
- $and_sql .= " and org_id in (" . $opera_org_id . ") ";
- }
- if ($main_corp_id != 0) {
- $and_sql .= " and main_corp_id in (" . $main_corp_id . ") ";
- }
-
- // $sql="select
- // A.RES_ID as res_id,
- // A.RES_NAME as res_name
- // from base_resource as A where A.RES_TYPE_ID=18 and A.CANCEL_FLAG=0;";
-
- $sql = "SELECT
- s.id AS res_id,
- s.supplier_name AS res_name
- FROM base_supplier AS s,
- base_supplier_purchase AS p
- WHERE
- s.id = p.supplier_id
- AND s.cancel_flag = 0
- AND p.cancel_flag = 0
- AND p.product_type = 259
- " . $and_sql . "
- GROUP BY s.id";
-
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- $json = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $data['code'] = "0";
- $data['info'] = "";
- if (count($json) > 0) {
- $data['company_list'] = $json;
- } else {
- $data['company_list'] = array();
- }
- }
- break;
- case 'selectPOI':
- $run_id = isset($_GET['run_id']) ? $_GET['run_id'] : "";
- $bus_order_id = isset($_GET['bus_order_id']) ? $_GET['bus_order_id'] : "";
- if ($run_id == "" || $bus_order_id == "") {
- $data['code'] = "400";
- $data['info'] = "缺少参数";
- echo json_encode($data);
- exit();
- }
- $sql = "SELECT DISTINCT
- A.START_STATION_AREA_ID AS start_area_id,
- A.END_STATION_AREA_ID AS end_area_id,
- (SELECT AREA_NAME FROM BASE_AREA WHERE ID = START_STATION_AREA_ID) AS start_area,
- (SELECT AREA_NAME FROM BASE_AREA WHERE ID = END_STATION_AREA_ID) AS end_area,
- (SELECT TYPE_NAME FROM DICT_TYPE WHERE ID = SEAT_TYPE) AS seat,
- A.PROD_ID AS prod_id,
- IFNULL((SELECT BUS_COST_TYPE FROM RUN_BUS AS A WHERE A.RUN_ID=" . $run_id . " AND A.BUS_ORDER_ID=" . $bus_order_id . " AND A.CANCEL_FLAG=0),'') AS method_type,
- IFNULL((SELECT TYPE_NAME FROM DICT_TYPE WHERE ID = HUMAN_TYPE),'') AS croed,
- IFNULL(PRICE.PROD_PRICE,0) AS price,
- IFNULL((SELECT B.COST_PRICE FROM RUN_BUS_COST AS B WHERE B.RUN_ID=" . $run_id . " AND B.START_AREA_ID=A.START_STATION_AREA_ID AND B.END_AREA_ID= A.END_STATION_AREA_ID AND B.BUS_ORDER_ID=1 AND B.CANCEL_FLAG=0 AND (SELECT BUS_COST_TYPE FROM RUN_BUS AS A WHERE A.RUN_ID=" . $run_id . " AND A.BUS_ORDER_ID=" . $bus_order_id . " AND A.CANCEL_FLAG=0)=129),'0') AS every_total_price,
- (SELECT count(*) FROM order_main AS T WHERE T.run_id=" . $run_id . " AND T.prod_start_station_area_id=A.START_STATION_AREA_ID AND T.prod_end_station_area_id=A.END_STATION_AREA_ID AND T.run_bus_order_id=" . $bus_order_id . " AND T.order_valid_status=1 AND T.cancel_flag=0) AS real_sale
- FROM RUN_PROD AS A LEFT JOIN OPERA_PRODUCT_PRICE PRICE ON PRICE.PROD_ID = A.PROD_ID AND PRICE.CANCEL_FLAG = 0
- WHERE A.RUN_ID =" . $run_id . " AND A.CANCEL_FLAG = 0
- GROUP BY start_area_id,end_area_id; ";
- writeLog('selectPOI sql->param=' . $run_id);
- $sql2 = "SELECT max(prod_id) AS prod_id,max(s_id) AS s_id,max(e_id) AS e_id FROM (
- SELECT A.prod_id AS prod_id,t1.property AS s_id,t2.property AS e_id FROM opera_product AS A
- LEFT JOIN opera_product_property AS t1 ON t1.prod_id=A.prod_id AND t1.type_id=125
- LEFT JOIN opera_product_property AS t2 ON t2.prod_id=A.prod_id AND t2.type_id=126
- WHERE A.prod_id=(SELECT prod_id FROM run_main WHERE run_id=" . $run_id . ")) AS temp20160820;";
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- $result2 = $pdo->query($sql2);
- if ($result) {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
- $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
- $result2->closeCursor();
- $data['code'] = "0";
- $data['info'] = "";
- $data['start_end_areaList'] = isset($rowset) ? $rowset : array();
- $data['real_start_end_area'] = isset($rowset2) ? $rowset2 : array();
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "500";
- $data['info'] = "数据库错误";
- echo json_encode($data);
- exit();
- }
- } else {
- $data['code'] = "300";
- $data['info'] = "链接数据库错误";
- echo json_encode($data);
- exit();
- }
- break;
- case 'selectCost': //查询成本
- $run_id = isset($_GET['run_id']) ? $_GET['run_id'] : "";
- $bus_order_id = isset($_GET['bus_order_id']) ? $_GET['bus_order_id'] : "";
- $start_area_id = isset($_GET['start_area_id']) ? $_GET['start_area_id'] : "";
- $end_area_id = isset($_GET['end_area_id']) ? $_GET['end_area_id'] : "";
- if ($run_id == "" || $bus_order_id == "" || $start_area_id == "" || $end_area_id == "") {
- $data['code'] = "400";
- $data['info'] = "缺少参数";
- echo json_encode($data);
- exit();
- }
- $str_main = "{" . $run_id . "," . $bus_order_id . "," . $start_area_id . "," . $end_area_id . "}";
- $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','','','','select');";
- writeLog('selectCost sql=' . $sql);
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- if ($result) {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $result->closeCursor();
-
- $data['code'] = "0";
- $data['info'] = "";
- $data['costList'] = isset($rowset) ? $rowset : array();
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "500";
- $data['info'] = "数据库错误";
- echo json_encode($data);
- exit();
- }
- } else {
- $data['code'] = "300";
- $data['info'] = "链接数据库错误";
- echo json_encode($data);
- exit();
- }
- break;
- case 'updateCost': //修改成本
- $str_main = isset($_GET['str_main']) ? $_GET['str_main'] : "";
- $str_info1 = isset($_GET['str_info1']) ? $_GET['str_info1'] : "{}";
- $str_info2 = isset($_GET['str_info2']) ? $_GET['str_info2'] : "{}";
- $str_remark = isset($_GET['str_remark']) ? $_GET['str_remark'] : "";
- $str_method = isset($_GET['str_method']) ? $_GET['str_method'] : "";
- if ($str_main == "" || $str_info1 == "" || $str_remark == "" || $str_method == "" || $str_info2 == "") {
- $data['code'] = "400";
- $data['info'] = "缺少参数";
- echo json_encode($data);
- exit();
- }
- if ($str_method == 'update_car') {
- $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','" . $str_info1 . "','" . $str_info2 . "','" . $str_remark . "','update_car')";
- } else {
- $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','" . $str_info1 . "','" . $str_info2 . "','" . $str_remark . "','update_seat')";
- }
-
- writeLog('updateCost sql=' . $sql);
- if (is_object($pdo)) {
- $result = $pdo->query($sql);
- if ($result) {
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $data = array();
- $data['code'] = isset($rowset['errcode']) ? $rowset['errcode'] : "0";
- $data['info'] = isset($rowset['errinfo']) ? $rowset['errinfo'] : "";
- $result->closeCursor();
- echo json_encode($data);
- exit();
- } else {
- $data['code'] = "500";
- $data['info'] = "数据库错误";
- echo json_encode($data);
- exit();
- }
- } else {
- $data['code'] = "300";
- $data['info'] = "链接数据库错误";
- echo json_encode($data);
- exit();
- }
- break;
- default:
- break;
-
- }
- if (is_array($data) && count($data) > 0) {
- echo json_encode($data);
- }
- exit;
|