convertCtripArray2StandardData($request_array); if( false == $base_request_array ) { return false; } //插入更新数据记录 $res_result = $this->dbOperateTravelProductRequest($base_request_array); if( false == $res_result ) { return false; } $traveller_array = $this->getTravellerArrayFromCtripArray($request_array); if( false != $traveller_array ) { //插入更新出行人信息数据 } return true; } /** * Function Description:插入更新request数据库的实际操作 * Function Name: convertCtripArray2StandardData * * @author Redstop */ public function dbOperateTravelProductRequest( $base_request_array ) { $insert_key_array = array(); $insert_value_array = array(); $update_sql_array = array(); foreach( $base_request_array as $request_key => $request_value ) { $insert_key_array[] = " {$request_key} "; if( is_numeric($request_value) || is_float($request_value) ) { $insert_value_array[] = " {$request_value} "; if( $request_key != "from_org_id" && $request_key != "outside_order_no" ) { $update_sql_array[] = " {$request_key} = {$request_value} "; } } else { $insert_value_array[] = " '{$request_value}' "; if( $request_key != "from_org_id" && $request_key != "outside_order_no" ) { $update_sql_array[] = " {$request_key} = '{$request_value}' "; } } } $excute_sql = " INSERT INTO outside_travel_product_request( id, ".implode( ",", $insert_key_array )." ) VALUE ( NULL, ".implode( ",", $insert_value_array )." ) ". " ON DUPLICATE KEY UPDATE ".implode( ",", $update_sql_array ); $res = Yii::$app->db->createCommand($excute_sql)->execute(); return $res; } /** * Function Description:重置所有出行人信息 * Function Name: dbResetTravellerArray * * @author Redstop */ public function dbResetTravellerArray( $from_org_id, $outside_order_no ) { $update_sql = " UPDATE SET "; } /** * Function Description:操作出行人列表 * Function Name: dbOperateTravellerArray * * @author Redstop */ public function dbOperateTravellerArray($traveller_array) { if( false == $traveller_array ) { return true; } } /*********************************************************************************/ /* Ctrip 数据结构转换为CS数据结构 */ /*********************************************************************************/ /** * Function Description:从携程获取的参数中提取出标准数据格式 * Function Name: convertCtripArray2StandardData * * @author Redstop */ public function convertCtripArray2StandardData( $request_array ) { $return_array = array( "request_time" => date("Y-m-d H:i:s") ); $return_array["from_org_id"] = $this->m_ctrip_org_id;//渠道为携程团队游 $return_array["outside_order_no"] = $request_array["Order"]["OrderId"];//渠道订单号 $return_array["cs_product_code"] = $request_array["Order"]["VendorProductCode"];//产品编号 $return_array["start_date"] = $request_array["Order"]["DepartureDate"];//出发日期 $return_array["message_id"] = $request_array["Order"]["MessageId"];//消息编号 $return_array["sub_channel"] = isset($request_array["Order"]["DistributionChannel"]) ? $request_array["Order"]["DistributionChannel"] : "";//分销渠道 $book_time = str_replace("T", " ", $request_array["Order"]["OrderInfo"]["BookingTime"] ); $book_time = str_replace("Z", "", $book_time ); $return_array["book_time"] = date("Y-m-d H:i:s", strtotime($book_time));//用户预订时间 $return_array["package_code"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["VendorPackageCode"];//套餐编号 $return_array["currency"] = isset($request_array["Order"]["OrderInfo"]["PackageInfo"]["Currency"]) ? $request_array["Order"]["OrderInfo"]["PackageInfo"]["Currency"] : "CNY";//币种 $return_array["exchange_rate"] = isset($request_array["Order"]["OrderInfo"]["PackageInfo"]["ExchangeRate"]) ? $request_array["Order"]["OrderInfo"]["PackageInfo"]["ExchangeRate"] : "1.00";//汇率 $return_array["adult_quantity"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["AdultQuantity"];//成人份数 $return_array["adult_cost_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["AdultCostPrice"];//成人底价 $return_array["adult_sales_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["AdultSalesPrice"];//成人卖价 $return_array["child_quantity"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["ChildQuantity"];//儿童份数 $return_array["child_cost_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["ChildCostPrice"];//儿童底价 $return_array["child_sales_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["ChildSalesPrice"];//儿童卖价 $return_array["single_person_quantity"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["SinglePersonQuantity"];//单房差份数 $return_array["single_person_cost_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["SinglePersonCostPrice"];//单房差底价 $return_array["single_person_sales_price"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["SinglePersonSalesPrice"];//单房差卖价 $return_array["infant_quantity"] = $request_array["Order"]["OrderInfo"]["PackageInfo"]["InfantQuantity"];//婴儿份数 $return_array["start_res_name"] = $request_array["Order"]["OrderInfo"]["BoardingInfo"]["Location"];//出发(集合)地点 $return_array["start_time"] = $request_array["Order"]["OrderInfo"]["BoardingInfo"]["Time"];//出发(集合)时间 $return_array["boarding_price"] = $request_array["Order"]["OrderInfo"]["BoardingInfo"]["Price"];//费用 $return_array["is_paid"] = $request_array["Order"]["OrderInfo"]["IsPaid"] == "true" ? 1 : 0;//是否付款 $return_array["remark"] = isset($request_array["Order"]["OrderInfo"]["Remark"]) ? $request_array["Order"]["OrderInfo"]["Remark"] : "";//备注 if( isset($request_array["Order"]["OrderInfo"]["BookingContact"]) ) { $return_array["contact_name"] = isset($request_array["Order"]["OrderInfo"]["BookingContact"]["Name"]) ? $request_array["Order"]["OrderInfo"]["BookingContact"]["Name"] : "";//联系人姓名 $return_array["contact_mobile"] = isset($request_array["Order"]["OrderInfo"]["BookingContact"]["Mobile"]) ? $request_array["Order"]["OrderInfo"]["BookingContact"]["Mobile"] : "";//联系人电话 } else { $return_array["contact_name"] = "";//联系人姓名 $return_array["contact_mobile"] = "";//联系人电话 } return $return_array; } /** * Function Description:从携程获取的参数中提取出出行人数组 * Function Name: getTravellerArrayFromCtripArray * * @author Redstop */ public function getTravellerArrayFromCtripArray( $request_array ) { if( !isset($request_array["Order"]["OrderInfo"]["TravelerList"]) ) { return false; } $return_array = array(); $traveller_array = $request_array["Order"]["OrderInfo"]["TravelerList"]["Traveler"]; foreach( $traveller_array as $traveller_info ) { $info_tmp = array(); $info_tmp["from_org_id"] = $this->m_ctrip_org_id; $info_tmp["outside_order_no"] = $request_array["Order"]["OrderId"]; $info_tmp["traveler_id"] = $traveller_info["TravelerId"]; $info_tmp["chinese_name"] = $traveller_info["ChineseName"]; $info_tmp["english_name"] = isset($traveller_info["EnglishName"]) ? $traveller_info["EnglishName"] : ""; $info_tmp["gender"] = $traveller_info["Gender"] == "Male" ? 0 :1; $info_tmp["nationality"] = isset($traveller_info["Nationality"]) ? $traveller_info["Nationality"] : ""; $info_tmp["birth_day"] = isset($traveller_info["BirthDate"]) ? $traveller_info["BirthDate"] : ""; $info_tmp["birth_city"] = isset($traveller_info["BirthCity"]) ? $traveller_info["BirthCity"] : ""; $info_tmp["mobile"] = isset($traveller_info["Mobile"]) ? $traveller_info["Mobile"] : ""; $info_tmp["age_category"] = $traveller_info["AgeCategory"]; $info_tmp["id_type"] = isset($traveller_info["IDType"]) ? $traveller_info["IDType"] : ""; $info_tmp["id_number"] = isset($traveller_info["IDNumber"]) ? $traveller_info["IDNumber"] : ""; $info_tmp["issue_date"] = isset($traveller_info["IssuedDate"]) ? $traveller_info["IssuedDate"] : ""; $info_tmp["expired_date"] = isset($traveller_info["ExpiredDate"]) ? $traveller_info["ExpiredDate"] : ""; $info_tmp["issue_place"] = isset($traveller_info["IssuedPlace"]) ? $traveller_info["IssuedPlace"] : ""; $info_tmp["is_room_share"] = $traveller_info["IsRoomShare"] == "true" ? 1 : 0; $traveller_array[] = $info_tmp; } return $traveller_array; } }