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.

zizai_ticket_info_3.php 5.3 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/8/16
  6. * Time: 11:57
  7. */
  8. require_once __DIR__.'/../Common/Mysql.php';
  9. require_once __DIR__.'/../Common/zizai_orderAPI.php';
  10. $current_time = date("Y-m-d H:i:s");
  11. $getOrderInfo = new orderService();
  12. $result = array();
  13. $can_sell_array = array("shz101", "zsz101");
  14. $end_res_array = array(
  15. 'shz101' => "普陀长途客运中心",
  16. 'zsz101' => "黄浦集散站"
  17. );
  18. //获取所有可销售线路$ccode
  19. $return_result = $getOrderInfo->run_list(zizaiArgs::$USER);
  20. if ($return_result["code"] == 0) {
  21. $circuitry_list = $return_result["circuitry_list"]["circuitry"];
  22. }
  23. if (isset($circuitry_list['ccode'])) {
  24. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry_list['ccode']);
  25. foreach ($godate_array['date_list']['godate'] as $godate) {
  26. if ($godate <= date("Y-m-d", strtotime("+30 days")) && $godate >= date("Y-m-d", strtotime("+21 days"))) {
  27. $circuitry_list['godate'] = $godate;
  28. //获取班次的信息
  29. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry_list['ccode'], $godate);
  30. //根据班次和时间获取所有的票种信息
  31. if (!isset($runlist['go_run_list']['run']['runid'])) {
  32. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  33. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry_list['ccode'], $runInfo['runid']);
  34. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  35. $runlist['go_run_list']['run'][$key] = $runInfo;
  36. }
  37. }
  38. $circuitry_list['runlist'] = $runlist['go_run_list']['run'];
  39. $result[] = $circuitry_list;
  40. }
  41. }
  42. } else {
  43. foreach ($circuitry_list as $circuitry) {
  44. if( !in_array($circuitry['ccode'],$can_sell_array) ) {continue;}
  45. //$result=$circuitry;
  46. $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry['ccode']); //获取指定线路可销售的运营日
  47. foreach ($godate_array['date_list']['godate'] as $godate) {
  48. if ($godate <= date("Y-m-d", strtotime("+30 days")) && $godate >= date("Y-m-d", strtotime("+21 days"))) {
  49. $circuitry['godate'] = $godate;
  50. //获取班次的信息
  51. $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry['ccode'], $godate);
  52. //根据班次和时间获取所有的票种信息
  53. if (!isset($runlist['go_run_list']['run']['runid'])) {
  54. foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
  55. $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
  56. $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
  57. $runlist['go_run_list']['run'][$key] = $runInfo;
  58. }
  59. }
  60. $circuitry['runlist'] = $runlist['go_run_list']['run'];
  61. $result[] = $circuitry;
  62. }
  63. }
  64. }
  65. }
  66. foreach ($result as $lineInfo) {
  67. //var_dump($lineInfo);
  68. $org_id = 3;
  69. $line_code = $lineInfo['ccode'];
  70. $line_name = $lineInfo['cname'];
  71. $start_date = $lineInfo['godate'];
  72. $area = mb_substr($line_name, 0, (utf8_strlen($line_name) - 5), 'utf-8');
  73. $area_arr = explode("-", $area);
  74. $start_area = $area_arr[0];
  75. $end_area = $area_arr[1];
  76. $end_res = isset($end_res_array[$line_code]) ? $end_res_array[$line_code] : $area_arr[1];
  77. foreach ($lineInfo['runlist'] as $runInfo) {
  78. $run_code = $runInfo['runid'];
  79. $start_time = $runInfo['runtime'];
  80. $start_res = $runInfo['runarea'];
  81. foreach ($runInfo['ticket_info'] as $ticketInfo) {
  82. if ( isset($ticketInfo['ticketname']) ) {
  83. $prod_code = $ticketInfo['ticketid'];
  84. $cus_price = $ticketInfo['ticketprice'];
  85. $mid_price = isset($ticketInfo['agentprice']) ? $ticketInfo['agentprice'] : $ticketInfo['ticketprice']*0.9;
  86. $remain_count = $ticketInfo['ticketcount'];
  87. $prod_name = $ticketInfo['ticketname'];
  88. if( $cus_price <= 0 || mb_strlen($prod_name) < 5 ) {
  89. continue;
  90. }
  91. $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) " .
  92. " 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}' ) " .
  93. " ON DUPLICATE KEY UPDATE remain_count = $remain_count,end_res='{$end_res}',start_time='{$start_time}',update_time='{$current_time}' ";
  94. $pdo2 = conn();
  95. if (is_object($pdo2)) {
  96. $result = $pdo2->exec($sql_insert);
  97. }
  98. }
  99. }
  100. }
  101. }
  102. // 计算中文字符串长度
  103. function utf8_strlen($string = null)
  104. {
  105. // 将字符串分解为单元
  106. preg_match_all("/./us", $string, $match);
  107. // 返回单元个数
  108. return count($match[0]);
  109. }