|
- <?php
- /**
- * Created by PhpStorm.
- * User: Redstop
- * Date: 2016/12/17
- * Time: 11:57
- */
- header("Content-type:text/html;charset=utf-8");
- require_once __DIR__.'/../Common/Mysql.php';
- require_once __DIR__.'/../Common/zizai_orderAPI.php';
- $current_time = date("Y-m-d H:i:s");
- $getOrderInfo = new orderService();
- $result = array();
-
- //$can_sell_array = array("shz101", "zsz101");
- $can_sell_array = array('cxpt001','cxpt002');
-
- $end_res_array = array(
- 'cxpt001' => "朱家尖慈航广场",
- 'cxpt002' => "黄浦集散站"
- );
-
- //获取所有可销售线路$ccode
- $circuitry_list = get_memcache('ZIZAI_TICKETS_CODE');
-
- foreach ($circuitry_list as $circuitry) {
- if( !in_array($circuitry['ccode'],$can_sell_array) ) {continue;}
- $godate = date("Y-m-d");
- $end_date = date("Y-m-d", strtotime("+14 days"));
- while ( $godate <= $end_date ) {
- $circuitry['godate'] = $godate;
- //获取班次的信息
- $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry['ccode'], $godate);
- if( false != $runlist && $runlist["code"] == 0 ) {
- //根据班次和时间获取所有的票种信息
- if (!isset($runlist['go_run_list']['run']['runid'])) {
- foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
- $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
- if( isset($ticketInfo['ticket_list']['ticket']["ticketid"]) ) {
- $runInfo['ticket_info'][] = $ticketInfo['ticket_list']['ticket'];
- } else {
- $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
- }
- $runlist['go_run_list']['run'][$key] = $runInfo;
- }
- } else {
- $runInfo = $runlist['go_run_list']['run'];
- $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry['ccode'], $runInfo['runid']);
- if( isset($ticketInfo['ticket_list']['ticket']["ticketid"]) ) {
- $runInfo['ticket_info'][] = $ticketInfo['ticket_list']['ticket'];
- } else {
- $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
- }
- $runlist['go_run_list']['run'] = $runInfo;
- }
- $circuitry['runlist'] = $runlist['go_run_list']['run'];
- $result[] = $circuitry;
- }
- $godate = date("Y-m-d", strtotime( $godate." +1 days" ));
- }
- }
-
- foreach ($result as $lineInfo) {
- $org_id = 3;
- $line_code = $lineInfo['ccode'];
- $line_name = $lineInfo['cname'];
- $start_date = $lineInfo['godate'];
- if( $line_code == "cxpt001" ) {
- $area_arr = array("上海","舟山");
- } else{
- $area_arr = array("舟山","上海");
- }
-
- $start_area = $area_arr[0];
- $end_area = $area_arr[1];
- $end_res = $area_arr[1];
- $end_res = isset($end_res_array[$line_code]) ? $end_res_array[$line_code] : $area_arr[1];
- if( isset($lineInfo['runlist']['runid']) ) {
- $runInfo = $lineInfo['runlist'];
- insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
- } else {
- foreach ($lineInfo['runlist'] as $runInfo) {
- insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time);
- }
- }
- }
-
- function insert_outside_run( $runInfo, $org_id, $line_code, $line_name, $start_date, $start_area, $end_area, $end_res, $current_time) {
- $run_code = $runInfo['runid'];
- $start_time = $runInfo['runtime'];
- $start_res = $runInfo['runarea'];
- if( $start_res == "十六铺旅游集散中心" ) {
- return;
- }
- foreach ($runInfo['ticket_info'] as $ticketInfo) {
- if (isset($ticketInfo['ticketname'])) {
- $prod_code = $ticketInfo['ticketid'];
- $cus_price = $ticketInfo['ticketprice'];
- $mid_price = isset($ticketInfo['agentprice']) ? $ticketInfo['agentprice'] : $ticketInfo['ticketprice']*0.9;
- $remain_count = $ticketInfo['ticketcount'];
- $prod_name = $ticketInfo['ticketname'];
- if ($cus_price <= 0 || mb_strlen($prod_name) < 5) {
- continue;
- }
- $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) " .
- " 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}' ) " .
- " ON DUPLICATE KEY UPDATE remain_count = $remain_count,start_time='{$start_time}',update_time='{$current_time}' ";
- $pdo2 = conn();
- if (is_object($pdo2)) {
- $result = $pdo2->exec($sql_insert);
- }
- }
- }
- }
|