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.
 
 
 
 

485 lines
20 KiB

  1. <?php
  2. /*
  3. Author:LB
  4. Compeny:Spiders Travel
  5. */
  6. require_once '../Common/Mysql.php';
  7. require_once '../Common/config_api.inc';
  8. if (ALLOW_ORIGIN)
  9. header("Access-Control-Allow-Origin:*");
  10. $method = isset($_GET['method']) ? $_GET['method'] : '';
  11. $USER_ID = getUserId();
  12. if ($USER_ID === false) {
  13. echo json_encode(array("code" => "1", "info" => "用户未登录"));
  14. exit;
  15. }
  16. $data = array();
  17. //$USER_ID=1;
  18. $pdo = conn();
  19. switch ($method) {
  20. case 'getBusList':
  21. $TYPE_ID = isset($_GET['type_id']) ? $_GET['type_id'] : 0;
  22. $SORT_ID = isset($_GET['sort_id']) ? $_GET['sort_id'] : 0;
  23. $PAGE = isset($_GET['currpage']) ? $_GET['currpage'] : 1;
  24. $PAGE_SIZE = isset($_GET['page_size']) ? $_GET['page_size'] : 10;
  25. $START_AREA = isset($_GET['start_area']) ? $_GET['start_area'] : '';
  26. $END_AREA = isset($_GET['end_area']) ? $_GET['end_area'] : '';
  27. $LINE = isset($_GET['line']) ? $_GET['line'] : '';
  28. $START_DATE = isset($_GET['start_date']) ? $_GET['start_date'] : '';
  29. $END_DATE = isset($_GET['end_date']) ? $_GET['end_date'] : '';
  30. $BUS_TYPE = isset($_GET['bus_type']) ? $_GET['bus_type'] : '0';
  31. $BUS_GROUP = isset($_GET['bus_group']) ? $_GET['bus_group'] : '0';
  32. $PROD_START_LIST = "";
  33. if ($BUS_GROUP != "0") {
  34. $sql = " SELECT id,group_name,prod_list,start_time_list FROM line_group_common WHERE id={$BUS_GROUP} ";
  35. $pdo1 = conn();
  36. $stmt1 = $pdo1->query($sql);
  37. if ($stmt1) {
  38. $rowset = $stmt1->fetchAll(PDO::FETCH_ASSOC);
  39. if ($rowset) {
  40. $bus_group_info = $rowset[0];
  41. $prod_array = explode("_", $bus_group_info["prod_list"]);
  42. $start_array = explode("_", $bus_group_info["start_time_list"]);
  43. $prod_start_array = array();
  44. foreach ($prod_array as $key => $prod_id) {
  45. $PROD_START_LIST .= $prod_id . "," . $start_array[$key] . "|";
  46. }
  47. }
  48. $stmt1->closeCursor();
  49. }
  50. }
  51. $sql = "CALL SP_GET_RUN_NO_LIST(" . $USER_ID . "," . $PAGE . "," . $PAGE_SIZE . ",'" . $START_AREA . "'
  52. ,'" . $END_AREA . "','" . $LINE . "','" . $START_DATE . "','" . $END_DATE . "'," . $TYPE_ID . "," . $BUS_TYPE . "," . $SORT_ID . ",'" . $PROD_START_LIST . "')";
  53. writeLog('班次调度 sql=' . $sql);
  54. if (is_object($pdo)) {
  55. $data['code'] = '0';
  56. $data['info'] = '';
  57. $data['run_no_list'] = array();
  58. $stmt = $pdo->query($sql);
  59. $i = 1;
  60. do {
  61. $rowset = $stmt->fetchAll(PDO::FETCH_ASSOC);
  62. //$stmt->closeCursor();
  63. if ($i == 1) {
  64. $data['currpage'] = $rowset[0]['currpage'];
  65. $data['total_page'] = $rowset[0]['total_page'];
  66. $data['total'] = $rowset[0]['total'];
  67. $data['page_size'] = $rowset[0]['page_size'];
  68. } else if ($i == 2) {
  69. // $temp_255=array();
  70. // $temp_256=array();
  71. // $temp_real=array();
  72. // foreach ($rowset as $v){
  73. // if($v['bus_type']=="255"){
  74. // array_unshift($temp_255,$v);
  75. // }
  76. // if($v['bus_type']=="256"){
  77. // array_unshift($temp_256,$v);
  78. // }
  79. // }
  80. // $temp_real=array_merge($temp_255,$temp_256);
  81. $data['run_no_list'] = $rowset;
  82. } else {
  83. }
  84. $i++;
  85. } while ($stmt->nextRowset());
  86. }
  87. $stmt->closeCursor();
  88. $pdo2 = conn();
  89. $sql = "CALL SP_GET_VEHICLE_LIST('" . $USER_ID . "','',0)";
  90. if (is_object($pdo2)) {
  91. $result = $pdo2->query($sql);
  92. $json = $result->fetchAll(PDO::FETCH_ASSOC);
  93. $result->closeCursor();
  94. if (count($json) > 0) {
  95. $data['vehicle_list'] = $json;
  96. } else {
  97. $data['vehicle_list'] = array();
  98. }
  99. }
  100. $sql = "CALL SP_GET_DRIVER_LIST('" . $USER_ID . "','',0)";
  101. if (is_object($pdo2)) {
  102. $result = $pdo2->query($sql);
  103. $json = $result->fetchAll(PDO::FETCH_ASSOC);
  104. $result->closeCursor();
  105. if (count($json) > 0) {
  106. $data['driver_list'] = $json;
  107. } else {
  108. $data['driver_list'] = array();
  109. }
  110. }
  111. $sql = " SELECT id AS group_id,group_name FROM line_group_common WHERE cancel_flag = 0 ";
  112. if (is_object($pdo2)) {
  113. $result = $pdo2->query($sql);
  114. $line_group = $result->fetchAll(PDO::FETCH_ASSOC);
  115. $result->closeCursor();
  116. if (count($line_group) > 0) {
  117. $data['bus_group_list'] = $line_group;
  118. } else {
  119. $data['bus_group_list'] = array();
  120. }
  121. }
  122. break;
  123. case 'vehicleDispatch':
  124. $BUS_ID = isset($_GET['bus_id']) ? $_GET['bus_id'] : '';//run_bus_id
  125. $RES_ID = isset($_GET['res_id']) ? $_GET['res_id'] : '';//车辆ID
  126. if (is_object($pdo)) {
  127. $url = 'http://' . CS1_DOMAIN . '/api/change-seat/change-bus-for-run-bus';
  128. $params = array(
  129. 'user_id' =>$USER_ID ,
  130. 'bus_id' => $RES_ID,
  131. 'run_bus_id' => $BUS_ID
  132. );
  133. $result = httpRequest($url, $params);
  134. $result = json_decode($result, true);
  135. if (!isset($result['code']) || $result['code'] != 0) {
  136. $data['code'] = "1";
  137. $data['info'] = empty($result['info']) ? '接口异常' : $result['info'];
  138. echo json_encode($data);
  139. exit();
  140. } else {
  141. $data['code'] = "0";
  142. $data['info'] = '派遣成功';
  143. }
  144. $sql_search = " SELECT RUN_ID,BUS_ORDER_ID FROM RUN_BUS WHERE ID={$BUS_ID} ";
  145. $pdo_search = conn();
  146. $result = $pdo_search->query($sql_search);
  147. if ($result == false) {
  148. break;
  149. }
  150. $run_bus_array = $result->fetchAll(PDO::FETCH_ASSOC);
  151. $result->closeCursor();
  152. if ($run_bus_array != false) {
  153. $run_id = $run_bus_array[0]["RUN_ID"];
  154. $bus_order_id = $run_bus_array[0]["BUS_ORDER_ID"];
  155. $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 ";
  156. $result = $pdo_search->query($sql_get_order);
  157. if ($result == false) {
  158. break;
  159. }
  160. $set_order_array = $result->fetchAll(PDO::FETCH_ASSOC);
  161. $result->closeCursor();
  162. if ($set_order_array == false) {
  163. break;
  164. }
  165. $order_id_array = array();
  166. foreach ($set_order_array as $set_order_info) {
  167. $order_id_array[] = $set_order_info["PARENT_ORDER_ID"];
  168. }
  169. $order_id_list = implode(",", $order_id_array);
  170. $post_data['order_id'] = "{$order_id_list}";
  171. $post_data['order_status'] = "454";
  172. send_post("http://" . CS_DOMAIN . "/st-xm/Api/add_order_status_log.php", $post_data);
  173. }
  174. }
  175. break;
  176. case 'driverDispatch':
  177. $BUS_ID = isset($_GET['bus_id']) ? $_GET['bus_id'] : '';
  178. $RES_ID = isset($_GET['res_id']) ? $_GET['res_id'] : '';
  179. $sql = "CALL SP_DRIVER_DISPATCH('" . $USER_ID . "','" . $BUS_ID . "','" . $RES_ID . "')";
  180. writeLog('driverDispatch sql===' . $sql);
  181. if (is_object($pdo)) {
  182. $result = $pdo->query($sql);
  183. if ($result) {
  184. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  185. $data['code'] = isset($rowset[0]['errorcode']) ? $rowset[0]['errorcode'] : "500";
  186. $data['info'] = isset($rowset[0]['errorinfo']) ? $rowset[0]['errorinfo'] : "未从数据库获得返回值";
  187. $result->closeCursor();
  188. echo json_encode($data);
  189. exit();
  190. } else {
  191. $data['code'] = "499";
  192. $data['info'] = "数据库错误";
  193. echo json_encode($data);
  194. exit();
  195. }
  196. // if($result !== false){
  197. // $data['code']='0';
  198. // $data['info']='派遣成功';
  199. // }else{
  200. // $data['code']="1";
  201. // $data['info']='派遣失败';
  202. // }
  203. }
  204. break;
  205. case 'reset':
  206. $id_str = isset($_GET['idstr']) ? $_GET['idstr'] : '';
  207. $sql = "CALL SP_UPDATE_RUN_DISPATCH(" . $USER_ID . ",'" . $id_str . "')";
  208. writeLog(" reset----重置sql=" . $sql);
  209. if (is_object($pdo)) {
  210. $result = $pdo->query($sql);
  211. if ($result) {
  212. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  213. $data['code'] = isset($rowset[0]['errorcode']) ? $rowset[0]['errorcode'] : "500";
  214. $data['info'] = isset($rowset[0]['errorinfo']) ? $rowset[0]['errorinfo'] : "未从数据库获得返回值";
  215. $result->closeCursor();
  216. echo json_encode($data);
  217. exit();
  218. } else {
  219. $data['code'] = "499";
  220. $data['info'] = "数据库错误";
  221. echo json_encode($data);
  222. exit();
  223. }
  224. } else {
  225. $data['code'] = "-1";
  226. $data['info'] = "重置发生未知错误";
  227. echo json_encode($data);
  228. exit();
  229. }
  230. break;
  231. case 'lock': //锁定 //..
  232. // $id_str=isset($_GET['idstr'])?$_GET['idstr']:'';
  233. // $sql="CALL ('".$USER_ID."','".$id_str."')";
  234. // writeLog("fhc update----锁定sql=".$sql);
  235. // if(is_object($pdo)){
  236. // $result=$pdo->query($sql);
  237. // $data['code']="0";
  238. // $data['info']="";
  239. // }else{
  240. // $data['code']="-1";
  241. // $data['info']="锁定发生未知错误";
  242. // }
  243. break;
  244. case 'unlock': //解锁 //..
  245. // $id_str=isset($_GET['idstr'])?$_GET['idstr']:'';
  246. // $sql="CALL ('".$USER_ID."','".$id_str."')";
  247. // writeLog("fhc update----解锁sql=".$sql);
  248. // if(is_object($pdo)){
  249. // $result=$pdo->query($sql);
  250. // $data['code']="0";
  251. // $data['info']="";
  252. // }else{
  253. // $data['code']="-1";
  254. // $data['info']="解锁发生未知错误";
  255. // }
  256. break;
  257. case 'getVehicleList':
  258. $keyword = isset($_GET['key_word']) ? $_GET['key_word'] : '';
  259. $company = isset($_GET['company']) ? (empty($_GET['company']) ? "0" : $_GET['company']) : "0";
  260. $sql = "CALL SP_GET_VEHICLE_LIST('" . $USER_ID . "','" . $keyword . "','" . $company . "')";
  261. if (is_object($pdo)) {
  262. $result = $pdo->query($sql);
  263. $json = $result->fetchAll(PDO::FETCH_ASSOC);
  264. $result->closeCursor();
  265. $data['code'] = "0";
  266. $data['info'] = "";
  267. if (count($json) > 0) {
  268. $data['vehicle_list'] = $json;
  269. } else {
  270. $data['vehicle_list'] = array();
  271. }
  272. }
  273. break;
  274. case 'getDriverList':
  275. $keyword = isset($_GET['key_word']) ? $_GET['key_word'] : '';
  276. $company = isset($_GET['company']) ? (empty($_GET['company']) ? "0" : $_GET['company']) : "0";
  277. $sql = "CALL SP_GET_DRIVER_LIST('" . $USER_ID . "','" . $keyword . "','" . $company . "')";
  278. if (is_object($pdo)) {
  279. $result = $pdo->query($sql);
  280. $json = $result->fetchAll(PDO::FETCH_ASSOC);
  281. $result->closeCursor();
  282. $data['code'] = "0";
  283. $data['info'] = "";
  284. if (count($json) > 0) {
  285. $data['driver_list'] = $json;
  286. } else {
  287. $data['driver_list'] = array();
  288. }
  289. }
  290. break;
  291. case 'getCompanyList':
  292. $opera_org_id_sql = "SELECT opera_org_id,main_corp_id FROM base_user WHERE id = " . $USER_ID . " AND cancel_flag = 0";
  293. $opera_org_id_result = $pdo->query($opera_org_id_sql);
  294. $rowset = $opera_org_id_result->fetchAll(PDO::FETCH_ASSOC);
  295. $opera_org_id = $rowset[0]['opera_org_id'];
  296. $main_corp_id = $rowset[0]['main_corp_id'];
  297. $and_sql = '';
  298. if ($opera_org_id != '') {
  299. $and_sql .= " and org_id in (" . $opera_org_id . ") ";
  300. }
  301. if ($main_corp_id != 0) {
  302. $and_sql .= " and main_corp_id in (" . $main_corp_id . ") ";
  303. }
  304. // $sql="select
  305. // A.RES_ID as res_id,
  306. // A.RES_NAME as res_name
  307. // from base_resource as A where A.RES_TYPE_ID=18 and A.CANCEL_FLAG=0;";
  308. $sql = "SELECT
  309. s.id AS res_id,
  310. s.supplier_name AS res_name
  311. FROM base_supplier AS s,
  312. base_supplier_purchase AS p
  313. WHERE
  314. s.id = p.supplier_id
  315. AND s.cancel_flag = 0
  316. AND p.cancel_flag = 0
  317. AND p.product_type = 259
  318. " . $and_sql . "
  319. GROUP BY s.id";
  320. if (is_object($pdo)) {
  321. $result = $pdo->query($sql);
  322. $json = $result->fetchAll(PDO::FETCH_ASSOC);
  323. $result->closeCursor();
  324. $data['code'] = "0";
  325. $data['info'] = "";
  326. if (count($json) > 0) {
  327. $data['company_list'] = $json;
  328. } else {
  329. $data['company_list'] = array();
  330. }
  331. }
  332. break;
  333. case 'selectPOI':
  334. $run_id = isset($_GET['run_id']) ? $_GET['run_id'] : "";
  335. $bus_order_id = isset($_GET['bus_order_id']) ? $_GET['bus_order_id'] : "";
  336. if ($run_id == "" || $bus_order_id == "") {
  337. $data['code'] = "400";
  338. $data['info'] = "缺少参数";
  339. echo json_encode($data);
  340. exit();
  341. }
  342. $sql = "SELECT DISTINCT
  343. A.START_STATION_AREA_ID AS start_area_id,
  344. A.END_STATION_AREA_ID AS end_area_id,
  345. (SELECT AREA_NAME FROM BASE_AREA WHERE ID = START_STATION_AREA_ID) AS start_area,
  346. (SELECT AREA_NAME FROM BASE_AREA WHERE ID = END_STATION_AREA_ID) AS end_area,
  347. (SELECT TYPE_NAME FROM DICT_TYPE WHERE ID = SEAT_TYPE) AS seat,
  348. A.PROD_ID AS prod_id,
  349. 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,
  350. IFNULL((SELECT TYPE_NAME FROM DICT_TYPE WHERE ID = HUMAN_TYPE),'') AS croed,
  351. IFNULL(PRICE.PROD_PRICE,0) AS price,
  352. 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,
  353. (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
  354. FROM RUN_PROD AS A LEFT JOIN OPERA_PRODUCT_PRICE PRICE ON PRICE.PROD_ID = A.PROD_ID AND PRICE.CANCEL_FLAG = 0
  355. WHERE A.RUN_ID =" . $run_id . " AND A.CANCEL_FLAG = 0
  356. GROUP BY start_area_id,end_area_id; ";
  357. writeLog('selectPOI sql->param=' . $run_id);
  358. $sql2 = "SELECT max(prod_id) AS prod_id,max(s_id) AS s_id,max(e_id) AS e_id FROM (
  359. SELECT A.prod_id AS prod_id,t1.property AS s_id,t2.property AS e_id FROM opera_product AS A
  360. LEFT JOIN opera_product_property AS t1 ON t1.prod_id=A.prod_id AND t1.type_id=125
  361. LEFT JOIN opera_product_property AS t2 ON t2.prod_id=A.prod_id AND t2.type_id=126
  362. WHERE A.prod_id=(SELECT prod_id FROM run_main WHERE run_id=" . $run_id . ")) AS temp20160820;";
  363. if (is_object($pdo)) {
  364. $result = $pdo->query($sql);
  365. $result2 = $pdo->query($sql2);
  366. if ($result) {
  367. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  368. $result->closeCursor();
  369. $rowset2 = $result2->fetchAll(PDO::FETCH_ASSOC);
  370. $result2->closeCursor();
  371. $data['code'] = "0";
  372. $data['info'] = "";
  373. $data['start_end_areaList'] = isset($rowset) ? $rowset : array();
  374. $data['real_start_end_area'] = isset($rowset2) ? $rowset2 : array();
  375. echo json_encode($data);
  376. exit();
  377. } else {
  378. $data['code'] = "500";
  379. $data['info'] = "数据库错误";
  380. echo json_encode($data);
  381. exit();
  382. }
  383. } else {
  384. $data['code'] = "300";
  385. $data['info'] = "链接数据库错误";
  386. echo json_encode($data);
  387. exit();
  388. }
  389. break;
  390. case 'selectCost': //查询成本
  391. $run_id = isset($_GET['run_id']) ? $_GET['run_id'] : "";
  392. $bus_order_id = isset($_GET['bus_order_id']) ? $_GET['bus_order_id'] : "";
  393. $start_area_id = isset($_GET['start_area_id']) ? $_GET['start_area_id'] : "";
  394. $end_area_id = isset($_GET['end_area_id']) ? $_GET['end_area_id'] : "";
  395. if ($run_id == "" || $bus_order_id == "" || $start_area_id == "" || $end_area_id == "") {
  396. $data['code'] = "400";
  397. $data['info'] = "缺少参数";
  398. echo json_encode($data);
  399. exit();
  400. }
  401. $str_main = "{" . $run_id . "," . $bus_order_id . "," . $start_area_id . "," . $end_area_id . "}";
  402. $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','','','','select');";
  403. writeLog('selectCost sql=' . $sql);
  404. if (is_object($pdo)) {
  405. $result = $pdo->query($sql);
  406. if ($result) {
  407. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  408. $result->closeCursor();
  409. $data['code'] = "0";
  410. $data['info'] = "";
  411. $data['costList'] = isset($rowset) ? $rowset : array();
  412. echo json_encode($data);
  413. exit();
  414. } else {
  415. $data['code'] = "500";
  416. $data['info'] = "数据库错误";
  417. echo json_encode($data);
  418. exit();
  419. }
  420. } else {
  421. $data['code'] = "300";
  422. $data['info'] = "链接数据库错误";
  423. echo json_encode($data);
  424. exit();
  425. }
  426. break;
  427. case 'updateCost': //修改成本
  428. $str_main = isset($_GET['str_main']) ? $_GET['str_main'] : "";
  429. $str_info1 = isset($_GET['str_info1']) ? $_GET['str_info1'] : "{}";
  430. $str_info2 = isset($_GET['str_info2']) ? $_GET['str_info2'] : "{}";
  431. $str_remark = isset($_GET['str_remark']) ? $_GET['str_remark'] : "";
  432. $str_method = isset($_GET['str_method']) ? $_GET['str_method'] : "";
  433. if ($str_main == "" || $str_info1 == "" || $str_remark == "" || $str_method == "" || $str_info2 == "") {
  434. $data['code'] = "400";
  435. $data['info'] = "缺少参数";
  436. echo json_encode($data);
  437. exit();
  438. }
  439. if ($str_method == 'update_car') {
  440. $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','" . $str_info1 . "','" . $str_info2 . "','" . $str_remark . "','update_car')";
  441. } else {
  442. $sql = "CALL SP_UPDATE_COST(" . $USER_ID . ",'" . $str_main . "','" . $str_info1 . "','" . $str_info2 . "','" . $str_remark . "','update_seat')";
  443. }
  444. writeLog('updateCost sql=' . $sql);
  445. if (is_object($pdo)) {
  446. $result = $pdo->query($sql);
  447. if ($result) {
  448. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  449. $data = array();
  450. $data['code'] = isset($rowset['errcode']) ? $rowset['errcode'] : "0";
  451. $data['info'] = isset($rowset['errinfo']) ? $rowset['errinfo'] : "";
  452. $result->closeCursor();
  453. echo json_encode($data);
  454. exit();
  455. } else {
  456. $data['code'] = "500";
  457. $data['info'] = "数据库错误";
  458. echo json_encode($data);
  459. exit();
  460. }
  461. } else {
  462. $data['code'] = "300";
  463. $data['info'] = "链接数据库错误";
  464. echo json_encode($data);
  465. exit();
  466. }
  467. break;
  468. default:
  469. break;
  470. }
  471. if (is_array($data) && count($data) > 0) {
  472. echo json_encode($data);
  473. }
  474. exit;