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.
 
 
 
 

481 lines
23 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/11/3
  6. * Time: 15:23
  7. */
  8. class getGroupInfo extends base
  9. {
  10. /**
  11. * Function Description:查询直通车次订单信息
  12. * Function Name: getRunmsg
  13. * @param $param
  14. *
  15. * @return mixed
  16. *
  17. * @author 娄梦宁
  18. */
  19. public function getRunmsg($param)
  20. {
  21. //$run_date = isset($param['run_date']) ? $param['run_date'] : false;
  22. //$bus_num = isset($param['bus_num']) ? $param['bus_num'] : false;
  23. /*if (false === $run_date || false === $bus_num) {
  24. $json["code"] = "2";
  25. $json["info"] = "缺少必要参数";
  26. return $json;
  27. }*/
  28. $valid = zzcsUtils::validateParams(array('run_id,bus_num,product_id' => 'number'), $param); //参数验证
  29. if (!$valid['status']) {
  30. $result['code'] = (string)$valid['status'];
  31. $result['info'] = $valid['info'];
  32. return $result;
  33. }
  34. $run_date = isset($param['run_date']) ? $param['run_date'] : false;
  35. //判断日期格式正确
  36. $tmp_arr = explode('-', $run_date);
  37. $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期
  38. if (!$bool) {
  39. $json['code'] = '1';
  40. $json['info'] = '日期格式不正确';
  41. return $json;
  42. }
  43. $run_id = trim($param['run_id']);
  44. $bus_num = trim($param['bus_num']);
  45. $run_date = trim($param['run_date']);
  46. $product_id = $param['product_id'];
  47. //查询出该车次下所有的父订单(新)---温依莅
  48. $sql = "
  49. SELECT *,convert(x.trans_name using gbk) 't1',convert(x.start_station using gbk) 't2'
  50. from(
  51. SELECT
  52. a.order_id,
  53. a.customer_mobile as tel,
  54. (DATEDIFF('$run_date',a.prod_start_station_date)+1) as day,
  55. IFNULL((SELECT h.line_id FROM order_main g LEFT JOIN opera_line h ON g.parent_prod_id=h.line_id WHERE h.LINE_TYPE=256 and g.PARENT_ORDER_ID=a.order_id limit 1),'') AS tran_id,
  56. IFNULL((select res_name from base_resource where res_id=(select parent_id from base_resource where res_id=(SELECT p.prod_start_station_res_id FROM order_main p LEFT JOIN opera_line q ON p.parent_prod_id=q.line_id WHERE q.LINE_TYPE=256 AND p.PARENT_ORDER_ID=a.order_id limit 1))),'') as trans_name,
  57. IFNULL((SELECT o.run_bus_order_id FROM order_main o LEFT JOIN opera_line v ON o.parent_prod_id=v.line_id WHERE v.LINE_TYPE=255 AND o.PARENT_ORDER_ID=a.order_id and o.run_id=$run_id and o.RUN_BUS_ORDER_ID=$bus_num limit 1),'') AS run_bus_id,
  58. a.prod_start_station_res_name AS start_station,
  59. b.line_code AS line_codes,
  60. IFNULL(SUBSTRING_INDEX(a.order_description,'|',-1),0) AS num
  61. FROM
  62. order_main a LEFT JOIN opera_line b
  63. ON
  64. a.parent_prod_id = b.line_id
  65. WHERE
  66. CONCAT_WS('-',$run_id,$bus_num) in (SELECT CONCAT_WS('-',o.run_id,o.RUN_BUS_ORDER_ID) FROM order_main o LEFT JOIN opera_line v ON o.parent_prod_id=v.line_id WHERE v.LINE_TYPE=255 AND o.PARENT_ORDER_ID=a.order_id)
  67. AND a.order_valid_status=1 AND a.order_status<>148
  68. AND b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1
  69. ) x
  70. ORDER BY t1,t2;";
  71. //查询出该车次下所有的父订单(原)
  72. /*$sql = "select
  73. b.parent_prod_id as tran_id,
  74. a.order_id,
  75. substring_index(a.ORDER_DESCRIPTION,'|',-1) as num,
  76. c.line_code as line_codes,
  77. a.PROD_START_STATION_RES_NAME as start_station,
  78. b.RUN_BUS_ORDER_ID as run_bus_id,
  79. b.run_date,
  80. (DATEDIFF('$run_date',a.prod_start_station_date)+1) as day
  81. from
  82. order_main as a
  83. inner join
  84. order_main as b on a.order_id=b.PARENT_ORDER_ID
  85. INNER JOIN
  86. run_main as d on b.run_id=d.run_id
  87. left join
  88. opera_line c on a.PARENT_PROD_ID=c.line_id
  89. where d.PROD_ID=0 and b.run_date='" . $run_date . "' and a.CANCEL_FLAG=0 and b.CANCEL_FLAG=0 and b.RUN_BUS_ORDER_ID=$bus_num and b.ORDER_VALID_STATUS=1 and b.order_status!=148 and b.PARENT_PROD_ID in (select line_id from opera_line where line_type=255)
  90. GROUP BY a.order_id ";*/
  91. zzcsUtils::writeLog($sql);
  92. $runmsg = $this->query($sql);
  93. /*if (isset($runmsg[0]['run_date']) && isset($runmsg[0]['run_bus_id'])) {
  94. $rundate = $runmsg[0]['run_date'];
  95. $bus_num = $runmsg[0]['run_bus_id'];
  96. //查询同日期其他车次及余位
  97. $sql = "SELECT
  98. a.run_id,
  99. b.BUS_ORDER_ID AS run_bus_id,
  100. (b.seat_count - b.saled_count) AS stock,
  101. count(DISTINCT b.BUS_ORDER_ID) AS assist
  102. FROM
  103. `run_main` a
  104. LEFT JOIN run_bus b ON a.run_id = b.RUN_ID
  105. WHERE
  106. run_date = '" . $rundate . "'
  107. and a.prod_id = 0
  108. AND b.BUS_ORDER_ID !='$bus_num'
  109. and b.CANCEL_FLAG=0
  110. GROUP BY
  111. b.BUS_ORDER_ID;
  112. ";
  113. $othercar = $this->query($sql);
  114. }*/
  115. //处理得到今日组合订单 直通段车次信息
  116. $sql2 = "SELECT
  117. a.order_id,a.parent_order_id,a.run_id,b.BUS_ORDER_ID as run_bus_id,(b.seat_count - b.saled_count) AS stock
  118. FROM
  119. order_main a,run_bus b,
  120. opera_line c,run_main d
  121. WHERE
  122. a.run_id = b.run_id
  123. AND a.PARENT_PROD_ID = c.line_id
  124. AND b.run_id = d.run_id
  125. AND d.prod_id = 0
  126. AND d.run_date = '$run_date'
  127. AND c.line_type = 255
  128. AND b.cancel_flag = 0
  129. group by b.bus_order_id
  130. having $product_id=(SELECT l.product_type FROM opera_line l LEFT JOIN order_main m ON l.line_id = m.PARENT_PROD_ID WHERE m.order_id = a.PARENT_ORDER_ID limit 1);";
  131. $bus_info = $this->query($sql2);
  132. if (false === $bus_info) {
  133. $json['code'] = '1';
  134. $json['info'] = '数据库出错';
  135. $json['list'] = array();
  136. return $json;
  137. }
  138. //若查询无车次信息
  139. if (count($bus_info) == 0) {
  140. //这里如果尚未派车,无车次信息,则返回一个空的bus_info数组
  141. /*$json['code'] = '1';
  142. $json['info'] = '无符合条件的车次信息';
  143. $json['list'] = array();
  144. return $json;*/
  145. $bus_info = array();
  146. }
  147. /*if(count($runmsg)==0){
  148. $json['code'] = '1';
  149. $json['info'] = '返回班次订单信息失败';
  150. $json['list_order'] = $runmsg;
  151. return $json;
  152. }*/
  153. if (false === $runmsg) {
  154. $json['code'] = '1';
  155. $json['info'] = '返回班次人员信息失败';
  156. $json['list_bus'] = '';
  157. $json['list_order'] = $runmsg;
  158. return $json;
  159. } else {
  160. //处理run_bus_id返回值
  161. foreach ($runmsg as $k => $v) {
  162. if ($v['run_bus_id'] == 0) {
  163. $order_info[$k]['run_bus_id'] = '';
  164. }
  165. }
  166. $json['code'] = '0';
  167. $json['info'] = '返回班次人员信息成功';
  168. //$json['list_bus'] = $othercar;
  169. $json['list_bus'] = $bus_info;
  170. $json['list_order'] = $runmsg;
  171. return $json;
  172. }
  173. }
  174. /**
  175. * Function Description:查询接驳车次订单信息
  176. * Function Name: getTransmsg
  177. * @param $param
  178. *
  179. * @return mixed
  180. *
  181. * @author 温依莅
  182. */
  183. public function getTransmsg($param)
  184. {
  185. //$run_date = isset($param['run_date']) ? $param['run_date'] : false;
  186. //$bus_num = isset($param['bus_num']) ? $param['bus_num'] : false;
  187. /*if (false === $run_date || false === $bus_num) {
  188. $json["code"] = "2";
  189. $json["info"] = "缺少必要参数";
  190. return $json;
  191. }*/
  192. $valid = zzcsUtils::validateParams(array('run_id,bus_num,product_id' => 'number'), $param); //参数验证
  193. if (!$valid['status']) {
  194. $result['code'] = (string)$valid['status'];
  195. $result['info'] = $valid['info'];
  196. return $result;
  197. }
  198. $run_date = isset($param['run_date']) ? $param['run_date'] : false;
  199. //判断日期格式正确
  200. $tmp_arr = explode('-', $run_date);
  201. $bool = checkdate($tmp_arr[1], $tmp_arr[2], $tmp_arr[0]);//判断日期是否是合法日期
  202. if (!$bool) {
  203. $json['code'] = '1';
  204. $json['info'] = '日期格式不正确';
  205. return $json;
  206. }
  207. $run_id = trim($param['run_id']);
  208. $bus_num = trim($param['bus_num']);
  209. $run_date = trim($param['run_date']);
  210. $product_id = $param['product_id'];
  211. //查询出该车次下所有的父订单(新)---温依莅
  212. $sql = "
  213. SELECT *
  214. from(
  215. SELECT
  216. a.order_id,
  217. a.customer_mobile as tel,
  218. (DATEDIFF('$run_date',a.prod_start_station_date)+1) as day,
  219. IFNULL((SELECT h.line_id FROM order_main g LEFT JOIN opera_line h ON g.parent_prod_id=h.line_id WHERE h.LINE_TYPE=256 and g.PARENT_ORDER_ID=a.order_id limit 1),'') AS tran_id,
  220. IFNULL((select res_name from base_resource where res_id=if((select parent_id from base_resource where res_id=(SELECT p.prod_start_station_res_id FROM order_main p LEFT JOIN opera_line q ON p.parent_prod_id=q.line_id WHERE q.LINE_TYPE=256 AND p.PARENT_ORDER_ID=a.order_id and p.run_id=$run_id and p.RUN_BUS_ORDER_ID=$bus_num limit 1))=0,-1,(select parent_id from base_resource where res_id=(SELECT p.prod_start_station_res_id FROM order_main p LEFT JOIN opera_line q ON p.parent_prod_id=q.line_id WHERE q.LINE_TYPE=256 AND p.PARENT_ORDER_ID=a.order_id and p.run_id=$run_id and p.RUN_BUS_ORDER_ID=$bus_num limit 1)))),'') as trans_name,
  221. IFNULL((SELECT o.run_bus_order_id FROM order_main o LEFT JOIN opera_line v ON o.parent_prod_id=v.line_id WHERE v.LINE_TYPE=256 AND o.PARENT_ORDER_ID=a.order_id and o.run_id=$run_id and o.RUN_BUS_ORDER_ID=$bus_num limit 1),'') AS run_bus_id,
  222. a.prod_start_station_res_name AS start_station,
  223. b.line_code AS line_codes,
  224. IFNULL(SUBSTRING_INDEX(a.order_description,'|',-1),0) AS num
  225. FROM
  226. order_main a LEFT JOIN opera_line b
  227. ON
  228. a.parent_prod_id = b.line_id
  229. WHERE
  230. CONCAT_WS('-',$run_id,$bus_num) in (SELECT CONCAT_WS('-',o.run_id,o.RUN_BUS_ORDER_ID) FROM order_main o LEFT JOIN opera_line v ON o.parent_prod_id=v.line_id WHERE v.LINE_TYPE=256 AND o.PARENT_ORDER_ID=a.order_id)
  231. AND a.order_valid_status=1 AND a.order_status<>148
  232. AND b.line_type=316 AND b.cancel_flag=0 AND b.if_disabled=0 AND b.is_onsale=1
  233. ) x
  234. ORDER BY x.trans_name,x.start_station;";
  235. zzcsUtils::writeLog($sql);
  236. $runmsg = $this->query($sql);
  237. /*if (isset($runmsg[0]['run_date']) && isset($runmsg[0]['run_bus_id'])) {
  238. $rundate = $runmsg[0]['run_date'];
  239. $bus_num = $runmsg[0]['run_bus_id'];
  240. //查询同日期其他车次及余位
  241. $sql = "SELECT
  242. a.run_id,
  243. b.BUS_ORDER_ID AS run_bus_id,
  244. (b.seat_count - b.saled_count) AS stock,
  245. count(DISTINCT b.BUS_ORDER_ID) AS assist
  246. FROM
  247. `run_main` a
  248. LEFT JOIN run_bus b ON a.run_id = b.RUN_ID
  249. WHERE
  250. run_date = '" . $rundate . "'
  251. and a.prod_id = 0
  252. AND b.BUS_ORDER_ID !='$bus_num'
  253. and b.CANCEL_FLAG=0
  254. GROUP BY
  255. b.BUS_ORDER_ID;
  256. ";
  257. $othercar = $this->query($sql);
  258. }*/
  259. //处理得到今日组合订单 接驳段车次信息
  260. /*$sql2 = "select distinct b.run_id,
  261. b.run_bus_order_id as run_bus_id,
  262. (s.SEAT_COUNT-s.SALED_COUNT) AS stock
  263. from opera_tickets a, run_bus s,order_main b, opera_line l
  264. where a.ticket_id = b.prod_id
  265. and s.run_id = b.RUN_ID
  266. and s.bus_order_id = b.run_bus_order_id
  267. and b.parent_prod_id = l.LINE_ID
  268. and l.line_type = 256
  269. and l.cancel_flag =0
  270. and a.line_id in (select line_id from opera_line where line_type = 316 and product_type = $product_id and cancel_flag = 0)
  271. and b.run_date = '$run_date' order by b.run_bus_order_id,s.SEAT_COUNT;";*/
  272. $sql2 = "select b.run_id,
  273. b.bus_order_id as run_bus_id,
  274. (b.SEAT_COUNT-b.SALED_COUNT) AS stock
  275. from run_bus b left join
  276. run_main m on b.run_id = m.run_id
  277. where m.run_date = '$run_date' and b.group_line_flag = 1 and b.cancel_flag = 0 and m.prod_id > 0
  278. and b.run_id in (
  279. select distinct run_id from order_main where parent_order_id > 0 and prod_id in (select ticket_id from opera_tickets t, opera_line l where t.line_id = l.line_id and l.line_type = 316 and l.product_type = $product_id)
  280. ) order by b.bus_order_id";
  281. $bus_info = $this->query($sql2);
  282. if (false === $bus_info) {
  283. $json['code'] = '1';
  284. $json['info'] = '获取班次失败';
  285. $json['list'] = array();
  286. return $json;
  287. }
  288. //若查询无车次信息
  289. if (count($bus_info) == 0) {
  290. //这里如果尚未派车,无车次信息,则返回一个空的bus_info数组
  291. /*$json['code'] = '1';
  292. $json['info'] = '无符合条件的车次信息';
  293. $json['list'] = array();
  294. return $json;*/
  295. $bus_info = array();
  296. }
  297. if (false === $runmsg) {
  298. $json['code'] = '1';
  299. $json['info'] = '返回班次人员信息失败';
  300. $json['list_bus'] = '';
  301. $json['list_order'] = $runmsg;
  302. return $json;
  303. } else {
  304. //处理run_bus_id返回值
  305. foreach ($runmsg as $k => $v) {
  306. if ($v['run_bus_id'] == 0) {
  307. $order_info[$k]['run_bus_id'] = '';
  308. }
  309. }
  310. $json['code'] = '0';
  311. $json['info'] = '返回班次人员信息成功';
  312. //$json['list_bus'] = $othercar;
  313. $json['list_bus'] = $bus_info;
  314. $json['list_order'] = $runmsg;
  315. return $json;
  316. }
  317. }
  318. /**
  319. * Function Description:修改车次
  320. * Function Name: uptRunId
  321. * @param $param
  322. *
  323. * @return int
  324. *
  325. * @author 娄梦宁
  326. */
  327. public function uptRunId($param)
  328. {
  329. if (isset($param['orderid']) && isset($param['run_id']) && isset($param['p_num']) && isset($param['bus_num']) && isset($param['bus_ori_str']) && isset($param['alter_str'])) {
  330. //传入父订单ID,以英文逗号分隔
  331. $idstr = $param['orderid'];
  332. //要添加乘客的巴士班次
  333. $run_id = $param['run_id'];
  334. //源车次信息
  335. $bus_ori_str = $param['bus_ori_str'];
  336. //各订单人数信息
  337. $alter_str = $param['alter_str'];
  338. //已选择的人数
  339. $p_num = $param['p_num'];
  340. //要添加乘客的巴士车次号
  341. $bus_num = $param['bus_num'];
  342. $userid = $this->user_id;
  343. $uptdate = date("Y-m-d H:i:s", time());
  344. $ori_order_arr = explode(',', $idstr);
  345. $ori_bus_arr = explode(',', $bus_ori_str);
  346. $pure_bus_arr = array_filter($ori_bus_arr);//去掉类似z(j)线路没分车之前,车次为空的情况
  347. $pure_bus_str = implode(',', $pure_bus_arr);
  348. $alter_arr = explode(',', $alter_str);
  349. //此处根据run_id 判断是该run_id是组合线路的接驳段256还是直通段255--温依莅
  350. $sql = "select b.run_date,c.line_type from order_main a,run_main b,opera_line c where a.run_id=b.run_id and a.PARENT_PROD_ID=c.line_id and a.run_id=$run_id limit 1;";
  351. $temp = $this->query($sql);
  352. if (false === $temp) {
  353. $json['code'] = '1';
  354. $json['info'] = '获取失败';
  355. $json['list'] = array();
  356. return $json;
  357. } else if (count($temp) == 0) {
  358. $json['code'] = '1';
  359. $json['info'] = '无符合条件信息';
  360. $json['list'] = array();
  361. return $json;
  362. }
  363. $line_type = $temp[0]['line_type'];
  364. ##得到该run_id班次的出发日期,在下面人工干预时,对于两日行程的车次只干预当天的车次信息.
  365. $run_date = $temp[0]['run_date'];
  366. //此处检查该run_id,bus_order_id的车次run_bus_status 状态是否是138,如果不是表示不可再调整
  367. /*如果$pure_bus_arr非空,则判断;否则不判断,说明全是z(j)类型未分配的车次*/
  368. if (!empty($pure_bus_arr)) {
  369. $chk_run_sql = "select run_bus_status from run_bus where run_id=$run_id and BUS_ORDER_ID in ($pure_bus_str) limit 1;";
  370. $run_bus_status = $this->query($chk_run_sql);
  371. if ($run_bus_status[0]['run_bus_status'] != 138) {
  372. $json['code'] = '1';
  373. $json['info'] = '该班次已发车,不可修改';
  374. return $json;
  375. }
  376. }
  377. // //检查剩余座位是否大于已选择人数
  378. $sql = "select (seat_count-saled_count) as num1 from run_bus
  379. where run_id=" . $run_id . " and bus_order_id=$bus_num and cancel_flag=0 limit 1 ";
  380. $num = $this->query($sql);
  381. if ($num[0]['num1'] >= 1) {
  382. $seatnum = $num[0]['num1'];
  383. } else {
  384. $json['code'] = '1';
  385. $json['info'] = '剩余座位不够';
  386. return $json;
  387. }
  388. if ($p_num > $seatnum) {
  389. $json['code'] = '1';
  390. $json['info'] = '可用剩余座位不够';
  391. return $json;
  392. } else {
  393. //-----如果该订单z(j)类型没有在直通段派车(order_main相应直通段子订单无对应的run_bus_order_id值)
  394. #处理$idstr--订单集合 和 $bus_ori_str车次集合
  395. $sql = '';
  396. foreach ($ori_order_arr as $k => $v) {
  397. if ($ori_bus_arr[$k] == '') { //如果该订单尚未分配车次,则只增加新车次
  398. } else { //如果已分配车次,则去掉原车次的saled_count
  399. //操作成功后修改减员巴士已售座位
  400. $sql .= "UPDATE run_bus
  401. SET saled_count = (saled_count-" . $alter_arr[$k] . "),
  402. real_total_count = (real_total_count-" . $alter_arr[$k] . "),
  403. UPDATE_USER_ID=$userid,
  404. UPDATE_TIME='$uptdate'
  405. WHERE
  406. bus_order_id = " . $ori_bus_arr[$k] . " and run_id = $run_id;";
  407. }
  408. }
  409. //-----
  410. //操作成功后修改减员巴士已售座位
  411. /* $sql = "UPDATE run_bus
  412. SET saled_count = (saled_count-" . $p_num . "),
  413. real_total_count = (real_total_count-" . $p_num . "),
  414. UPDATE_USER_ID=$userid,
  415. UPDATE_TIME='$uptdate'
  416. WHERE
  417. bus_order_id = (
  418. SELECT DISTINCT
  419. run_bus_order_id
  420. FROM
  421. order_main
  422. WHERE
  423. parent_order_id in (" . $idstr . ")
  424. and run_date = (select DISTINCT run_date from order_main where run_id=$run_id)
  425. and PARENT_PROD_ID in (select line_id from opera_line where line_type=$line_type)
  426. ) and run_id = '$run_id';";*/
  427. //修改新增乘客巴士已售座位
  428. $sql .= "UPDATE run_bus
  429. SET saled_count = (saled_count +" . $p_num . "),
  430. real_total_count = (real_total_count +" . $p_num . "),
  431. UPDATE_USER_ID=$userid,
  432. UPDATE_TIME='$uptdate'
  433. WHERE
  434. run_id = " . $run_id . "
  435. and bus_order_id=$bus_num ;";
  436. //修改子订单以及车次号
  437. $sql .= "update order_main
  438. set
  439. RUN_ID=" . $run_id . ",
  440. RUN_BUS_ORDER_ID=" . $bus_num . ",
  441. UPDATE_USER_ID=$userid,
  442. UPDATE_TIME='$uptdate'
  443. where
  444. parent_order_id in (" . $idstr . ")
  445. and run_date ='$run_date'
  446. and PARENT_PROD_ID in (select line_id from opera_line where line_type=$line_type);";
  447. zzcsUtils::writeLog($sql);
  448. $uptsaled = $this->exec($sql);
  449. if ($uptsaled !== false) {
  450. $json['code'] = '0';
  451. $json['info'] = '修改成功';
  452. return $json;
  453. } else {
  454. $json['code'] = '2';
  455. $json['info'] = '修改巴士已售座位失败';
  456. return $json;
  457. }
  458. }
  459. } else {
  460. $json['code'] = '4';
  461. $json['info'] = '缺少必要参数';
  462. return $json;
  463. }
  464. }
  465. }