25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

466 lines
19 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 张帅
  5. * Date: 2016/10/12
  6. * Time: 14:30
  7. */
  8. class singleTicket extends base
  9. {
  10. /**
  11. * 获取单一线路票种列表
  12. * @param $param
  13. * @return mixed
  14. */
  15. public function getTicketList($param)
  16. {
  17. $line_id = isset($param['line_id'])?trim($param['line_id']):false;//152251
  18. $page_size = isset($param['page_size'])?trim($param['page_size']):false;
  19. $current_page = isset($param['current_page'])?trim($param['current_page']):false;
  20. $start_row = ($current_page-1)*$page_size;
  21. if(!$line_id || !$page_size || !$current_page)
  22. {
  23. $json['code'] = '2';
  24. $json['info'] = '缺少必要参数';
  25. return $json;
  26. }
  27. $sql = "SELECT
  28. id as group_id,
  29. ticket_id,
  30. station_id,
  31. station_name,
  32. seat_type,
  33. (SELECT type_name FROM dict_type WHERE id = seat_type) AS seat_type_name,
  34. human_type,
  35. (SELECT type_name FROM dict_type WHERE id = human_type ) AS human_type_name,
  36. prod_price,
  37. cus_price
  38. FROM
  39. opera_tickets_group
  40. WHERE
  41. line_id = " . $line_id . "
  42. AND cancel_flag = 0
  43. LIMIT " . $start_row . "," . $page_size;
  44. $res = $this->query($sql);
  45. if(count($res) == 0)
  46. {
  47. $json['code'] = '0';
  48. $json['info'] = '无票种信息';
  49. $json['ticket_list'] = array();
  50. $json['page']['page_size'] = $page_size;
  51. $json['page']['current_page'] = $current_page;
  52. $json['page']['total_count'] = '0';
  53. $json['page']['total_page'] = '0';
  54. return $json;
  55. }
  56. $count_sql = "SELECT
  57. count(id) as total_count
  58. FROM
  59. opera_tickets_group
  60. WHERE
  61. line_id = " . $line_id . "
  62. AND cancel_flag = 0";
  63. $total_count = $this->query($count_sql);
  64. $total_count = $total_count[0]['total_count'];
  65. $total_page = ceil($total_count/$page_size);
  66. $json['code'] = '0';
  67. $json['info'] = '返回促销规则列表成功';
  68. $json['ticket_list'] = $res;
  69. $json['page']['page_size'] = $page_size;
  70. $json['page']['current_page'] = $current_page;
  71. $json['page']['total_count'] = $total_count;
  72. $json['page']['total_page'] = $total_page;
  73. return $json;
  74. }
  75. /**
  76. * 获取票种配置信息
  77. */
  78. public function getTicketBase($param)
  79. {
  80. //获取上下车可配置上车站点数据
  81. $line_id = trim($param['line_id']);//152251
  82. if(!$line_id)
  83. {
  84. $json['code'] = '2';
  85. $json['info'] = '缺少必要参数';
  86. return $json;
  87. }
  88. $sql = "SELECT
  89. res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name,order_id
  90. FROM
  91. opera_station AS s
  92. WHERE
  93. line_id = " . $line_id . "
  94. AND inout_type in (108,109)
  95. AND cancel_flag = 0
  96. GROUP BY res_id";
  97. $start_res = $this->query($sql);
  98. //获取座位类型
  99. $base_seat = array(72);
  100. $seat_type_result = $this->getSeat();
  101. foreach($seat_type_result as $k => $v)
  102. {
  103. if(in_array($v['id'],$base_seat))
  104. {
  105. $seat_type[] = $v;
  106. }
  107. }
  108. //获取人群属性
  109. // $base_human_type = array(159,160,161);
  110. // $human_type_result = $this->getPeopleType();
  111. $human_type = array(array('id' => '0','type_name' => '不限'));
  112. // foreach($human_type_result as $k => $v)
  113. // {
  114. // if(in_array($v['id'],$base_human_type))
  115. // {
  116. // $human_type[] = $v;
  117. // }
  118. // }
  119. $json['code'] = '0';
  120. $json['info'] = '获取票种配置成功';
  121. $json['start_res'] = $start_res;
  122. $json['seat_type'] = $seat_type;
  123. $json['human_type'] = $human_type;
  124. return $json;
  125. }
  126. /**
  127. *获取下车站点信息
  128. */
  129. public function getTicketEndStation($param)
  130. {
  131. $line_id = isset($param['line_id'])?trim($param['line_id']):false;//线路ID
  132. $start_res_id = isset($param['start_res_id'])?trim($param['start_res_id']):false;//出发站ID
  133. if($line_id===false || $start_res_id === false )
  134. {
  135. $json['code'] = '2';
  136. $json['info'] = '缺少必要参数';
  137. return $json;
  138. }
  139. if(empty($line_id) || empty($start_res_id))
  140. {
  141. $json['code'] = '2';
  142. $json['info'] = '部分参数为空';
  143. return $json;
  144. }
  145. $sql = "SELECT
  146. order_id,res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name
  147. FROM
  148. opera_station as s
  149. WHERE
  150. line_id = " . $line_id . "
  151. AND order_id > (SELECT order_id FROM opera_station WHERE line_id = s.line_id AND res_id = " . $start_res_id . " AND cancel_flag = 0 LIMIT 1)
  152. AND inout_type IN (109, 110)
  153. AND res_id != " . $start_res_id . "
  154. AND cancel_flag = 0
  155. GROUP BY
  156. res_id";
  157. $end_res = $this->query($sql);
  158. $json['code'] = '0';
  159. $json['info'] = '获取下车站点成功';
  160. $json['end_res'] = $end_res;
  161. return $json;
  162. }
  163. /**
  164. * 添加票种信息
  165. * @param $param
  166. * @return mixed
  167. */
  168. public function addTicket($param)
  169. {
  170. //存储过程:SP_SAVE_LINE_TICKET_XM
  171. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  172. $station_str = isset($param['station_str'])?trim($param['station_str']):false;
  173. $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false;
  174. $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false;
  175. $seat_type = isset($param['seat_type'])?trim($param['seat_type']):false;
  176. $human_type = isset($param['human_type'])?trim($param['human_type']):false;
  177. $human_type=159;
  178. $line_type = 1;
  179. $user_id = $this->user_id;
  180. $create_time = date("Y-m-d H:i:s",time());
  181. if(!$line_id || $station_str === false || $prod_price === false || $cus_price === false || $seat_type === false || $human_type === false)
  182. {
  183. $json['code'] = '2';
  184. $json['info'] = '缺少必要参数';
  185. return $json;
  186. }
  187. if(empty($line_id) || empty($station_str) || empty($prod_price) || empty($cus_price) || empty($seat_type) || empty($human_type) )
  188. {
  189. $json['code'] = '2';
  190. $json['info'] = '部分参数为空';
  191. return $json;
  192. }
  193. $ticket_name_sql = "select type_name from dict_type where id = " . $seat_type;
  194. $ticket_name = $this->query($ticket_name_sql);
  195. $ticket_name = $ticket_name[0]['type_name'] . "票";
  196. //获取最大的ticket_id
  197. $ticket_id_sql = "select ifnull(max(ticket_id),0) as ticket_id from opera_tickets";
  198. $ticket_id = $this->query($ticket_id_sql);
  199. $ticket_id = $ticket_id[0]['ticket_id'];
  200. $station_str = substr($station_str,1,-1);
  201. $station_array = explode("}{",$station_str);
  202. //获取检验是否存在票种的查询条件
  203. foreach($station_array as $k => $v)
  204. {
  205. $res_group = explode(",",$v);
  206. //获取所有的站点id;
  207. $res_array[$res_group[0]] = $res_group[0];
  208. $res_array[$res_group[1]] = $res_group[1];
  209. $check_arr[] = "(start_station_res_id = " . $res_group[0] . " and end_station_res_id = " . $res_group[1] . ")";
  210. }
  211. $check_str = "(" . implode(" or ",$check_arr) . ")";
  212. //检查是否存在已添加的票种
  213. $check_sql = "SELECT
  214. start_station_res_id,
  215. (SELECT res_name FROM base_resource WHERE res_id = t.start_station_res_id) as start_station_res_name,
  216. end_station_res_id,
  217. (SELECT res_name FROM base_resource WHERE res_id = t.end_station_res_id) as end_station_res_name
  218. FROM
  219. opera_tickets as t
  220. WHERE
  221. line_id = " . $line_id . "
  222. AND cancel_flag = 0
  223. AND seat_type = " . $seat_type . "
  224. AND human_type = " . $human_type . "
  225. AND " . $check_str;
  226. $check_ticket = $this->query($check_sql);
  227. if(count($check_ticket) > 0)
  228. {
  229. foreach($check_ticket as $k => $v)
  230. {
  231. $info_array[] = $v['start_station_res_name'] . "-" . $v['end_station_res_name'];
  232. }
  233. $json['code'] = '1';
  234. $json['info'] = implode(",",$info_array) . "的该人群及座位等级已添加过,添加失败";
  235. return $json;
  236. }
  237. //查询所有站点ID的area_id
  238. $area_sql = "SELECT
  239. area_id,
  240. res_id
  241. FROM
  242. opera_station
  243. WHERE
  244. line_id = " . $line_id . "
  245. AND res_id in (" . implode(",",$res_array) . ")
  246. AND cancel_flag = 0";
  247. $res_area = $this->query($area_sql);
  248. //查询所有的站点名称
  249. $area_sql = "SELECT
  250. res_id,
  251. res_name
  252. FROM
  253. base_resource
  254. WHERE
  255. res_id in (" . implode(",",$res_array) . ")
  256. AND cancel_flag = 0";
  257. $res_name = $this->query($area_sql);
  258. foreach ($res_area as $k => $v)
  259. {
  260. $res_area_array[$v['res_id']] = $v['area_id'];
  261. }
  262. foreach ($res_name as $k => $v)
  263. {
  264. $res_name_array[$v['res_id']] = $v['res_name'];
  265. }
  266. $insert_ticket_sql = "INSERT INTO opera_tickets (
  267. ticket_id,
  268. create_user_id,
  269. create_time,
  270. update_user_id,
  271. cancel_flag,
  272. line_id,
  273. ticket_name,
  274. ticket_type,
  275. start_station_res_id,
  276. end_station_res_id,
  277. start_station_area_id,
  278. end_station_area_id,
  279. seat_type,
  280. human_type,
  281. prod_price,
  282. cus_price
  283. )
  284. VALUES ";
  285. foreach($station_array as $k => $v)
  286. {
  287. $ticket_id ++;
  288. $ticket_group[] = $ticket_id;
  289. $station_res_group = explode(",",$v);
  290. $station_id_group[] = $station_res_group[0] . "-" . $station_res_group[1];//站点联系组合
  291. $station_name_group[] = $res_name_array[$station_res_group[0]] . "-" . $res_name_array[$station_res_group[1]];//站点名称联系组合
  292. $ticket_sql_array[] = "(" . $ticket_id . "," . $user_id . ",'" . $create_time . "'," . $user_id . ",0," . $line_id . ",'" . $ticket_name . "',1," . $station_res_group[0] . "," . $station_res_group[1] . "," . $res_area_array[$station_res_group[0]] . "," . $res_area_array[$station_res_group[1]] . "," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "')";
  293. }
  294. $ticket_sql = implode(",",$ticket_sql_array);
  295. $insert_ticket_sql .= $ticket_sql;
  296. //添加票种分组
  297. $insert_ticket_group_sql = "INSERT INTO opera_tickets_group (
  298. create_user_id,
  299. create_time,
  300. update_user_id,
  301. update_time,
  302. cancel_flag,
  303. line_id,
  304. ticket_id,
  305. station_id,
  306. station_name,
  307. seat_type,
  308. human_type,
  309. prod_price,
  310. cus_price
  311. )
  312. VALUES(" . $user_id . ",'" . $create_time . "'," . $user_id . ",'" . $create_time . "',0," . $line_id . ",'" . implode(",",$ticket_group) . "','" . implode(",",$station_id_group) . "','" . implode(",",$station_name_group) . "'," . $seat_type . "," . $human_type . ",'" . $prod_price . "','" . $cus_price . "')";
  313. zzcsUtils::writeLog($insert_ticket_sql);
  314. $result1 = $this->exec($insert_ticket_sql);
  315. zzcsUtils::writeLog($insert_ticket_group_sql);
  316. $result2 = $this->exec($insert_ticket_group_sql);
  317. if($result1 && $result2)
  318. {
  319. $json['code'] = '0';
  320. $json['info'] = '添加票种成功';
  321. }
  322. else
  323. {
  324. $json['code'] = '1';
  325. $json['info'] = '后台逻辑有误';
  326. }
  327. return $json;
  328. }
  329. /**
  330. * 更新票种信息
  331. * @param $param
  332. * @return mixed
  333. */
  334. public function updateTicket($param)
  335. {
  336. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  337. $group_id = isset($param['group_id'])?trim($param['group_id']):false;
  338. $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false;
  339. $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false;
  340. $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false;
  341. $user_id = $this->user_id;
  342. $update_time = date("Y-m-d H:i:s",time());
  343. if($line_id === false || $ticket_id === false || $prod_price === false || $cus_price === false || $group_id === false)
  344. {
  345. $json['code'] = '2';
  346. $json['info'] = '缺少必要参数';
  347. return $json;
  348. }
  349. $ticket_sql = "UPDATE opera_tickets
  350. SET prod_price = '" . $prod_price . "',
  351. cus_price = '" . $cus_price . "',
  352. update_user_id = " . $user_id . ",
  353. update_time = '" . $update_time . "'
  354. WHERE
  355. line_id = " . $line_id . "
  356. AND cancel_flag = 0
  357. AND ticket_id IN (" . $ticket_id . ")";
  358. $ticket_group_sql = "UPDATE opera_tickets_group
  359. SET prod_price = '" . $prod_price . "',
  360. cus_price = '" . $cus_price . "',
  361. update_user_id = " . $user_id . ",
  362. update_time = '" . $update_time . "'
  363. WHERE
  364. line_id = " . $line_id . "
  365. AND cancel_flag = 0
  366. AND id = " . $group_id;
  367. zzcsUtils::writeLog($ticket_sql);
  368. $result1 = $this->exec($ticket_sql);
  369. zzcsUtils::writeLog($ticket_group_sql);
  370. $result2 = $this->exec($ticket_group_sql);
  371. if($result1 && $result2)
  372. {
  373. $json['code'] = '0';
  374. $json['info'] = '修改价格成功';
  375. }
  376. else
  377. {
  378. $json['code'] = '1';
  379. $json['info'] = '后台逻辑有误';
  380. }
  381. return $json;
  382. }
  383. /**
  384. * 删除票种信息
  385. * @param $param
  386. * @return mixed
  387. */
  388. public function deleteTicket($param)
  389. {
  390. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  391. $group_id = isset($param['group_id'])?trim($param['group_id']):false;
  392. $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false;
  393. $user_id = $this->user_id;
  394. $update_time = date("Y-m-d H:i:s",time());
  395. if($line_id === false || $ticket_id === false)
  396. {
  397. $json['code'] = '2';
  398. $json['info'] = '缺少必要参数';
  399. return $json;
  400. }
  401. $ticket_sql = "UPDATE opera_tickets
  402. SET cancel_flag = 1,
  403. update_user_id = " . $user_id . ",
  404. update_time = '" . $update_time . "'
  405. WHERE
  406. line_id = " . $line_id . "
  407. AND cancel_flag = 0
  408. AND ticket_id IN (" . $ticket_id . ")";
  409. $ticket_group_sql = "UPDATE opera_tickets_group
  410. SET cancel_flag = 1,
  411. update_user_id = " . $user_id . ",
  412. update_time = '" . $update_time . "'
  413. WHERE
  414. line_id = " . $line_id . "
  415. AND cancel_flag = 0
  416. AND id = " . $group_id;
  417. //将opera_message_template表的相关数据cancel_flag置为1
  418. $ticket_template_sql = "UPDATE opera_message_template
  419. SET cancel_flag = 1,
  420. update_user_id = " . $user_id . ",
  421. update_time = '" . $update_time . "'
  422. WHERE template_type=2
  423. AND cancel_flag = 0
  424. AND ticket_group_id = " . $group_id;
  425. zzcsUtils::writeLog($ticket_sql);
  426. $result1 = $this->exec($ticket_sql);
  427. zzcsUtils::writeLog($ticket_group_sql);
  428. $result2 = $this->exec($ticket_group_sql);
  429. zzcsUtils::writeLog($ticket_template_sql);
  430. $result3 = $this->exec($ticket_template_sql);
  431. if($result1 && $result2)
  432. {
  433. $json['code'] = '0';
  434. $json['info'] = '删除票种成功';
  435. }
  436. else
  437. {
  438. $json['code'] = '1';
  439. $json['info'] = '后台逻辑有误';
  440. }
  441. return $json;
  442. }
  443. }
  444. ?>