load->helper('array'); $this->load->library('trippest'); $this->load->model('Orders_query', 'Orders_model'); header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Methods:POST, GET'); header('Access-Control-Max-Age:0'); header('Access-Control-Allow-Headers:x-requested-with, Content-Type'); header('Access-Control-Allow-Credentials:true'); } public function index() { $this->operation_detail(); } public function operation_detail($find=null) { ($find===null) ? $find = $this->input->get_post('q') : null; $find = (mb_strlen($find)<9) ? null : $find; preg_match('/[\d]+\-?[\w]*/', characet($find, "UTF-8"), $temp_array); $find = isset($temp_array[0]) ? $temp_array[0] : null; $order_plan = null; if ($find !== null) { $order_plan = $this->Orders_model->get_order_vendorplan($find); } if ($find===null || $order_plan == null) { $ret['status'] = 0; $ret['msg'] = "Not Found."; return $this->output->set_content_type('application/json')->set_output(json_encode($ret)); } $ret['status'] = 1; $ret['msg'] = ""; $gri_sn = $order_plan[0]->VAS_GRI_SN; $group_number_info = analysis_groupCode($order_plan[0]->COLI_GroupCode); $ret['group_number'] = $group_number_info["all"]; $operation_info = $ht_tourguide = $this->tourguide_common($gri_sn); if (empty($operation_info)) { return $this->operation_detail_tulanduo($find); } $ret['operation'] = $operation_info; /** 外联信息 */ $raw_opi_id = 0; if (intval($order_plan[0]->COLI_OPI_ID) === 435) { $real_code_info = analysis_groupCode($ret['group_number']); $raw_opi_id = $this->Orders_model->get_gri_opi_id($real_code_info['cut']); } else { $raw_opi_id = $order_plan[0]->COLI_OPI_ID; } $operator = $this->Orders_model->get_operator($raw_opi_id); if ( ! empty($operator)) { $ret['operator']['chinese_name'] = $operator->OPI_Name; $ret['operator']['mobile'] = $operator->OPI_MoveTelephone; $ret['operator']['email'] = $operator->OPI_Email; $ret['operator']['english_name'] = $operator->OPI2_Name; // 英文名没有 if ($operator->OPI_FirstName == null || $operator->OPI2_Name == null ) { $ret['operator']['english_name'] = ucfirst(strstr($operator->OPI_Email, "@", true)); } } return $this->output->set_content_type('application/json')->set_output(json_encode($ret)); } public function tourguide_common($gri_sn) { $operation = array(); $tourguide = $this->Orders_model->get_plan_tourguide($gri_sn); if (empty($tourguide)) { return null; } $order_detail = $this->Orders_model->get_order_detail($gri_sn); foreach ($order_detail as $kd => $poi) { $operation_tmp = array(); $operation_tmp['start_date'] = substr($poi->COLD_StartDate, 0, 10); $out_datetime = strtotime($poi->COLD_StartDate); $out_datetime2 = strtotime($poi->COLD_EndDate); $operation_tmp['dateWeek_text'] = date('D', $out_datetime); $operation_tmp['dateDay_text'] = date('d', $out_datetime); $operation_tmp['dateMonth_text'] = date('M', $out_datetime); $operation_tmp['dateYear_text'] = date('Y', $out_datetime); if ($out_datetime !== $out_datetime2) { $operation_tmp['start_date'] = $poi->COLD_StartDate . " to " . $poi->COLD_EndDate; } $operation_tmp['tour_name'] = $poi->PAG2_Name; $code_name = $this->trippest->tour_name(strtoupper($poi->pag_code)); if ($code_name !== "") { $operation_tmp['tour_name'] = $code_name; } // 领队名字 // $operation_tmp['full_leader_name'] = trim($poi->GUT_FirstName . " " . $poi->GUT_LastName); $replace_cnt1 = $replace_cnt2 = 0; if (mb_strlen($poi->GUT_FirstName, 'UTF-8') > 2) { $replace_cnt1 = mb_strlen($poi->GUT_FirstName, 'UTF-8')-2; } if (mb_strlen($poi->GUT_LastName, 'UTF-8') > 2) { $replace_cnt2 = mb_strlen($poi->GUT_LastName, 'UTF-8')-2; } $operation_tmp['leader_name'] = substr_replace($poi->GUT_FirstName,str_repeat('*', $replace_cnt1),1,-1) . " " . substr_replace($poi->GUT_LastName,str_repeat('*', $replace_cnt2),1,-1); $operation_tmp['leader_name'] = trim($operation_tmp['leader_name']); // 行程人数 $operation_tmp['personNum_text'] = $poi->COLD_PersonNum + $poi->COLD_ChildNum; $operation_tmp['personNum_text'] .= " (" . $poi->COLD_PersonNum . " Adult(s)"; if ($poi->COLD_ChildNum > 0) { $operation_tmp['personNum_text'] .= " " . $poi->COLD_ChildNum . " Child(ren)"; } $operation_tmp['personNum_text'] .= ")" ; // 人数 $operation_tmp['adult_number'] = $poi->COLD_PersonNum; $operation_tmp['kid_number'] = $poi->COLD_ChildNum; // 酒店 $operation_tmp['hotel_name'] = $poi->POI_Hotel; $operation_tmp['hotel_address'] = $poi->POI_HotelAddress; $operation_tmp['hotel_tel'] = $poi->POI_HotelPhone; // 航班/车次 $operation_tmp['flights_no'] = $poi->POI_FlightsNo; $operation_tmp['flights_airport'] = $poi->POI_AirPort; // 接送信息 $operation_tmp['pick_up'] = ""; $operation_tmp['drop_off'] = ""; $decode_MemoText = $memo_text_tmp = ""; $operation_tmp['pick_up'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Pick Up From:"), "\n", true), 13)); $operation_tmp['drop_off'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Drop Off:"), "\n" , true), 9)); if ($operation_tmp['pick_up'] === "") { if (strval($poi->PAGS_Direction) === '0') { $operation_tmp['pick_up'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; $operation_tmp['drop_off'] .= $poi->POI_Hotel; } else if (strval($poi->PAGS_Direction) === '1') { $operation_tmp['pick_up'] .= $poi->POI_Hotel; $operation_tmp['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; } else { // if ($poi->POI_FlightsNo != "") $operation_tmp['pick_up'] .= $poi->POI_Hotel; // $operation_tmp['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; // 结束后送机 } } $opd = new stdclass(); foreach ($tourguide as $key => $tgi) { if ($poi->COLD_PlanVEI_SN === $tgi->EOI_VEI_SN // && strcmp($operation_tmp['start_date_raw'], substr($poi->COLD_StartDate, 0, 10) ) === 0 ) { $opd = $tgi; } } if (empty($opd)) { $opd = $tgi[0]; } $tourguide_tmp['guide_name'] = $opd->TGI2_Name; $tourguide_tmp['guide_tel'] = $opd->TGI_Mobile; $tourguide_tmp['guide_pic'] = ""; // $tourguide_tmp['using_startdate'] = $opd->GCOD_startDate; // $tourguide_tmp['using_enddate'] = $opd->GCOD_endDate; $operation_tmp['tourguide'][] = $tourguide_tmp; $tourguide_tmp = array(); $operation[] = $operation_tmp; } return $operation; } public function operation_detail_tulanduo($find=null) { // ($find===null) ? $find = $this->input->get_post('q') : null; // $find = (mb_strlen($find)<9) ? null : $this->input->get_post('q'); $order_project = $this->Orders_model->get_package_order($find); if ($find===null || $order_project == null) { $ret['status'] = 0; $ret['msg'] = "Not Found."; return $this->output->set_content_type('application/json')->set_output(json_encode($ret)); } $ret['status'] = 1; $ret['msg'] = ""; $group_number_info = analysis_groupCode($order_project[0]->COLI_GroupCode); $ret['group_number'] = $group_number_info["all"]; $all_combine_no = array_unique(array_map(function($ele) { return $ele->GCI_combineNo; }, $order_project)); $ret['operation'] = array(); $operation = $this->Orders_model->get_operation($all_combine_no); // 司机, 导游 if ( ! empty($operation)) { // 按照实际安排的日期分组 foreach ($operation as $key => $value) { if ($value->GCOD_operationType === 'touristCarOperations') { $tmp_car = array(); $tmp_car['car_type'] = $value->GCOD_subType; $tmp_car['car_company'] = $value->GCOD_title; $tmp_car['car_license'] = $value->GCOD_carLicense; $tmp_car['driver_name'] = $value->GCOD_dutyName; $tmp_car['driver_tel'] = $value->GCOD_dutyTel; $tmp_car['driver_pic'] = $value->GCOD_dutyPhoto; $tmp_car['car_remark'] = $value->GCOD_remark; $tmp_car['using_startdate'] = $value->GCOD_startDate; $tmp_car['using_enddate'] = $value->GCOD_endDate; $ret['operation'][$value->GCOD_startDate]['cardriver'][] = $tmp_car; // 出团时间 $ret['operation'][$value->GCOD_startDate]['start_date'] = $value->GCOD_startDate; if ( ! isset($ret['operation'][$value->GCOD_startDate]['end_date']) || strtotime($ret['operation'][$value->GCOD_startDate]['end_date']) > strtotime($value->GCOD_endDate) ) { $ret['operation'][$value->GCOD_startDate]['end_date'] = $value->GCOD_endDate; } } else if ($value->GCOD_operationType === 'guiderOperations') { $tmp_g = array(); $tmp_g['guide_name'] = $value->GCOD_dutyName; $tmp_g['guide_tel'] = $value->GCOD_dutyTel; $tmp_g['guide_pic'] = $value->GCOD_dutyPhoto; $tmp_g['guide_remark'] = $value->GCOD_remark; $tmp_g['using_startdate'] = $value->GCOD_startDate; $tmp_g['using_enddate'] = $value->GCOD_endDate; $ret['operation'][$value->GCOD_startDate]['tourguide'][] = $tmp_g; // 出团时间 $ret['operation'][$value->GCOD_startDate]['start_date'] = $value->GCOD_startDate; if ( ! isset($ret['operation'][$value->GCOD_startDate]['end_date']) || strtotime($ret['operation'][$value->GCOD_startDate]['end_date']) > strtotime($value->GCOD_endDate) ) { $ret['operation'][$value->GCOD_startDate]['end_date']= $value->GCOD_endDate; } } } // 加上行程 $num_index = 0; foreach ($ret['operation'] as $kro => &$vro) { $vro['start_date_raw'] = $vro['start_date']; $out_datetime = strtotime($vro['start_date']); $out_datetime2 = strtotime($vro['end_date']); $vro['dateWeek_text'] = date('D', $out_datetime); $vro['dateDay_text'] = date('d', $out_datetime); $vro['dateMonth_text'] = date('M', $out_datetime); $vro['dateYear_text'] = date('Y', $out_datetime); if ($out_datetime !== $out_datetime2) { $vro['start_date'] = $vro['start_date'] . " to " . $vro['end_date']; } $poi = new stdclass(); foreach ($order_project as $kd => $poi_info) { if (strcmp($vro['start_date_raw'], substr($poi_info->COLD_StartDate, 0, 10) ) === 0) { if (count((array)$poi)===0) { $poi = $poi_info; } else if ($poi->POI_Hotel == "") { $poi->POI_Hotel = $poi_info->POI_Hotel; $poi->POI_HotelAddress = $poi_info->POI_HotelAddress; $poi->POI_HotelPhone = $poi_info->POI_HotelPhone; // } else if ($poi->POI_FlightsNo == "") { } else if ($poi_info->POI_FlightsNo != "" && $poi_info->COLD_SN != $poi->COLD_SN) { $poi->POI_FlightsNo .= "; " . $poi_info->POI_FlightsNo; // $poi->POI_AirPort .= "; " . $poi_info->POI_AirPort; } } } if (count((array)$poi)===0) { $poi = $order_project[0]; } $vro['cold_date'] = $poi->COLD_StartDate; $vro['cold_enddate'] = $poi->COLD_EndDate; $vro['tour_name'] = $poi->PAG2_Name; $code_name = $this->trippest->tour_name(strtoupper($poi->pag_code)); if ($code_name !== "") { $vro['tour_name'] = $code_name; } // 领队名字 // $vro['full_leader_name'] = trim($poi->GUT_FirstName . " " . $poi->GUT_LastName); $replace_cnt1 = $replace_cnt2 = 0; if (mb_strlen($poi->GUT_FirstName, 'UTF-8') > 2) { $replace_cnt1 = mb_strlen($poi->GUT_FirstName, 'UTF-8')-2; } if (mb_strlen($poi->GUT_LastName, 'UTF-8') > 2) { $replace_cnt2 = mb_strlen($poi->GUT_LastName, 'UTF-8')-2; } $vro['leader_name'] = substr_replace($poi->GUT_FirstName, str_repeat('*', $replace_cnt1), 1,-1) . " " . substr_replace($poi->GUT_LastName,str_repeat('*', $replace_cnt2),1,-1); $vro['leader_name'] = trim($vro['leader_name']); // 行程人数 $vro['personNum_text'] = $poi->COLD_PersonNum + $poi->COLD_ChildNum; $vro['personNum_text'] .= " (" . $poi->COLD_PersonNum . " Adult(s)"; if ($poi->COLD_ChildNum > 0) { $vro['personNum_text'] .= " " . $poi->COLD_ChildNum . " Child(ren)"; } $vro['personNum_text'] .= ")" ; // 人数 $vro['adult_number'] = $order_project[0]->COLD_PersonNum; $vro['kid_number'] = $order_project[0]->COLD_ChildNum; // 酒店 $vro['hotel_name'] = $poi->POI_Hotel; $vro['hotel_address'] = $poi->POI_HotelAddress; $vro['hotel_tel'] = $poi->POI_HotelPhone; // 航班/车次 $vro['flights_no'] = $poi->POI_FlightsNo; $vro['flights_airport'] = $poi->POI_AirPort; // 接送信息 $vro['pick_up'] = ""; $vro['drop_off'] = ""; $decode_MemoText = $memo_text_tmp = ""; if ($vro['pick_up'] === "" && $poi->COLD_MemoText != null && json_decode($poi->COLD_MemoText) != null) { $decode_MemoText = json_decode($poi->COLD_MemoText, true); $vro['pick_up'] = $decode_MemoText['Pick up']; $vro['drop_off'] = $decode_MemoText['Drop off']; } if ($vro['pick_up'] === "" && $num_index == 0) { $vro['pick_up'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Pick Up From:"), "\n", true), 13)); $vro['drop_off'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Drop Off:"), "\n" , true), 9)); } if ($vro['pick_up'] === "") { if (strval($poi->PAGS_Direction) === '0') { $vro['pick_up'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; $vro['drop_off'] .= $poi->POI_Hotel; } else if (strval($poi->PAGS_Direction) === '1') { $vro['pick_up'] .= $poi->POI_Hotel; $vro['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; } else { // if ($poi->POI_FlightsNo != "") $vro['pick_up'] .= $poi->POI_Hotel; // $vro['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; // 结束后送机 } } $vro['leader_name'] = mb_convert_encoding($vro['leader_name'], "UTF-8"); $vro['hotel_name'] = mb_convert_encoding($vro['hotel_name'], "UTF-8"); $vro['hotel_address'] = mb_convert_encoding($vro['hotel_address'], "UTF-8"); $vro['pick_up'] = mb_convert_encoding($vro['pick_up'], "UTF-8"); $vro['drop_off'] = mb_convert_encoding($vro['drop_off'], "UTF-8"); $num_index++; } unset($vro); } else { foreach ($order_project as $kd => $poi) { $vro = array(); $vro['start_date_raw'] = $vro['start_date'] = substr($poi->COLD_StartDate, 0, 10); $out_datetime = strtotime($poi->COLD_StartDate); $out_datetime2 = strtotime($poi->COLD_EndDate); $vro['dateWeek_text'] = date('D', $out_datetime); $vro['dateDay_text'] = date('d', $out_datetime); $vro['dateMonth_text'] = date('M', $out_datetime); $vro['dateYear_text'] = date('Y', $out_datetime); if ($out_datetime !== $out_datetime2) { $vro['start_date'] = $poi->COLD_StartDate . " to " . $poi->COLD_EndDate; } $vro['cold_date'] = $poi->COLD_StartDate; $vro['cold_enddate'] = $poi->COLD_EndDate; $vro['tour_name'] = $poi->PAG2_Name; $code_name = $this->trippest->tour_name(strtoupper($poi->pag_code)); if ($code_name !== "") { $vro['tour_name'] = $code_name; } // 领队名字 // $vro['full_leader_name'] = trim($poi->GUT_FirstName . " " . $poi->GUT_LastName); $replace_cnt1 = $replace_cnt2 = 0; if (mb_strlen($poi->GUT_FirstName, 'UTF-8') > 2) { $replace_cnt1 = mb_strlen($poi->GUT_FirstName, 'UTF-8')-2; } if (mb_strlen($poi->GUT_LastName, 'UTF-8') > 2) { $replace_cnt2 = mb_strlen($poi->GUT_LastName, 'UTF-8')-2; } $vro['leader_name'] = substr_replace($poi->GUT_FirstName,str_repeat('*', $replace_cnt1),1,-1) . " " . substr_replace($poi->GUT_LastName,str_repeat('*', $replace_cnt2),1,-1); $vro['leader_name'] = trim($vro['leader_name']); // 行程人数 $vro['personNum_text'] = $poi->COLD_PersonNum + $poi->COLD_ChildNum; $vro['personNum_text'] .= " (" . $poi->COLD_PersonNum . " Adult(s)"; if ($poi->COLD_ChildNum > 0) { $vro['personNum_text'] .= " " . $poi->COLD_ChildNum . " Child(ren)"; } $vro['personNum_text'] .= ")" ; // 人数 $vro['adult_number'] = $order_project[0]->COLD_PersonNum; $vro['kid_number'] = $order_project[0]->COLD_ChildNum; // 酒店 $vro['hotel_name'] = mb_convert_encoding($poi->POI_Hotel, "UTF-8"); $vro['hotel_address'] = mb_convert_encoding($poi->POI_HotelAddress, "UTF-8"); $vro['hotel_tel'] = $poi->POI_HotelPhone; // 航班/车次 $vro['flights_no'] = $poi->POI_FlightsNo; $vro['flights_airport'] = $poi->POI_AirPort; // 接送信息 $vro['pick_up'] = ""; $vro['drop_off'] = ""; $decode_MemoText = $memo_text_tmp = ""; if ($vro['pick_up'] === "" && $poi->COLD_MemoText != null && json_decode($poi->COLD_MemoText) != null) { $decode_MemoText = json_decode($poi->COLD_MemoText, true); $vro['pick_up'] = $decode_MemoText['Pick up']; $vro['drop_off'] = $decode_MemoText['Drop off']; } if ($vro['pick_up'] === "" && $kd == 0) { $vro['pick_up'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Pick Up From:"), "\n", true), 13)); $vro['drop_off'] = trim(substr(strstr(strstr($poi->COLI_OrderDetailText, "Drop Off:"), "\n" , true), 9)); } if ($vro['pick_up'] === "") { if (strval($poi->PAGS_Direction) === '0') { $vro['pick_up'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; $vro['drop_off'] .= $poi->POI_Hotel; } else if (strval($poi->PAGS_Direction) === '1') { $vro['pick_up'] .= $poi->POI_Hotel; $vro['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; } else { // if ($poi->POI_FlightsNo != "") $vro['pick_up'] .= $poi->POI_Hotel; // $vro['drop_off'] .= $poi->POI_FlightsNo . " " . $poi->POI_AirPort; // 结束后送机 } } $vro['leader_name'] = mb_convert_encoding($vro['leader_name'], "UTF-8"); $vro['hotel_name'] = mb_convert_encoding($vro['hotel_name'], "UTF-8"); $vro['hotel_address'] = mb_convert_encoding($vro['hotel_address'], "UTF-8"); $vro['pick_up'] = mb_convert_encoding($vro['pick_up'], "UTF-8"); $vro['drop_off'] = mb_convert_encoding($vro['drop_off'], "UTF-8"); $ret['operation'][] = $vro; } } $ret['operation'] = array_values($ret['operation']); $ret_operation = array(); foreach ($ret['operation'] as $ko => $vo) { if (strtotime($vo['start_date_raw']) >= strtotime($vo['cold_date']) && strtotime($vo['start_date_raw']) <= strtotime($vo['cold_enddate'])) { unset($vo['cold_date']); unset($vo['cold_enddate']); $ret_operation[] = $vo; continue; } } $ret['operation'] = $ret_operation; /** 外联信息 */ $raw_opi_id = 0; if (intval($order_project[0]->COLI_OPI_ID) === 435) { $real_code_info = analysis_groupCode($ret['group_number']); $raw_opi_id = $this->Orders_model->get_gri_opi_id($real_code_info['cut']); } else { $raw_opi_id = $order_project[0]->COLI_OPI_ID; } $operator = $this->Orders_model->get_operator($raw_opi_id); if ( ! empty($operator)) { $ret['operator']['chinese_name'] = mb_convert_encoding($operator->OPI_Name, "UTF-8"); $ret['operator']['mobile'] = $operator->OPI_MoveTelephone; $ret['operator']['email'] = $operator->OPI_Email; $ret['operator']['english_name'] = $operator->OPI2_Name; // 英文名没有 if ($operator->OPI_FirstName == null || $operator->OPI2_Name == null ) { $ret['operator']['english_name'] = ucfirst(strstr($operator->OPI_Email, "@", true)); } } return $this->output->set_content_type('application/json')->set_output(json_encode($ret)); } } /* End of file api.php */ /* Location: ./third_party/trippestOrderSync/controllers/api.php */