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.
 
 
 
 

499 regels
22 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 张帅
  5. * Date: 2016/10/12
  6. * Time: 14:30
  7. */
  8. class singleLine extends base
  9. {
  10. /**
  11. * @param line_id 线路id
  12. * @param line_name 线路名称
  13. * @param line_code 线路代码
  14. * @param line_type 线路类型1
  15. * @param line_sub_type 线路类型2
  16. * @param time_type 时间类型
  17. * @param time_info 时间
  18. * @param supply_id 供应商id
  19. * @param station_list 线路id 格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
  20. * @return array|null
  21. * User: Steven
  22. */
  23. function addLine($param)
  24. {
  25. $valid = zzcsUtils::validateParams(array('line_name,line_code,line_type,line_sub_type,time_type,time_info,supply_id,station_list' => 'empty'), $param);
  26. if (!$valid['status']) {
  27. $result['code'] = (string)$valid['status'];
  28. $result['info'] = $valid['info'];
  29. return $result;
  30. }
  31. $line_name = isset($param['line_name']) ? trim($param['line_name']) : false;//线路名称
  32. $line_code = isset($param['line_code']) ? trim($param['line_code']) : false;//线路代码
  33. $line_type = isset($param['line_type']) ? trim($param['line_type']) : false;//线路类型1
  34. $line_sub_type = isset($param['line_sub_type']) ? trim($param['line_sub_type']) : false;//线路类型2
  35. $time_type = isset($param['time_type']) ? trim($param['time_type']) : false;//时间类型
  36. $time_info = isset($param['time_info']) ? trim($param['time_info']) : false;//时间
  37. $supply_id = isset($param['supply_id']) ? trim($param['supply_id']) : false;//供应商id
  38. //格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
  39. $station_list = isset($param['station_list']) ? trim($param['station_list']) : false;//站点列表
  40. $distance_list = isset($param['distance_list']) ? trim($param['distance_list']) : false;//站点列表
  41. $user_id = $this->user_id;
  42. $sql_check = 'SELECT line_id count from opera_line WHERE line_code = \'' . $line_code . '\' AND cancel_flag = 0';
  43. $res_check = $this->query($sql_check);
  44. if (count($res_check) > 0) {
  45. $result['code'] = '3';
  46. $result['info'] = "线路编号已存在";
  47. return $result;
  48. }
  49. $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 . "')";
  50. zzcsUtils::writeLog($sql);
  51. $result = $this->procQuery($sql);
  52. if ($result['code'] == 0) {
  53. $json['code'] = '0';
  54. $json['info'] = '添加线路成功';
  55. $json['line_id'] = $result['data'][0][0]['line_id'];
  56. $json['line_type'] = $line_type;
  57. } else {
  58. $json['code'] = $result['code'];
  59. $json['info'] = $result['info'];
  60. }
  61. return $json;
  62. }
  63. /**
  64. * 单一线路详情
  65. * @param $param
  66. */
  67. function getLineDetail($param)
  68. {
  69. $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;//线路id
  70. if (!$line_id) {
  71. $json['code'] = '2';
  72. $json['info'] = '缺少必要参数';
  73. return $json;
  74. }
  75. $sql = "SELECT
  76. 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
  77. FROM
  78. opera_line AS l,
  79. opera_station AS s
  80. WHERE
  81. l.line_id = s.line_id
  82. AND l.cancel_flag = 0
  83. AND s.cancel_flag = 0
  84. AND l.line_id = " . $line_id;
  85. $line_info = $this->query($sql);
  86. if (count($line_info) == 0) {
  87. $json['code'] = '1';
  88. $json['info'] = '该线路配置不全';
  89. return $json;
  90. }
  91. foreach ($line_info as $k => $v) {
  92. if (!isset($line_base_info)) {
  93. $line_base_info['line_id'] = $v['line_id'];
  94. $line_base_info['line_name'] = $v['line_name'];
  95. $line_base_info['line_code'] = $v['line_code'];
  96. $line_base_info['line_type'] = $v['line_type'];
  97. $line_base_info['org_id'] = $v['org_id'];
  98. $line_base_info['sale_expired_type'] = $v['sale_expired_type'];
  99. $line_base_info['sale_expired_time'] = $v['sale_expired_time'];
  100. }
  101. $res_base_info[$v['order_id']]['res_id'] = $v['res_id'];
  102. $res_base_info[$v['order_id']]['inout_type'] = $v['inout_type'];
  103. $res_base_info[$v['order_id']]['checkport_res_id'] = $v['checkport_res_id'];
  104. $res_base_info[$v['order_id']]['area_id'] = $v['area_id'];
  105. $res_base_info[$v['order_id']]['start_minutes'] = $v['start_minutes'];
  106. $res_base_info[$v['order_id']]['distance'] = $v['distance'];
  107. }
  108. ksort($res_base_info);
  109. foreach ($res_base_info as $order_id => $res_v) {
  110. $res_detail_info = $this->getStationInfo(array('res_id' => $res_v['res_id']));
  111. if ($res_detail_info['code'] != '0') {
  112. $json['code'] = '1';
  113. $json['info'] = '站点信息有误';
  114. return $json;
  115. }
  116. $res_detail_info = $res_detail_info['res_info'];
  117. foreach ($res_detail_info['parent_area'] as $k => $v) {
  118. if ($v['id'] == $res_v['area_id']) {
  119. $res_detail_info['parent_area'][$k]['checked'] = '1';
  120. } else {
  121. $res_detail_info['parent_area'][$k]['checked'] = '0';
  122. }
  123. }
  124. foreach ($res_detail_info['inout_type'] as $k => $v) {
  125. if ($v['id'] == $res_v['inout_type']) {
  126. $res_detail_info['inout_type'][$k]['checked'] = '1';
  127. } else {
  128. $res_detail_info['inout_type'][$k]['checked'] = '0';
  129. }
  130. }
  131. foreach ($res_detail_info['check_port'] as $k => $v) {
  132. if ($v['id'] == $res_v['checkport_res_id']) {
  133. $res_detail_info['check_port'][$k]['checked'] = '1';
  134. } else {
  135. $res_detail_info['check_port'][$k]['checked'] = '0';
  136. }
  137. }
  138. $res_detail_info['start_minutes'] = $res_v['start_minutes'];
  139. $res_detail_info['distance'] = $res_v['distance'];
  140. $res_array[$order_id] = $res_detail_info;
  141. }
  142. $json['code'] = '0';
  143. $json['info'] = '返回数据成功';
  144. $json['line_info'] = $line_base_info;
  145. $json['station_info'] = array_merge($res_array);
  146. return $json;
  147. }
  148. /**
  149. * 获取线路列表配置信息
  150. * @return mixed
  151. */
  152. function getLineListBase()
  153. {
  154. $res = $this->productLine(); //获取产品线
  155. $supply = $this->getSupply();
  156. $json['code'] = '0';
  157. $json['info'] = '获取供应商列表成功';
  158. $json['product_list'] = $res;
  159. $json['supply_list'] = $supply;
  160. return $json;
  161. }
  162. /**
  163. * 单一线路列表
  164. * @param $param
  165. */
  166. function getLineList($post)
  167. {
  168. $page_size = isset($post['page_size']) ? trim($post['page_size']) : false;
  169. $current_page = isset($post['current_page']) ? trim($post['current_page']) : false;
  170. $line_code = isset($post['line_code']) ? (empty($post['line_code']) ? "''" : "'" . trim($post['line_code']) . "'") : false;
  171. $supply_id = isset($post['supply_id']) ? trim($post['supply_id']) : false;
  172. $line_status = isset($post['line_status']) ? trim($post['line_status']) : false;
  173. $line_type = isset($post['line_type']) ? trim($post['line_type']) : false;
  174. if (!$page_size || !$current_page || !$line_code || !$supply_id || !$line_type) {
  175. $json['code'] = '2';
  176. $json['info'] = '缺少必要参数';
  177. return $json;
  178. }
  179. $where['line_type'] = $line_type;
  180. $where['line_code'] = $line_code;
  181. $where['supply_id'] = $supply_id;
  182. $where['line_status'] = $line_status;
  183. $start_row = ($current_page - 1) * $page_size;
  184. $extra_sql = "";
  185. if (isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0) {
  186. $extra_sql .= ' AND ORG_ID IN( ' . $_COOKIE["opera_org_id"] . ' ) ';
  187. }
  188. if (isset($_COOKIE["user_main_corp"]) && mb_strlen($_COOKIE["user_main_corp"]) > 0 && $_COOKIE["user_main_corp"] > 0 ) {
  189. $extra_sql .= ' AND MAIN_CORP_ID IN( ' . $_COOKIE["user_main_corp"] . ' ) ';
  190. }
  191. $search_line_type = "l.line_type = " . $where['line_type'];
  192. if( $where['line_type'] == 255 ) {
  193. $search_line_type = "l.line_type IN (255,368) " ;//一日游线路
  194. }
  195. $sql = "SELECT
  196. l.line_id,l.line_code,l.line_name,
  197. IFNULL((SELECT type_name FROM dict_type WHERE id = l.line_sub_type),'') AS line_sub_type,
  198. IFNULL((SELECT supplier_name FROM base_supplier WHERE id = l.org_id ), '' ) AS org_name,
  199. CASE l.if_disabled WHEN 0 THEN '启用' ELSE '停用' END AS disabled_status,
  200. count(t.id) AS cnt
  201. FROM
  202. opera_line AS l LEFT JOIN
  203. (SELECT id,line_id FROM opera_tickets_group WHERE cancel_flag = 0) AS t
  204. ON l.line_id = t.line_id
  205. WHERE
  206. l.cancel_flag = 0
  207. AND {$search_line_type}
  208. 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'] . ",'%')))
  209. AND IF(TRIM(" . $where['supply_id'] . ")=-1,0=0,l.org_id = " . $where['supply_id'] . ")
  210. AND IF(TRIM(" . $where['line_status'] . ")=-1,0=0,l.if_disabled = " . $where['line_status'] . ")" . $extra_sql . "
  211. GROUP BY
  212. l.line_id,l.line_code,l.line_name,l.line_sub_type,l.org_id,l.if_disabled
  213. ORDER BY
  214. l.line_id DESC
  215. LIMIT " . $start_row . "," . $page_size;
  216. $line_list = $this->query($sql);
  217. if (count($line_list) == 0) {
  218. $json['code'] = '0';
  219. $json['info'] = '没有符合的线路';
  220. $json['line_list'] = array();
  221. $json['page']['page_size'] = $page_size;
  222. $json['page']['current_page'] = $current_page;
  223. $json['page']['total_count'] = '0';
  224. $json['page']['total_page'] = '0';
  225. return $json;
  226. }
  227. $count_sql = "SELECT
  228. count(line_id) as total_count
  229. FROM
  230. opera_line as l
  231. WHERE
  232. cancel_flag = 0
  233. AND {$search_line_type}
  234. AND IF(TRIM(" . $where['line_code'] . ")='',0=0,(line_code LIKE CONCAT('%'," . $where['line_code'] . ",'%') OR line_name LIKE CONCAT('%'," . $where['line_code'] . ",'%')))
  235. AND IF(TRIM(" . $where['supply_id'] . ")=-1,0=0,org_id = " . $where['supply_id'] . ")
  236. AND IF(TRIM(" . $where['line_status'] . ")=-1,0=0,if_disabled = " . $where['line_status'] . ") " . $extra_sql ;
  237. $total_count = $this->query($count_sql);
  238. $total_count = $total_count[0]['total_count'];
  239. $total_page = ceil($total_count / $page_size);
  240. $json['code'] = '0';
  241. $json['info'] = '返回线路列表成功符合的线路';
  242. $json['line_list'] = $line_list;
  243. $json['page']['page_size'] = $page_size;
  244. $json['page']['current_page'] = $current_page;
  245. $json['page']['total_count'] = $total_count;
  246. $json['page']['total_page'] = $total_page;
  247. return $json;
  248. }
  249. /**
  250. * @param line_id 线路id
  251. * @param line_name 线路名称
  252. * @param line_code 线路代码
  253. * @param line_type 线路类型1
  254. * @param line_sub_type 线路类型2
  255. * @param time_type 时间类型
  256. * @param time_info 时间
  257. * @param supply_id 供应商id
  258. * @param station_list 线路id 格式{上下车类型,站点顺序,到达用时,检票口,站点RES_ID,站点AREA_ID} 上下车类型: 108:上车 109:同时上下车 110:下客 114:不停靠;检票口目前默认都为0,如果有检票口需要在base_resource中配置
  259. * @return array|null
  260. * User: Steven
  261. */
  262. function lineUpdate($param)
  263. {
  264. $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);
  265. if (!$valid['status']) {
  266. $result['code'] = (string)$valid['status'];
  267. $result['info'] = $valid['info'];
  268. return $result;
  269. }
  270. $user_id = $this->user_id;
  271. $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'];
  272. $res_check = $this->query($sql_check);
  273. if (count($res_check) > 0) {
  274. $result['code'] = '3';
  275. $result['info'] = "线路编号已存在";
  276. return $result;
  277. }
  278. $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'] . "')";
  279. zzcsUtils::writeLog($sql);
  280. $result = $this->procQuery($sql);
  281. if ($result['code'] == 0) {
  282. $json['code'] = '0';
  283. $json['info'] = '修改线路成功';
  284. $json['line_id'] = $param['line_id'];
  285. $json['line_type'] = $param['line_type'];
  286. } else {
  287. $json['code'] = $result['code'];
  288. $json['info'] = $result['info'];
  289. }
  290. return $json;
  291. }
  292. /**
  293. * 单一线路启用
  294. * @param $param
  295. */
  296. function lineStart($param)
  297. {
  298. //hyk
  299. $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;
  300. if (!$line_id) {
  301. $json['code'] = '2';
  302. $json['info'] = '缺少必要参数';
  303. return $json;
  304. }
  305. $update_time = date('Y-m-d h:i:s');//更新时间
  306. $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";
  307. $result = $this->exec($sql);
  308. if ($result === false) {
  309. $json['code'] = '1';
  310. $json['info'] = '数据库异常';
  311. return $json;
  312. } else {
  313. $json['code'] = '0';
  314. $json['info'] = '更新成功';
  315. return $json;
  316. }
  317. }
  318. /**
  319. * 单一线路停用
  320. * @param $param
  321. */
  322. function lineStop($param)
  323. {
  324. //hyk
  325. $line_id = isset($param['line_id']) ? trim($param['line_id']) : false;
  326. if (!$line_id) {
  327. $json['code'] = '2';
  328. $json['info'] = '缺少必要参数';
  329. return $json;
  330. }
  331. $update_time = date('Y-m-d h:i:s');//更新时间
  332. $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";
  333. $result = $this->exec($sql);
  334. if ($result === false) {
  335. $json['code'] = '1';
  336. $json['info'] = '数据库异常';
  337. return $json;
  338. } else {
  339. $json['code'] = '0';
  340. $json['info'] = '更新成功';
  341. return $json;
  342. }
  343. }
  344. /**
  345. * 获取添加线路的基础信息
  346. * @param $param OK
  347. */
  348. function getBaseManager()
  349. {
  350. //1.售卖情况时间列表
  351. $time_type = $this->getTimeType();
  352. //2.巴士类型表
  353. $bus_type = $this->getBusType();
  354. //3.供应商列表
  355. $supply_list = $this->getSupply();
  356. $json['code'] = '0';
  357. $json['info'] = '返回数据成功';
  358. $json['bus_type'] = $bus_type;
  359. $json['supply_list'] = $supply_list;
  360. $json['time_type'] = $time_type;
  361. return $json;
  362. }
  363. /**
  364. * 获取全部站点
  365. * @param $param
  366. */
  367. function getLineStation($post)
  368. {
  369. $res_name = trim($post['res_name']);//输入框输入的站点信息
  370. $sql = "SELECT
  371. res_id,
  372. res_name
  373. FROM
  374. base_resource
  375. WHERE
  376. res_type_id = 24
  377. AND cancel_flag = 0
  378. AND res_name like '%" . $res_name . "%'";
  379. $res_list = $this->query($sql);//场站列表
  380. $json['code'] = '0';
  381. $json['info'] = '返回数据成功';
  382. $json['res_list'] = $res_list;
  383. return $json;
  384. }
  385. /**
  386. * 获取站点详情
  387. * @param $param
  388. */
  389. function getStationInfo($post)
  390. {
  391. $res_id = trim($post['res_id']);//站点id
  392. $check_area = "SELECT
  393. ifnull(area_id, 0) as area_id
  394. FROM
  395. base_resource
  396. WHERE
  397. res_id = " . $res_id;
  398. $area = $this->query($check_area);//场站列表
  399. if ($area[0]['area_id'] == 0) {
  400. $json['code'] = '1';
  401. $json['info'] = '该站点无应用POI,请先配置应用POI!';
  402. return $json;
  403. }
  404. //获取站点信息详情
  405. $station_info = "SELECT
  406. a.res_id,
  407. a.res_name,
  408. IFNULL(concat(b.parent_area_id_list,'{',b.area_id,'}'),'') AS parent_area_id_list,
  409. IFNULL(concat(b.parent_area_name_list,'{',b.area_name,'}'),'') AS parent_area_name_list,
  410. IFNULL(
  411. (
  412. SELECT
  413. group_concat(res_id)
  414. FROM
  415. base_resource
  416. WHERE
  417. res_type_id = 79
  418. AND cancel_flag = 0
  419. AND parent_id = a.res_id
  420. ),
  421. 0
  422. ) AS checkport_res_id,
  423. IFNULL(
  424. (
  425. SELECT
  426. group_concat(res_name)
  427. FROM
  428. base_resource
  429. WHERE
  430. res_type_id = 79
  431. AND cancel_flag = 0
  432. AND parent_id = a.res_id
  433. ),
  434. ''
  435. ) AS checkport_res_name
  436. FROM
  437. base_resource a
  438. LEFT JOIN base_area_view b ON a.area_id = b.area_id
  439. WHERE
  440. a.cancel_flag = 0
  441. AND a.res_id = " . $res_id;
  442. $res_info = $this->query($station_info);//场站详情
  443. $res_info = $res_info[0];
  444. $res_info['parent_area_id_list'] = substr($res_info['parent_area_id_list'], 1, -1);
  445. $res_info['parent_area_name_list'] = substr($res_info['parent_area_name_list'], 1, -1);
  446. $res_info['parent_area_id_list'] = explode("}{", $res_info['parent_area_id_list']);//应用POI站点id数组
  447. $res_info['parent_area_name_list'] = explode("}{", $res_info['parent_area_name_list']);//应用POI站点name数组
  448. $res_info['checkport_res_id'] = explode(",", $res_info['checkport_res_id']);//检票口id数组
  449. $res_info['checkport_res_name'] = explode(",", $res_info['checkport_res_name']);//检票口name数组
  450. //规整返回前端的站点数据
  451. $res = array();
  452. $res['res_id'] = $res_info['res_id'];
  453. $res['res_name'] = $res_info['res_name'];
  454. foreach ($res_info['parent_area_id_list'] as $k => $v) {
  455. $res['parent_area'][$k]['id'] = $v;
  456. $res['parent_area'][$k]['name'] = $res_info['parent_area_name_list'][$k];
  457. }
  458. foreach ($res_info['checkport_res_id'] as $k => $v) {
  459. $res['check_port'][$k]['id'] = $v;
  460. $res['check_port'][$k]['name'] = $res_info['checkport_res_name'][$k];
  461. }
  462. $res['inout_type'] = array(
  463. 0 => array(
  464. 'id' => '108',
  465. 'name' => '上'
  466. ),
  467. 1 => array(
  468. 'id' => '109',
  469. 'name' => '上下'
  470. ),
  471. 2 => array(
  472. 'id' => '110',
  473. 'name' => '下'
  474. )
  475. );
  476. $json['code'] = '0';
  477. $json['info'] = '返回数据成功';
  478. $json['res_info'] = $res;
  479. return $json;
  480. }
  481. }