|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2016/8/16
- * Time: 11:57
- */
- 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");
- $end_res_array = array(
- 'shz101' => "普陀长途客运中心",
- 'zsz101' => "黄浦集散站"
- );
-
- //获取所有可销售线路$ccode
- $return_result = $getOrderInfo->run_list(zizaiArgs::$USER);
- if ($return_result["code"] == 0) {
- $circuitry_list = $return_result["circuitry_list"]["circuitry"];
- }
-
- if (isset($circuitry_list['ccode'])) {
- $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry_list['ccode']);
- foreach ($godate_array['date_list']['godate'] as $godate) {
-
- if ($godate <= date("Y-m-d", strtotime("+20 days")) && $godate >= date("Y-m-d", strtotime("+11 days"))) {
- $circuitry_list['godate'] = $godate;
- //获取班次的信息
- $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry_list['ccode'], $godate);
-
- //根据班次和时间获取所有的票种信息
- if (!isset($runlist['go_run_list']['run']['runid'])) {
- foreach ($runlist['go_run_list']['run'] as $key => $runInfo) {
- $ticketInfo = $getOrderInfo->ticket(zizaiArgs::$USER, $circuitry_list['ccode'], $runInfo['runid']);
- $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
- $runlist['go_run_list']['run'][$key] = $runInfo;
- }
- }
- $circuitry_list['runlist'] = $runlist['go_run_list']['run'];
- $result[] = $circuitry_list;
- }
- }
- } else {
- foreach ($circuitry_list as $circuitry) {
- if( !in_array($circuitry['ccode'],$can_sell_array) ) {continue;}
- //$result=$circuitry;
- $godate_array = $getOrderInfo->godate(zizaiArgs::$USER, $circuitry['ccode']); //获取指定线路可销售的运营日
- foreach ($godate_array['date_list']['godate'] as $godate) {
- if ($godate <= date("Y-m-d", strtotime("+20 days")) && $godate >= date("Y-m-d", strtotime("+11 days"))) {
- $circuitry['godate'] = $godate;
- //获取班次的信息
- $runlist = $getOrderInfo->gorun(zizaiArgs::$USER, $circuitry['ccode'], $godate);
- //根据班次和时间获取所有的票种信息
- 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']);
- $runInfo['ticket_info'] = $ticketInfo['ticket_list']['ticket'];
- $runlist['go_run_list']['run'][$key] = $runInfo;
- }
- }
- $circuitry['runlist'] = $runlist['go_run_list']['run'];
- $result[] = $circuitry;
- }
- }
- }
- }
- foreach ($result as $lineInfo) {
- //var_dump($lineInfo);
- $org_id = 3;
- $line_code = $lineInfo['ccode'];
- $line_name = $lineInfo['cname'];
- $start_date = $lineInfo['godate'];
- $area = mb_substr($line_name, 0, (utf8_strlen($line_name) - 5), 'utf-8');
- $area_arr = explode("-", $area);
- $start_area = $area_arr[0];
- $end_area = $area_arr[1];
- $end_res = isset($end_res_array[$line_code]) ? $end_res_array[$line_code] : $area_arr[1];
- foreach ($lineInfo['runlist'] as $runInfo) {
- $run_code = $runInfo['runid'];
- $start_time = $runInfo['runtime'];
- $start_res = $runInfo['runarea'];
- 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,end_res='{$end_res}',start_time='{$start_time}',update_time='{$current_time}' ";
- $pdo2 = conn();
- if (is_object($pdo2)) {
- $result = $pdo2->exec($sql_insert);
- }
- }
-
- }
- }
- }
- // 计算中文字符串长度
- function utf8_strlen($string = null)
- {
- // 将字符串分解为单元
- preg_match_all("/./us", $string, $match);
- // 返回单元个数
- return count($match[0]);
- }
-
-
-
-
-
|