您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

572 行
25 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. if(ifnull((select is_onsale from opera_tickets where TICKET_ID in (a.TICKET_ID) limit 1),0)=1,'上架','下架') as is_onsale,
  37. prod_price,
  38. cus_price,
  39. cost_price
  40. FROM
  41. opera_tickets_group a
  42. WHERE
  43. line_id = " . $line_id . "
  44. AND cancel_flag = 0
  45. LIMIT " . $start_row . "," . $page_size;
  46. $res = $this->query($sql);
  47. if(count($res) == 0)
  48. {
  49. $json['code'] = '0';
  50. $json['info'] = '无票种信息';
  51. $json['ticket_list'] = array();
  52. $json['page']['page_size'] = $page_size;
  53. $json['page']['current_page'] = $current_page;
  54. $json['page']['total_count'] = '0';
  55. $json['page']['total_page'] = '0';
  56. return $json;
  57. }
  58. $count_sql = "SELECT
  59. count(id) as total_count
  60. FROM
  61. opera_tickets_group
  62. WHERE
  63. line_id = " . $line_id . "
  64. AND cancel_flag = 0";
  65. $total_count = $this->query($count_sql);
  66. $total_count = $total_count[0]['total_count'];
  67. $total_page = ceil($total_count/$page_size);
  68. $json['code'] = '0';
  69. $json['info'] = '返回促销规则列表成功';
  70. $json['ticket_list'] = $res;
  71. $json['page']['page_size'] = $page_size;
  72. $json['page']['current_page'] = $current_page;
  73. $json['page']['total_count'] = $total_count;
  74. $json['page']['total_page'] = $total_page;
  75. return $json;
  76. }
  77. /**
  78. * 获取票种配置信息
  79. */
  80. public function getTicketBase($param)
  81. {
  82. //获取上下车可配置上车站点数据
  83. $line_id = trim($param['line_id']);//152251
  84. if(!$line_id)
  85. {
  86. $json['code'] = '2';
  87. $json['info'] = '缺少必要参数';
  88. return $json;
  89. }
  90. $sql = "SELECT
  91. res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name,order_id
  92. FROM
  93. opera_station AS s
  94. WHERE
  95. line_id = " . $line_id . "
  96. AND inout_type in (108,109)
  97. AND cancel_flag = 0
  98. GROUP BY res_id";
  99. $start_res = $this->query($sql);
  100. //获取座位类型
  101. $base_seat = array(72);
  102. $seat_type_result = $this->getSeat();
  103. foreach($seat_type_result as $k => $v)
  104. {
  105. if(in_array($v['id'],$base_seat))
  106. {
  107. $seat_type[] = $v;
  108. }
  109. }
  110. //获取人群属性
  111. // $base_human_type = array(159,160,161);
  112. // $human_type_result = $this->getPeopleType();
  113. $human_type = array(array('id' => '0','type_name' => '不限'));
  114. // foreach($human_type_result as $k => $v)
  115. // {
  116. // if(in_array($v['id'],$base_human_type))
  117. // {
  118. // $human_type[] = $v;
  119. // }
  120. // }
  121. $json['code'] = '0';
  122. $json['info'] = '获取票种配置成功';
  123. $json['start_res'] = $start_res;
  124. $json['seat_type'] = $seat_type;
  125. $json['human_type'] = $human_type;
  126. return $json;
  127. }
  128. /**
  129. *获取下车站点信息
  130. */
  131. public function getTicketEndStation($param)
  132. {
  133. $line_id = isset($param['line_id'])?trim($param['line_id']):false;//线路ID
  134. $start_res_id = isset($param['start_res_id'])?trim($param['start_res_id']):false;//出发站ID
  135. if($line_id===false || $start_res_id === false )
  136. {
  137. $json['code'] = '2';
  138. $json['info'] = '缺少必要参数';
  139. return $json;
  140. }
  141. if(empty($line_id) || empty($start_res_id))
  142. {
  143. $json['code'] = '2';
  144. $json['info'] = '部分参数为空';
  145. return $json;
  146. }
  147. $sql = "SELECT
  148. order_id,res_id,(SELECT res_name FROM base_resource WHERE res_id = s.res_id) AS res_name
  149. FROM
  150. opera_station as s
  151. WHERE
  152. line_id = " . $line_id . "
  153. 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)
  154. AND inout_type IN (109, 110)
  155. AND res_id != " . $start_res_id . "
  156. AND cancel_flag = 0
  157. GROUP BY
  158. res_id";
  159. $end_res = $this->query($sql);
  160. $json['code'] = '0';
  161. $json['info'] = '获取下车站点成功';
  162. $json['end_res'] = $end_res;
  163. return $json;
  164. }
  165. /**
  166. * 添加票种信息
  167. * @param $param
  168. * @return mixed
  169. */
  170. public function addTicket($param)
  171. {
  172. //存储过程:SP_SAVE_LINE_TICKET_XM
  173. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  174. $station_str = isset($param['station_str'])?trim($param['station_str']):false;
  175. $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false;
  176. $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false;
  177. $cost_price = isset($param['cost_price'])?trim($param['cost_price']):false;
  178. $seat_type = isset($param['seat_type'])?trim($param['seat_type']):false;
  179. $human_type = isset($param['human_type'])?trim($param['human_type']):false;
  180. $human_type=159;
  181. $line_type = 1;
  182. $user_id = $this->user_id;
  183. $create_time = date("Y-m-d H:i:s",time());
  184. if(!$line_id || $station_str === false || $prod_price === false || $cus_price === false || $cost_price === false || $seat_type === false || $human_type === false)
  185. {
  186. $json['code'] = '2';
  187. $json['info'] = '缺少必要参数';
  188. return $json;
  189. }
  190. if(empty($line_id) || empty($station_str) || empty($prod_price) || empty($cus_price) || empty($seat_type) || empty($human_type) )
  191. {
  192. $json['code'] = '2';
  193. $json['info'] = '部分参数为空';
  194. return $json;
  195. }
  196. $ticket_name_sql = "select type_name from dict_type where id = " . $seat_type;
  197. $ticket_name = $this->query($ticket_name_sql);
  198. $ticket_name = $ticket_name[0]['type_name'] . "票";
  199. //获取最大的ticket_id
  200. $ticket_id_sql = "select ifnull(max(ticket_id),0) as ticket_id from opera_tickets";
  201. $ticket_id = $this->query($ticket_id_sql);
  202. $ticket_id = $ticket_id[0]['ticket_id'];
  203. $station_str = substr($station_str,1,-1);
  204. $station_array = explode("}{",$station_str);
  205. //获取检验是否存在票种的查询条件
  206. foreach($station_array as $k => $v)
  207. {
  208. $res_group = explode(",",$v);
  209. //获取所有的站点id;
  210. $res_array[$res_group[0]] = $res_group[0];
  211. $res_array[$res_group[1]] = $res_group[1];
  212. $check_arr[] = "(start_station_res_id = " . $res_group[0] . " and end_station_res_id = " . $res_group[1] . ")";
  213. }
  214. $check_str = "(" . implode(" or ",$check_arr) . ")";
  215. //检查是否存在已添加的票种
  216. $check_sql = "SELECT
  217. start_station_res_id,
  218. (SELECT res_name FROM base_resource WHERE res_id = t.start_station_res_id) as start_station_res_name,
  219. end_station_res_id,
  220. (SELECT res_name FROM base_resource WHERE res_id = t.end_station_res_id) as end_station_res_name
  221. FROM
  222. opera_tickets as t
  223. WHERE
  224. line_id = " . $line_id . "
  225. AND cancel_flag = 0
  226. AND seat_type = " . $seat_type . "
  227. AND human_type = " . $human_type . "
  228. AND " . $check_str;
  229. $check_ticket = $this->query($check_sql);
  230. if(count($check_ticket) > 0)
  231. {
  232. foreach($check_ticket as $k => $v)
  233. {
  234. $info_array[] = $v['start_station_res_name'] . "-" . $v['end_station_res_name'];
  235. }
  236. $json['code'] = '1';
  237. $json['info'] = implode(",",$info_array) . "的该人群及座位等级已添加过,添加失败";
  238. return $json;
  239. }
  240. //查询所有站点ID的area_id
  241. $area_sql = "SELECT
  242. area_id,
  243. res_id
  244. FROM
  245. opera_station
  246. WHERE
  247. line_id = " . $line_id . "
  248. AND res_id in (" . implode(",",$res_array) . ")
  249. AND cancel_flag = 0";
  250. $res_area = $this->query($area_sql);
  251. //查询所有的站点名称
  252. $area_sql = "SELECT
  253. res_id,
  254. res_name
  255. FROM
  256. base_resource
  257. WHERE
  258. res_id in (" . implode(",",$res_array) . ")
  259. AND cancel_flag = 0";
  260. $res_name = $this->query($area_sql);
  261. foreach ($res_area as $k => $v)
  262. {
  263. $res_area_array[$v['res_id']] = $v['area_id'];
  264. }
  265. foreach ($res_name as $k => $v)
  266. {
  267. $res_name_array[$v['res_id']] = $v['res_name'];
  268. }
  269. $insert_ticket_sql = "INSERT INTO opera_tickets (
  270. ticket_id,
  271. create_user_id,
  272. create_time,
  273. update_user_id,
  274. cancel_flag,
  275. line_id,
  276. ticket_name,
  277. ticket_type,
  278. start_station_res_id,
  279. end_station_res_id,
  280. start_station_area_id,
  281. end_station_area_id,
  282. seat_type,
  283. human_type,
  284. prod_price,
  285. cus_price,
  286. cost_price,
  287. is_onsale
  288. )
  289. VALUES ";
  290. foreach($station_array as $k => $v)
  291. {
  292. $ticket_id ++;
  293. $ticket_group[] = $ticket_id;
  294. $station_res_group = explode(",",$v);
  295. $station_id_group[] = $station_res_group[0] . "-" . $station_res_group[1];//站点联系组合
  296. $station_name_group[] = $res_name_array[$station_res_group[0]] . "-" . $res_name_array[$station_res_group[1]];//站点名称联系组合
  297. $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 . "','" . $cost_price . "',0)";
  298. }
  299. $ticket_sql = implode(",",$ticket_sql_array);
  300. $insert_ticket_sql .= $ticket_sql;
  301. //添加票种分组
  302. $insert_ticket_group_sql = "INSERT INTO opera_tickets_group (
  303. create_user_id,
  304. create_time,
  305. update_user_id,
  306. update_time,
  307. cancel_flag,
  308. line_id,
  309. ticket_id,
  310. station_id,
  311. station_name,
  312. seat_type,
  313. human_type,
  314. prod_price,
  315. cus_price,
  316. cost_price
  317. )
  318. 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 . "','" . $cost_price . "')";
  319. zzcsUtils::writeLog($insert_ticket_sql);
  320. $result1 = $this->exec($insert_ticket_sql);
  321. zzcsUtils::writeLog($insert_ticket_group_sql);
  322. $result2 = $this->exec($insert_ticket_group_sql);
  323. if($result1 && $result2)
  324. {
  325. $json['code'] = '0';
  326. $json['info'] = '添加票种成功';
  327. }
  328. else
  329. {
  330. $json['code'] = '1';
  331. $json['info'] = '后台逻辑有误';
  332. }
  333. return $json;
  334. }
  335. /**
  336. * 更新票种信息
  337. * @param $param
  338. * @return mixed
  339. */
  340. public function updateTicket($param)
  341. {
  342. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  343. $group_id = isset($param['group_id'])?trim($param['group_id']):false;
  344. $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false;
  345. $prod_price = isset($param['prod_price'])?trim($param['prod_price']):false;
  346. $cus_price = isset($param['cus_price'])?trim($param['cus_price']):false;
  347. $cost_price = isset($param['cost_price'])?trim($param['cost_price']):false;
  348. $user_id = $this->user_id;
  349. $update_time = date("Y-m-d H:i:s",time());
  350. if($line_id === false || $ticket_id === false || $prod_price === false || $cus_price === false || $cost_price === false || $group_id === false)
  351. {
  352. $json['code'] = '2';
  353. $json['info'] = '缺少必要参数';
  354. return $json;
  355. }
  356. //判断分销价是否改变,改变需要操作下属分销
  357. $get_prod_price="select prod_price from opera_tickets where ticket_id in ($ticket_id) limit 1";
  358. $tmp_prod_price = $this->query($get_prod_price);
  359. if($tmp_prod_price[0]['prod_price'] != $prod_price){
  360. $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale';
  361. $cookie="user_id=$user_id";
  362. $send_data=array(
  363. 'prod_price'=>$prod_price,
  364. 'ticket_list'=>$ticket_id,
  365. 'is_onsale'=>0
  366. );
  367. $result=$this->httpRequestForYii($url,$send_data,$cookie);
  368. $result=unserialize($result);
  369. if($result['code']!=0){
  370. return array(
  371. 'code'=>1,
  372. 'info'=>'票种代售授权失败'
  373. );
  374. }
  375. }
  376. $ticket_sql = "UPDATE opera_tickets
  377. SET prod_price = '" . $prod_price . "',
  378. cus_price = '" . $cus_price . "',
  379. cost_price = '" . $cost_price . "',
  380. update_user_id = " . $user_id . ",
  381. update_time = '" . $update_time . "'
  382. WHERE
  383. line_id = " . $line_id . "
  384. AND cancel_flag = 0
  385. AND ticket_id IN (" . $ticket_id . ")";
  386. $ticket_group_sql = "UPDATE opera_tickets_group
  387. SET prod_price = '" . $prod_price . "',
  388. cus_price = '" . $cus_price . "',
  389. cost_price = '" . $cost_price . "',
  390. update_user_id = " . $user_id . ",
  391. update_time = '" . $update_time . "'
  392. WHERE
  393. line_id = " . $line_id . "
  394. AND cancel_flag = 0
  395. AND id = " . $group_id;
  396. zzcsUtils::writeLog($ticket_sql);
  397. $result1 = $this->exec($ticket_sql);
  398. zzcsUtils::writeLog($ticket_group_sql);
  399. $result2 = $this->exec($ticket_group_sql);
  400. if($result1 && $result2)
  401. {
  402. $json['code'] = '0';
  403. $json['info'] = '修改价格成功';
  404. }
  405. else
  406. {
  407. $json['code'] = '1';
  408. $json['info'] = '后台逻辑有误';
  409. }
  410. return $json;
  411. }
  412. /**
  413. * 删除票种信息
  414. * @param $param
  415. * @return mixed
  416. */
  417. public function deleteTicket($param)
  418. {
  419. $line_id = isset($param['line_id'])?trim($param['line_id']):false;
  420. $group_id = isset($param['group_id'])?trim($param['group_id']):false;
  421. $ticket_id = isset($param['ticket_id'])?trim($param['ticket_id']):false;
  422. $user_id = $this->user_id;
  423. $update_time = date("Y-m-d H:i:s",time());
  424. if($line_id === false || $ticket_id === false)
  425. {
  426. $json['code'] = '2';
  427. $json['info'] = '缺少必要参数';
  428. return $json;
  429. }
  430. $current_day = date("Y-m-d");
  431. $ticket_type_exists_sql = "SELECT count(order_id) as total_num FROM `order_main`
  432. WHERE `order_status` IN (145,146)
  433. AND `RUN_DATE` >= '{$current_day}'
  434. AND `PROD_ID` IN ($ticket_id)";
  435. $run_bus_exists_sql = "SELECT count(id) as total_num2 FROM `run_bus`
  436. WHERE `RUN_ID` IN (SELECT `RUN_ID` FROM `run_main` WHERE `PROD_id`= '{$line_id}')
  437. AND `RUN_BUS_STATUS` IN (137,138,139)";
  438. $result5 = $this->query($ticket_type_exists_sql);
  439. $result6 = $this->query($run_bus_exists_sql);
  440. if( $result5[0]["total_num"] > 0 || $result6[0]["total_num2"] > 0 )
  441. {
  442. $json['code'] = '3';
  443. $json['info'] = $result5[0]["total_num"] > 0 ? '请将该票种相关未完成的订单全部取消后再执行删除操作' : '请将该线路的未完成班次全部停运后再执行删除操作' ;
  444. return $json;
  445. }/*else{
  446. $json['code'] = '3';
  447. $json['info'] ='该票种可删除' ;
  448. return $json;
  449. }*/
  450. $ticket_sql = "UPDATE opera_tickets
  451. SET cancel_flag = 1,
  452. update_user_id = " . $user_id . ",
  453. update_time = '" . $update_time . "'
  454. WHERE
  455. line_id = " . $line_id . "
  456. AND cancel_flag = 0
  457. AND ticket_id IN (" . $ticket_id . ")";
  458. $ticket_group_sql = "UPDATE opera_tickets_group
  459. SET cancel_flag = 1,
  460. update_user_id = " . $user_id . ",
  461. update_time = '" . $update_time . "'
  462. WHERE
  463. line_id = " . $line_id . "
  464. AND cancel_flag = 0
  465. AND id = " . $group_id;
  466. //将opera_message_template表的相关数据cancel_flag置为1
  467. $ticket_template_sql = "UPDATE opera_message_template
  468. SET cancel_flag = 1,
  469. update_user_id = " . $user_id . ",
  470. update_time = '" . $update_time . "'
  471. WHERE template_type=2
  472. AND cancel_flag = 0
  473. AND ticket_group_id = " . $group_id;
  474. zzcsUtils::writeLog($ticket_sql);
  475. $result1 = $this->exec($ticket_sql);
  476. zzcsUtils::writeLog($ticket_group_sql);
  477. $result2 = $this->exec($ticket_group_sql);
  478. zzcsUtils::writeLog($ticket_template_sql);
  479. $result3 = $this->exec($ticket_template_sql);
  480. if($result1 && $result2)
  481. {
  482. //删除票种后,代售信息删除
  483. $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/delete-ticket';
  484. $user_id = $this->user_id;
  485. $cookie="user_id=$user_id";
  486. $send_data=array(
  487. 'ticket_list'=>$ticket_id,
  488. );
  489. $result4=$this->httpRequestForYii($url,$send_data,$cookie);
  490. //return unserialize($result);
  491. $json['code'] = '0';
  492. $json['info'] = '删除票种成功';
  493. }
  494. else
  495. {
  496. $json['code'] = '1';
  497. $json['info'] = '后台逻辑有误';
  498. }
  499. return $json;
  500. }
  501. /**
  502. * Function Description:ajax发送请求---修改自营票种的上下架
  503. * Function Name: sendInfo
  504. * @param $param
  505. *
  506. * @return mixed
  507. *
  508. * @author 娄梦宁
  509. */
  510. public function sendInfo($param){
  511. $ticket_list = isset($param['ticket_list'])?trim($param['ticket_list']):false;
  512. $is_onsale = isset($param['is_onsale'])?trim($param['is_onsale']):false;
  513. if(!$ticket_list || $is_onsale===false){
  514. $json['code'] = '2';
  515. $json['info'] = '缺少必要参数';
  516. return $json;
  517. }
  518. $url='http://'.CS1_DOMAIN.'/zzcs/agent-product/upt-status-for-self-sale';
  519. $user_id = $this->user_id;
  520. $cookie="user_id=$user_id";
  521. $result=$this->httpRequestForYii($url,$param,$cookie);
  522. return unserialize($result);
  523. }
  524. public function httpRequestForYii($url,$data=null,$cookie) {
  525. $ch=curl_init();
  526. curl_setopt($ch, CURLOPT_COOKIE, $cookie);
  527. curl_setopt($ch, CURLOPT_URL, $url);
  528. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  529. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  530. if (!empty($data)){
  531. curl_setopt($ch, CURLOPT_POST, 1);
  532. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  533. }
  534. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  535. $output=curl_exec($ch);
  536. curl_close($ch);
  537. return $output;
  538. }
  539. }
  540. ?>