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.
 
 
 
 

149 lines
7.4 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/8/16
  6. * Time: 11:57
  7. */
  8. header("Content-type:text/html;charset=utf-8");
  9. require_once '../Common/Mysql.php';
  10. require_once '../Common/zizai_orderAPI.php';
  11. $current_time = date("Y-m-d H:i:s");
  12. $getOrderInfo = new orderService();
  13. $result = array();
  14. //$can_sell_array = array("shz101", "zsz101");
  15. $can_sell_array = array('HSHH01','HSPT01','HSHH02','HSPT02');
  16. $end_res_array = array(
  17. 'HSHH01' => array("黄山风景区南大门汤口镇","黄山市区自驾车旅游服务中心"),
  18. 'HSPT01' => array("黄山风景区南大门汤口镇","黄山市区自驾车旅游服务中心"),
  19. 'HSHH02' => array("黄浦集散站","上海南站","人民广场"),
  20. 'HSPT02' => array("黄浦集散站","上海南站","人民广场")
  21. );
  22. //获取所有可销售线路$ccode
  23. $return_result = $getOrderInfo->run_list(zizaiArgs::$USER);
  24. if ($return_result["code"] == 0) {
  25. $circuitry_list = $return_result["circuitry_list"]["circuitry"];
  26. }
  27. if (isset($circuitry_list['ccode'])) {
  28. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry_list['ccode']);
  29. foreach ($godate_array['date_list']['godate'] as $godate) {
  30. if ($godate <= date("Y-m-d", strtotime("+21 days")) && $godate >= date("Y-m-d", strtotime("+2 days")) ) {
  31. $circuitry_list['godate'] = $godate;
  32. //获取班次的信息
  33. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry_list['ccode'], $godate);
  34. //根据班次和时间获取所有的票种信息
  35. if (!isset($runlist['go_run_list']['run']['runid'])) {
  36. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  37. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry_list['ccode'], $runInfo['runid']);
  38. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  39. $runlist['go_run_list']['run'][$key] = $runInfo;
  40. }
  41. }
  42. $circuitry_list['runlist'] = $runlist['go_run_list']['run'];
  43. $result[] = $circuitry_list;
  44. }
  45. }
  46. } else {
  47. foreach ($circuitry_list as $circuitry) {
  48. if( !in_array($circuitry['ccode'],$can_sell_array) ) {continue;}
  49. //$result=$circuitry;
  50. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry['ccode']); //获取指定线路可销售的运营日
  51. foreach ($godate_array['date_list']['godate'] as $godate) {
  52. if ($godate <= date("Y-m-d", strtotime("+21 days")) && $godate >= date("Y-m-d", strtotime("+2 days")) ) {
  53. $circuitry['godate'] = $godate;
  54. //获取班次的信息
  55. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry['ccode'], $godate);
  56. //根据班次和时间获取所有的票种信息
  57. if (!isset($runlist['go_run_list']['run']['runid'])) {
  58. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  59. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
  60. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  61. $runlist['go_run_list']['run'][$key] = $runInfo;
  62. }
  63. } else {
  64. $runInfo = $runlist['go_run_list']['run'];
  65. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
  66. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  67. $runlist['go_run_list']['run'] = $runInfo;
  68. }
  69. $circuitry['runlist'] = $runlist['go_run_list']['run'];
  70. $result[] = $circuitry;
  71. }
  72. }
  73. }
  74. }
  75. foreach ($result as $lineInfo) {
  76. $org_id = 3;
  77. $line_code = $lineInfo['ccode'];
  78. $line_name = $lineInfo['cname'];
  79. $start_date = $lineInfo['godate'];
  80. $str_trip_pos = mb_strpos( $line_name, "旅游", 0,'utf-8' );
  81. $area = mb_substr($line_name, 0, $str_trip_pos, 'utf-8');
  82. if( mb_strpos( $line_name, "—", 0,'utf-8' ) != false ) {
  83. $area_arr = explode("—", $area);
  84. } else {
  85. $area_arr = explode("-", $area);
  86. }
  87. $start_area = $area_arr[0];
  88. $end_area = $area_arr[1];
  89. $end_res = $area_arr[1];
  90. $end_res = isset($end_res_array[$line_code]) ? $end_res_array[$line_code] : $area_arr[1];
  91. if( isset($lineInfo['runlist']['runid']) ) {
  92. $runInfo = $lineInfo['runlist'];
  93. insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
  94. } else {
  95. foreach ($lineInfo['runlist'] as $runInfo) {
  96. insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
  97. }
  98. }
  99. }
  100. function insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time) {
  101. $run_code = $runInfo['runid'];
  102. $start_time = $runInfo['runtime'];
  103. $start_res = $runInfo['runarea'];
  104. foreach ($runInfo['ticket_info'] as $ticketInfo) {
  105. if (isset($ticketInfo['ticketname'])) {
  106. $prod_code = $ticketInfo['ticketid'];
  107. $cus_price = $ticketInfo['ticketprice'];
  108. $mid_price = isset($ticketInfo['agentprice']) ? $ticketInfo['agentprice'] : $ticketInfo['ticketprice']*0.9;
  109. $remain_count = $ticketInfo['ticketcount'];
  110. $prod_name = $ticketInfo['ticketname'];
  111. if ($mid_price <= 0 || mb_strlen($prod_name) < 5) {
  112. continue;
  113. }
  114. if( is_array($end_res) ) {
  115. foreach( $end_res as $end_res_txt ) {
  116. $sql_insert = " INSERT INTO outside_run ( org_id, run_code, prod_code, prod_name, line_code, line_name, start_date, start_time, start_area, end_area, start_res, end_res, cus_price, mid_price, remain_count, cancel_flag,update_time) " .
  117. " VALUES ( {$org_id}, '{$run_code}', '{$prod_code}','{$prod_name}','{$line_code}','{$line_name}','{$start_date}', '{$start_time}', '{$start_area}', '{$end_area}', '{$start_res}', '{$end_res_txt}', {$cus_price}, {$mid_price}, {$remain_count}, 0,'{$current_time}' ) " .
  118. " ON DUPLICATE KEY UPDATE remain_count = {$remain_count},start_time='{$start_time}',update_time='{$current_time}' ";
  119. $pdo2 = conn();
  120. if (is_object($pdo2)) {
  121. $result = $pdo2->exec($sql_insert);
  122. }
  123. }
  124. } else {
  125. $sql_insert = " INSERT INTO outside_run ( org_id, run_code, prod_code, prod_name, line_code, line_name, start_date, start_time, start_area, end_area, start_res, end_res, cus_price, mid_price, remain_count, cancel_flag,update_time) " .
  126. " VALUES ( {$org_id}, '{$run_code}', '{$prod_code}','{$prod_name}','{$line_code}','{$line_name}','{$start_date}', '{$start_time}', '{$start_area}', '{$end_area}', '{$start_res}', '{$end_res}', {$cus_price}, {$mid_price}, {$remain_count}, 0,'{$current_time}' ) " .
  127. " ON DUPLICATE KEY UPDATE remain_count = {$remain_count},start_time='{$start_time}',update_time='{$current_time}' ";
  128. $pdo2 = conn();
  129. if (is_object($pdo2)) {
  130. $result = $pdo2->exec($sql_insert);
  131. }
  132. }
  133. }
  134. }
  135. }