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.

groupLine.class.php 19 KiB

3 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/10/13
  6. * Time: 16:18
  7. * 组合线路票种相关
  8. */
  9. class groupLine extends base
  10. {
  11. /**
  12. * 获取产品线 所有用来拼接组合线路的单一线路 获取运营公司
  13. * @return mixed
  14. */
  15. function getProduct()
  16. {
  17. $res = $this->productLine(); //获取产品线
  18. $extra_sql = "";
  19. if( isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0 ) {
  20. $extra_sql .= ' AND ORG_ID IN( '.$_COOKIE["opera_org_id"].' ) ';
  21. }
  22. if (isset($_COOKIE["user_main_corp"]) && mb_strlen($_COOKIE["user_main_corp"]) > 0 && $_COOKIE["user_main_corp"] > 0 ) {
  23. $extra_sql .= ' AND MAIN_CORP_ID IN( '.$_COOKIE["user_main_corp"].' ) ';
  24. }
  25. //获取线路列表
  26. $sql1 = "SELECT line_id,line_name FROM opera_line WHERE CANCEL_FLAG=0 AND LINE_TYPE<>316".$extra_sql;
  27. $res_line = $this->query($sql1);
  28. if ($res_line) {
  29. $code = '0';
  30. $msg = "获取列表基本信息成功";
  31. } else {
  32. $code = '1';
  33. $msg = "获取列表基本信息失败";
  34. }
  35. $res_company = $this->getSupply(); //获取运营公司
  36. $result['code'] = (string)$code;
  37. $result['info'] = $msg;
  38. $result['product'] = $res;
  39. $result['res_line'] = $res_line;
  40. $result['company'] = $res_company;
  41. return $result;
  42. }
  43. /**
  44. * 根据line_id获取上车点
  45. * @param $param
  46. * @return mixed
  47. */
  48. public function getStartByLine($param)
  49. {
  50. $line_id = isset($param['line_id']) ? $param['line_id'] : false;
  51. if (false === $line_id) {
  52. $result['code'] = '2';
  53. $result['info'] = "缺少必要参数";
  54. return $result;
  55. }
  56. if ($line_id == -1) { //处理提交的上车站点是“请选择”选项
  57. $result['code'] = '0';
  58. $result['info'] = "请选择上车站点";
  59. $result['station'] = array();
  60. return $result;
  61. }
  62. //sql:根据线路ID查询可行的上车点(站点和应用poi) 其中res_id=(站点或应用POI标记,站点ID) 0:不限;1:站点ID; 2:应用POI
  63. $sql = "SELECT concat(1,',',a.res_id) as res_id,
  64. b.res_name
  65. FROM opera_station a left join
  66. base_resource b on a.res_id = b.res_id and b.res_type_id = 24
  67. WHERE a.CANCEL_FLAG=0 AND a.LINE_ID=$line_id AND a.INOUT_TYPE in(108,109)
  68. union all
  69. SELECT distinct concat(2,',',a.area_id) as res_area_flag,
  70. b.area_name
  71. FROM opera_station a left join
  72. base_area b on a.area_id = b.id
  73. WHERE a.CANCEL_FLAG=0 AND a.LINE_ID=$line_id AND a.INOUT_TYPE in(108,109)";
  74. $res = $this->query($sql);
  75. array_unshift($res, array('res_id' => '0,0', 'res_name' => '不限')); //给数组的开头插入一个元素
  76. if ($res) {
  77. $code = 0;
  78. $msg = '获取' . $line_id . '线路对应上车站成功';
  79. } else {
  80. $code = 1;
  81. $msg = '获取' . $line_id . '线路对应上车站失败';
  82. }
  83. $result['code'] = (string)$code;
  84. $result['info'] = $msg;
  85. $result['station'] = $res;
  86. return $result;
  87. }
  88. /**
  89. * 根据上车站获取下车站点
  90. * @param $param
  91. * @return mixed
  92. */
  93. public function getEndStation($param)
  94. {
  95. $para_line_id = isset($param['line_id']) ? $param['line_id'] : false;
  96. $res_id = isset($param['res_id']) ? $param['res_id'] : false;
  97. if ($para_line_id === false || $res_id === false) {
  98. $result['code'] = '2';
  99. $result['info'] = "缺少必要参数";
  100. return $result;
  101. }
  102. if ($res_id == -1) {
  103. $result['code'] = '0';
  104. $result['info'] = "请选择上车站点";
  105. return $result;
  106. }
  107. $para = explode(",", $res_id);
  108. $para_flag = $para[0];
  109. $para_start_id = $para[1];
  110. $sql = "CALL SP_GET_END_STATION($para_line_id,$para_flag,$para_start_id)";
  111. zzcsUtils::writeLog($sql);
  112. $res = $this->procQuery($sql);
  113. if ($res['code'] != 0) { //存储过程执行出错
  114. $json["code"] = (string)$res['code'];
  115. $json["info"] = $res['info'];
  116. return $json;
  117. }
  118. //数据查询成功
  119. $json["code"] = '0';
  120. $json["info"] = '下车站点获取成功';
  121. $json["station"] = $res['data'][0];
  122. return $json;
  123. }
  124. /**
  125. * 添加组合线路
  126. * @param $param
  127. * @return mixed
  128. */
  129. public function addGroupLine($param)
  130. {
  131. //{行程第几日,第几条,线路ID,出发站点或应用POI标志,出发res_id,目的站点或应用POI标志,目的RES_ID,出发时间} 站点或应用POI标志: 1:站点 2:应用POI, 出发时间需要换算成距离0点的分钟数
  132. $user_id = $this->user_id;
  133. $line_name = isset($param['line_name']) ? $param['line_name'] : false; //线路名称
  134. $line_code = isset($param['line_code']) ? $param['line_code'] : false; //线路编号
  135. $producttype = isset($param['product_type']) ? $param['product_type'] : false; //产品线
  136. $expiredtype = isset($param['expired_type']) ? $param['expired_type'] : false; //售卖截止类型
  137. $expiredtime = isset($param['expired_time']) ? $param['expired_time'] : false; //售卖截止时间
  138. $orgid = isset($param['org_id']) ? $param['org_id'] : false; //运营公司
  139. $station_list = isset($param['station_list']) ? $param['station_list'] : false; //行程字符串
  140. if ($line_name === false || $line_code === false || $producttype === false || $expiredtype === false || $expiredtime === false || $orgid === false || $station_list === false) {
  141. $result['code'] = '2';
  142. $result['info'] = "缺少必要参数";
  143. return $result;
  144. }
  145. $sql_check = 'SELECT line_id count from opera_line WHERE cancel_flag = 0 AND LINE_CODE=\'' . $line_code . '\'';
  146. $res_check = $this->query($sql_check);
  147. if (count($res_check) > 0) {
  148. $result['code'] = '3';
  149. $result['info'] = "线路编号已存在";
  150. return $result;
  151. }
  152. $station_list = str_replace("},", "}", $station_list);
  153. $sql = "CALL SP_ADD_LINE_GROUP(" . $user_id . ",'" . $line_name . "','" . $line_code . "'," . $producttype . "," . $expiredtype . ",'" . $expiredtime . "','" . $orgid . "','" . $station_list . "')";
  154. zzcsUtils::writeLog($sql);
  155. $res = $this->procQuery($sql);
  156. if ($res['code'] != 0) //存储过程执行出错
  157. {
  158. $result['code'] = (string)$res['code'];
  159. $result['info'] = $res['info'];
  160. return $result;
  161. }
  162. $result['code'] = '0';
  163. $result['info'] = '组合线路添加成功';
  164. $result['line_id'] = $res['data'][0][0]['line_id'];
  165. return $result;
  166. }
  167. /**
  168. * 根据line_id获取组合线路基本信息
  169. * @param $param
  170. * @return string
  171. */
  172. public function getGroupLineByID($param)
  173. {
  174. $line_id = isset($param['line_id']) ? $param['line_id'] : false;
  175. if ($line_id === false) {
  176. $result['code'] = '2';
  177. $result['info'] = "缺少必要参数";
  178. return $result;
  179. }
  180. //sql:根据线路ID 获取组合线路的基本信息
  181. $sql = "SELECT a.line_id,b.line_name,b.line_code,b.product_type,c.max_day_num,b.org_id,b.sale_expired_type,b.sale_expired_time,a.sub_line_id,a.day_num,a.seq_id,a.start_choice_flag,a.start_res_id,a.start_area_id,a.end_choice_flag,a.end_order_id,a.end_res_id,a.end_area_id,a.start_time,a.start_minutes
  182. FROM opera_line_group a,opera_line b,(select line_id,max(day_num) as max_day_num from opera_line_group group by line_id) c
  183. WHERE a.line_id = b.line_id and a.line_id = c.line_id AND a.LINE_ID = $line_id ORDER BY DAY_NUM,SEQ_ID";
  184. $res = $this->query($sql);
  185. $arr = array();
  186. if (!$res) {
  187. $result['code'] = '1';
  188. $result['info'] = "获取{$line_id}线路基本信息失败";
  189. }
  190. $arr['line_id'] = $res[0]['line_id']; //线路ID
  191. $arr['line_name'] = $res[0]['line_name']; //线路名称
  192. $arr['line_code'] = $res[0]['line_code'];//线路代码
  193. $arr['product_type'] = $res[0]['product_type']; //产品线
  194. $arr['max_day_num'] = $res[0]['max_day_num']; //行程
  195. $arr['org_id'] = $res[0]['org_id']; //运营公司
  196. $arr['sale_expired_type'] = $res[0]['sale_expired_type']; //售卖截止类型
  197. $arr['sale_expired_time'] = $res[0]['sale_expired_time']; //售卖截止时间
  198. foreach ($res as $k => $v) {
  199. $line['day_num'] = $v['day_num']; //第几天
  200. $line['seq_id'] = $v['seq_id']; //顺序
  201. $line['sub_line_id'] = $v['sub_line_id']; //组合线路的实际线路ID
  202. #region 根据线路ID获取上车站点列表
  203. $param_line_id['line_id'] = $v['sub_line_id'];
  204. $base_start_station = $this->getStartByLine($param_line_id);
  205. $line['start_station'] = $base_start_station['station'];
  206. #endregion
  207. $line['start_time'] = $v['start_time']; //出发时间
  208. //出发站点 start_choice_flag 区分是站点还是应用POI start_res_id=站点类型,站点ID; 站点类型:0:不限;1:站点ID 2:应用POI
  209. $line['start_res_id'] = ($v['start_choice_flag'] == 0) ? '0,0' : (($v['start_choice_flag'] == 1) ? ($v['start_choice_flag'] . ',' . $v['start_res_id']) : (($v['start_choice_flag'] == 2) ? ($v['start_choice_flag'] . ',' . $v['start_area_id']) : 0)); //出发站点 start_choice_flag 区分是站点还是应用POI 1:选择站点, 2:选择应用POI
  210. #region 根据线路ID和上车站点获取下车站点列表
  211. $param_res['line_id'] = $v['sub_line_id'];
  212. $param_res['res_id'] = $line['start_res_id'];
  213. $end_station = $this->getEndStation($param_res);
  214. $line['end_station'] = $end_station['station'];
  215. #endregion
  216. //目的地站点 start_choice_flag 区分是站点还是应用POI end_res_id=站点类型,站点ID; 站点类型:1:站点ID 2:应用POI
  217. //$line['end_res_id'] = ($v['end_choice_flag'] == 0) ? '0,0' : (($v['end_choice_flag'] == 1) ? ($v['end_choice_flag'] . ',' . $v['end_res_id']) : (($v['end_choice_flag'] == 2) ? ($v['end_choice_flag'] . ',' . $v['end_area_id']) : 0)); //目的地站点
  218. $line['end_res_id'] = ($v['end_choice_flag'] == 1) ? $v['end_choice_flag'] . ',' . $v['end_res_id'] : (($v['end_choice_flag'] == 2) ? $v['end_choice_flag'] . ',' . $v['end_area_id'] : 0);
  219. $arr['line']["{$v['day_num']}"][] = $line;
  220. }
  221. $sql1 = "SELECT line_id,line_name FROM opera_line WHERE CANCEL_FLAG=0 AND LINE_TYPE<>316"; //获取线路列表
  222. $res_line = $this->query($sql1);
  223. $result['code'] = '0';
  224. $result['info'] = "获取{$line_id}线路基本信息成功";
  225. $result['line_info'] = $arr;
  226. //其他基本信息
  227. $result['res_line'] = $res_line; //获取线路
  228. $result['product'] = $this->productLine(); //获取产品线
  229. $result['company'] = $this->getSupply(); //获取运营公司/
  230. return $result;
  231. }
  232. /**
  233. * 组合线路基本信息的修改
  234. * @param $param
  235. * @return string
  236. */
  237. public function updateGroupLine($param)
  238. {
  239. //{行程第几日,第几条,线路ID,出发站点或应用POI标志,出发res_id,目的站点或应用POI标志,目的RES_ID,出发时间} 站点或应用POI标志: 1:站点 2:应用POI, 出发时间需要换算成距离0点的分钟数
  240. $line_id = isset($param['line_id']) ? $param['line_id'] : false; //线路
  241. $line_name = isset($param['line_name']) ? $param['line_name'] : false; //线路名称
  242. $line_code = isset($param['line_code']) ? $param['line_code'] : false; //线路编号
  243. $producttype = isset($param['product_type']) ? $param['product_type'] : false; //产品线
  244. $expiredtype = isset($param['expired_type']) ? $param['expired_type'] : false; //售卖截止类型
  245. $expiredtime = isset($param['expired_time']) ? $param['expired_time'] : false; //售卖截止时间
  246. $orgid = isset($param['org_id']) ? $param['org_id'] : false; //运营公司
  247. $station_list = isset($param['station_list']) ? $param['station_list'] : false; //行程字符串
  248. if ($line_name === false || $line_code === false || $producttype === false || $expiredtype === false || $expiredtime === false || $orgid === false || $station_list === false) {
  249. $result['code'] = '2';
  250. $result['info'] = "缺少必要参数";
  251. return $result;
  252. }
  253. $sql_check = 'SELECT line_id count from opera_line WHERE cancel_flag = 0 AND LINE_CODE=\'' . $line_code . '\' AND LINE_ID<>' . $line_id;
  254. $res_check = $this->query($sql_check);
  255. if (count($res_check) > 0) {
  256. $result['code'] = '3';
  257. $result['info'] = "线路编号已存在";
  258. return $result;
  259. }
  260. $station_list = str_replace("},", "}", $station_list);
  261. //station_list 格式{行程第几日,线路ID,出发站点或应用POI标志,出发res_id,目的站点或应用POI标志,目的RES_ID,出发时间} 站点或应用POI标志: 1:站点 2:应用POI, 出发时间需要换算成距离0点的分钟数
  262. $sql = "CALL sp_update_line_group(" . $this->user_id . "," . $line_id . ",'" . $line_name . "','" . $line_code . "'," . $producttype . "," . $expiredtype . ",'" . $expiredtime . "','" . $orgid . "','" . $station_list . "')";
  263. zzcsUtils::writeLog($sql);
  264. $res = $this->procQuery($sql);
  265. if ($res['code'] != 0) { //存储过程执行出错
  266. $result['code'] = (string)$res['code'];
  267. $result['info'] = $res['info'];
  268. return $result;
  269. }
  270. $result['code'] = '0';
  271. $result['info'] = '组合线路修改成功';
  272. return $result;
  273. }
  274. /**
  275. * 张帅
  276. * 组合线路线路列表
  277. */
  278. public function getLineList($post)
  279. {
  280. $page_size = isset($post['page_size']) ? trim($post['page_size']) : false;
  281. $current_page = isset($post['current_page']) ? trim($post['current_page']) : false;
  282. $line_code = isset($post['line_code']) ? (empty($post['line_code']) ? "''" : "'" . trim($post['line_code']) . "'") : false;
  283. $supply_id = isset($post['supply_id']) ? trim($post['supply_id']) : false;
  284. $line_status = isset($post['line_status']) ? trim($post['line_status']) : false;
  285. $line_type = isset($post['line_type']) ? trim($post['line_type']) : false;
  286. $product_type = isset($post['product_type']) ? trim($post['product_type']) : false;
  287. $start_row = ($current_page - 1) * $page_size;
  288. if ($page_size === false || $current_page === false || $line_code === false || $supply_id === false || $line_type === false || $product_type === false) {
  289. $json['code'] = '2';
  290. $json['info'] = '缺少必要参数';
  291. return $json;
  292. }
  293. $extra_sql = "";
  294. if( isset($_COOKIE["opera_org_id"]) && mb_strlen($_COOKIE["opera_org_id"]) > 0 ) {
  295. $extra_sql .= ' AND l.org_id IN( '.$_COOKIE["opera_org_id"].' ) ';
  296. }
  297. if (isset($_COOKIE["user_main_corp"]) && mb_strlen($_COOKIE["user_main_corp"]) > 0 && $_COOKIE["user_main_corp"] > 0 ) {
  298. $extra_sql .= ' AND MAIN_CORP_ID IN( ' . $_COOKIE["user_main_corp"] . ' ) ';
  299. }
  300. $sql = "SELECT
  301. l.line_id,l.line_code,l.line_name,l.product_type,
  302. (SELECT type_name FROM dict_type WHERE id = l.product_type) as product_type_name,
  303. IFNULL((SELECT type_name FROM dict_type WHERE id = l.line_sub_type),'') AS line_sub_type,
  304. IFNULL((SELECT supplier_name FROM base_supplier WHERE id = l.org_id ), '' ) AS org_name,
  305. CASE l.if_disabled WHEN 0 THEN '启用' ELSE '停用' END AS disabled_status,
  306. count(t.ticket_id) AS cnt
  307. FROM
  308. opera_line AS l LEFT JOIN
  309. (SELECT ticket_id,line_id FROM opera_tickets WHERE cancel_flag = 0) AS t
  310. ON l.line_id = t.line_id
  311. WHERE
  312. l.cancel_flag = 0
  313. AND l.line_type = " . $line_type . "
  314. AND IF(TRIM(" . $line_code . ")='',0=0,(l.line_code LIKE CONCAT('%'," . $line_code . ",'%') OR l.line_name LIKE CONCAT('%'," . $line_code . ",'%')))
  315. AND IF(TRIM(" . $supply_id . ")=-1,0=0,l.org_id = " . $supply_id . ")
  316. AND IF(TRIM(" . $product_type . ")=-1,0=0,l.product_type = " . $product_type . ")
  317. AND IF(TRIM(" . $line_status . ")=-1,0=0,l.if_disabled = " . $line_status . ")".$extra_sql."
  318. GROUP BY
  319. l.line_id,l.line_code,l.line_name,l.line_sub_type,l.org_id,l.if_disabled
  320. ORDER BY
  321. l.line_id DESC
  322. LIMIT " . $start_row . "," . $page_size;
  323. $line_list = $this->query($sql);
  324. if (count($line_list) == 0) {
  325. $json['code'] = '0';
  326. $json['info'] = '没有符合的线路';
  327. $json['line_list'] = array();
  328. $json['page']['page_size'] = $page_size;
  329. $json['page']['current_page'] = $current_page;
  330. $json['page']['total_count'] = '0';
  331. $json['page']['total_page'] = '0';
  332. return $json;
  333. }
  334. $count_sql = "SELECT
  335. count(line_id) as total_count
  336. FROM
  337. opera_line
  338. WHERE
  339. cancel_flag = 0
  340. AND line_type = " . $line_type . "
  341. AND IF(TRIM(" . $line_code . ")='',0=0,(line_code LIKE CONCAT('%'," . $line_code . ",'%') OR line_name LIKE CONCAT('%'," . $line_code . ",'%')))
  342. AND IF(TRIM(" . $supply_id . ")=-1,0=0,org_id = " . $supply_id . ")
  343. AND IF(TRIM(" . $product_type . ")=-1,0=0,product_type = " . $product_type . ")
  344. AND IF(TRIM(" . $line_status . ")=-1,0=0,if_disabled = " . $line_status . ") ".$extra_sql;
  345. zzcsUtils::writeLog($count_sql);
  346. $total_count = $this->query($count_sql);
  347. $total_count = $total_count[0]['total_count'];
  348. $total_page = ceil($total_count / $page_size);
  349. $json['code'] = '0';
  350. $json['info'] = '返回线路列表成功符合的线路';
  351. $json['line_list'] = $line_list;
  352. $json['page']['page_size'] = (string)$page_size;
  353. $json['page']['current_page'] = (string)$current_page;
  354. $json['page']['total_count'] = (string)$total_count;
  355. $json['page']['total_page'] = (string)$total_page;
  356. return $json;
  357. }
  358. }