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.
 
 
 
 

136 lines
6.1 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 __DIR__.'/../Common/Mysql.php';
  10. require_once __DIR__.'/../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('xn005','xn006');
  16. $end_res_array = array(
  17. 'xn005' => "朱家尖慈航大酒店",
  18. 'xn006' => "黄浦集散站"
  19. );
  20. //获取所有可销售线路$ccode
  21. $return_result = $getOrderInfo->run_list(zizaiArgs::$USER);
  22. if ($return_result["code"] == 0) {
  23. $circuitry_list = $return_result["circuitry_list"]["circuitry"];
  24. }
  25. if (isset($circuitry_list['ccode'])) {
  26. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry_list['ccode']);
  27. foreach ($godate_array['date_list']['godate'] as $godate) {
  28. if ($godate <= date("Y-m-d", strtotime("+21 days")) && $godate >= date("Y-m-d", time())) {
  29. $circuitry_list['godate'] = $godate;
  30. //获取班次的信息
  31. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry_list['ccode'], $godate);
  32. //根据班次和时间获取所有的票种信息
  33. if (!isset($runlist['go_run_list']['run']['runid'])) {
  34. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  35. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry_list['ccode'], $runInfo['runid']);
  36. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  37. $runlist['go_run_list']['run'][$key] = $runInfo;
  38. }
  39. }
  40. $circuitry_list['runlist'] = $runlist['go_run_list']['run'];
  41. $result[] = $circuitry_list;
  42. }
  43. }
  44. } else {
  45. foreach ($circuitry_list as $circuitry) {
  46. if( !in_array($circuitry['ccode'],$can_sell_array) ) {continue;}
  47. //$result=$circuitry;
  48. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry['ccode']); //获取指定线路可销售的运营日
  49. foreach ($godate_array['date_list']['godate'] as $godate) {
  50. if ($godate <= date("Y-m-d", strtotime("+21 days")) && $godate >= date("Y-m-d", time())) {
  51. $circuitry['godate'] = $godate;
  52. //获取班次的信息
  53. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry['ccode'], $godate);
  54. //根据班次和时间获取所有的票种信息
  55. if (!isset($runlist['go_run_list']['run']['runid'])) {
  56. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  57. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
  58. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  59. $runlist['go_run_list']['run'][$key] = $runInfo;
  60. }
  61. } else {
  62. $runInfo = $runlist['go_run_list']['run'];
  63. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
  64. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  65. $runlist['go_run_list']['run'] = $runInfo;
  66. }
  67. $circuitry['runlist'] = $runlist['go_run_list']['run'];
  68. $result[] = $circuitry;
  69. }
  70. }
  71. }
  72. }
  73. foreach ($result as $lineInfo) {
  74. $org_id = 3;
  75. $line_code = $lineInfo['ccode'];
  76. $line_name = $lineInfo['cname'];
  77. $start_date = $lineInfo['godate'];
  78. $str_trip_pos = mb_strpos( $line_name, "旅游", 0,'utf-8' );
  79. $area = mb_substr($line_name, 0, $str_trip_pos, 'utf-8');
  80. if( mb_strpos( $line_name, "—", 0,'utf-8' ) != false ) {
  81. $area_arr = explode("—", $area);
  82. } else {
  83. $area_arr = explode("-", $area);
  84. }
  85. $start_area = $area_arr[0];
  86. $end_area = $area_arr[1];
  87. $end_res = $area_arr[1];
  88. $end_res = isset($end_res_array[$line_code]) ? $end_res_array[$line_code] : $area_arr[1];
  89. if( isset($lineInfo['runlist']['runid']) ) {
  90. $runInfo = $lineInfo['runlist'];
  91. insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
  92. } else {
  93. foreach ($lineInfo['runlist'] as $runInfo) {
  94. insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
  95. }
  96. }
  97. }
  98. function insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time) {
  99. $run_code = $runInfo['runid'];
  100. $start_time = $runInfo['runtime'];
  101. $start_res = $runInfo['runarea'];
  102. foreach ($runInfo['ticket_info'] as $ticketInfo) {
  103. if (isset($ticketInfo['ticketname'])) {
  104. $prod_code = $ticketInfo['ticketid'];
  105. $cus_price = $ticketInfo['ticketprice'];
  106. $mid_price = isset($ticketInfo['agentprice']) ? $ticketInfo['agentprice'] : $ticketInfo['ticketprice']*0.9;
  107. $remain_count = $ticketInfo['ticketcount'];
  108. $prod_name = $ticketInfo['ticketname'];
  109. if ($mid_price <= 0 || mb_strlen($prod_name) < 5) {
  110. continue;
  111. }
  112. $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) " .
  113. " 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}' ) " .
  114. " ON DUPLICATE KEY UPDATE remain_count = $remain_count,start_time='{$start_time}',update_time='{$current_time}' ";
  115. $pdo2 = conn();
  116. if (is_object($pdo2)) {
  117. $result = $pdo2->exec($sql_insert);
  118. }
  119. }
  120. }
  121. }