diff --git a/application/libraries/bokun_lib.php b/application/libraries/bokun_lib.php new file mode 100644 index 00000000..bdcf6df2 --- /dev/null +++ b/application/libraries/bokun_lib.php @@ -0,0 +1,107 @@ +ci =& get_instance(); + } + + /** + * @description: + * @param string $activityid :产品的ID + * @return: json :产品的详细json数据 + * @Date Changed: + */ + public function get_activity_detail($activityid){ + $path = "/activity.json/$activityid?currency=USD&lang=EN"; + $activity = $this->call_bokun($path,'get'); + return ($activity); + } + + public function get_all_product_list() + { + $path = "/product-list.json/list?lang=EN"; + $product_list = $this->call_bokun($path,'get'); + return ($product_list); + } + + public function get_product_list_detail($list_id) + { + $path = "/product-list.json/$list_id?currency=USD&lang=EN"; + $product_list = $this->call_bokun($path,'get'); + return ($product_list); + } + + public function get_activity_price($bokun_id) + { + $path = "/activity.json/$bokun_id/price-list?currency=USD"; + $price_list = $this->call_bokun($path,'get'); + return ($price_list); + } + + private function make_bokun_signature($date, $method, $path) + { + $raw_str = $date . $this->access_key . strtoupper($method) . $path; + return base64_encode(hash_hmac("sha1", $raw_str, $this->secret_key, TRUE)); + } + + private function call_bokun($path, $method, $body=null) + { + $url = $this->bokun_url . $path; + $create_date = gmdate("Y-m-d H:i:s"); + $bokun_signature = $this->make_bokun_signature($create_date, $method, $path); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_FAILONERROR, false); + curl_setopt($curl, CURLOPT_HEADER, false); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_TIMEOUT, 20); + curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20); + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HTTPHEADER, + array( + "X-Bokun-Date:" . $create_date, + "X-Bokun-AccessKey :" . $this->access_key, + "X-Bokun-Signature :" . $bokun_signature + ) + ); + $set_post = strtoupper($method) === 'GET' ? false : true; + curl_setopt($curl, CURLOPT_POST, $set_post); + // curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); + log_message('debug','call_bokun ' . $method . PHP_EOL . var_export($url, 1)); + $output = curl_exec($curl); + if (curl_errno($curl)) { + log_message('error', "curl error code: ".curl_error($curl)."; curl call: ".$path); + } else { + $httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); + if (200 !== $httpStatusCode) { + log_message('error', "Request html Status Code: ".$httpStatusCode."; curl call: ".$path); + } + } + curl_close($curl); + return $output; + } + + + +} + +/* End of file Bokun_lib.php */ diff --git a/application/third_party/tpmanage/controllers/getbokun.php b/application/third_party/tpmanage/controllers/getbokun.php new file mode 100644 index 00000000..0f13769d --- /dev/null +++ b/application/third_party/tpmanage/controllers/getbokun.php @@ -0,0 +1,288 @@ +load->library("Bokun_lib"); + $this->load->model("tpBokun_model"); + } + + public function index() + { + //echo "bokun数据导入页面!"; + $this->load->view('getindex'); + } + + /* + "activity":{ + "readme":"这个json数据用来记录从bokun接口中获取的数据项", + "id": 75363, //产品activity的ID + "published": false, //不确定是否需要用这个来判断发布 + "title": "Mini Group: 2-Day Beijing Boutique Tour: Forbidden City, Mutianyu Great Wall, Summer Palace and Temple of Heaven", + "description": "", + "excerpt": "", + "requiredCustomerFields": [ + "firstName", + "lastName", + "email", + "phoneNumber", + "nationality", + "passportId" + ], //这个主要是判断passportId在预订表单是否需要录入 + "keyPhoto": { + "id": 343309, + "originalUrl": "https://bokun.s3.amazonaws.com/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg", + "description": "Temple of Heaven", + "alternateText": "Temple of Heaven", + "height": null, + "width": null, + "flags": [], + "derived": [ + { + "name": "large", + "url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=660&h=660", + "cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=660&h=660" + }, + { + "name": "preview", + "url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=300&h=300", + "cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=300&h=300" + }, + { + "name": "thumbnail", + "url": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=80&h=80&fit=crop", + "cleanUrl": "https://bokunprod.imgix.net/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg?w=80&h=80&fit=crop" + } + ], + "fileName": "/ddaf9b4b-72b0-4062-9978-7a060bda32d4.jpg" + }, //产品主要图片 + "photos": [ + { + "id": 343297, + "originalUrl": "https://bokun.s3.amazonaws.com/8b40e352-6410-4e43-a150-21ad918188d3.jpg", + "description": "Bird view of Forbidden City from Jingshan Park", + "alternateText": "Bird view of Forbidden City from Jingshan Park", + "height": null, + "width": null, + "flags": [], + "derived": [ + { + "name": "large", + "url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=660&h=660", + "cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=660&h=660" + }, + { + "name": "preview", + "url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=300&h=300", + "cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=300&h=300" + }, + { + "name": "thumbnail", + "url": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=80&h=80&fit=crop", + "cleanUrl": "https://bokunprod.imgix.net/8b40e352-6410-4e43-a150-21ad918188d3.jpg?w=80&h=80&fit=crop" + } + ], + "fileName": "/8b40e352-6410-4e43-a150-21ad918188d3.jpg" + } + ], //产品其它图片 + "included": "
" . $ContentItem->excerpt . "
"; + } + + if ($strTemp != "") { + $strContent .= "" . $activityDeatil->excerpt . "
"; + } + $this->tpBokun_model->ic_summary = $temp_summary; + + //seo + $this->tpBokun_model->ic_seo_title = character_limiter($title, 100); + $this->tpBokun_model->ic_seo_description = character_limiter(strip_tags($activityDeatil->description), 200); + $tempKeywords = $activityDeatil->keywords; + if (is_array($tempKeywords) && count($tempKeywords) > 0) { + $this->tpBokun_model->ic_seo_keywords = implode(",", $tempKeywords); + } + $this->tpBokun_model->ic_status = 1; + + $tempData = json_decode($this->tpBokun_model->addInfo($is_id)); + if (is_array($tempData)) { + $ic_id = $tempData[0]->value->ic_id; + } else { + $result["status"] = "error"; + echo json_encode($result); + } + + //4.附加属性添加(infometa表及新建的infoBokunData表) + if ($ic_id > 0) { + + //先旧的infometa表 + $tempRequireFileds = $activityDeatil->requiredCustomerFields; //根据抓取的需求字段,判断是否需要passport + if (is_array($tempRequireFileds)) { + if (in_array("passportId", $tempRequireFileds[0])) { + $this->tpBokun_model->addMeta($ic_id, "meta_trippest_type", "gg"); + } + } + $this->tpBokun_model->addMeta($ic_id, "meta_product_code", $PAG_Code); //对应翰特编码 + $this->tpBokun_model->addMeta($ic_id, "meta_facts_city", $activityDeatil->googlePlace->city); //保存一下具体城市 + + //然后保存新建的infobokunData表 + $this->InfoBokunData_model->ibd_ic_id = $ic_id; //统一的 + + $this->InfoBokunData_model->ibd_ItemName = "ActivityID"; + $this->InfoBokunData_model->ibd_Itemvalue = $activityid; + $ibd_id = $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_parentId = $ibd_id; //设置剩余的属性都是这个activityid的子类,避免每条记录都保存activityid + + $this->InfoBokunData_model->ibd_ItemName = "keyPhoto"; //主要图片 + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->keyPhoto->originalUrl; + $this->InfoBokunData_model->ibd_ItemType = "originalUrl"; + $this->InfoBokunData_model->Add(); + $arrKeyPhoto = $activityDeatil->keyPhoto->derived; //主要图片派生图,大中小类型 + if (is_array($arrKeyPhoto)) { + foreach ($arrKeyPhoto as $kPhotoItem) { + $this->InfoBokunData_model->ibd_Itemvalue = $kPhotoItem->url; + $this->InfoBokunData_model->ibd_ItemType = $kPhotoItem->name; + $this->InfoBokunData_model->Add(); + } + } + + $arrProductPhoto = $activityDeatil->photos; //产品主要图片 + if (is_array($arrProductPhoto)) { + foreach ($arrProductPhoto as $pPhotoItem) { + $this->InfoBokunData_model->ibd_ItemName = "ProductPhoto"; + $this->InfoBokunData_model->ibd_Itemvalue = $pPhotoItem->originalUrl; + $this->InfoBokunData_model->ibd_ItemType = "originalUrl"; + $this->InfoBokunData_model->Add(); + + $arrProductPhotoDerived = $pPhotoItem->derived; //产品主要图片的派生图,大中小类型 + if (is_array($arrProductPhotoDerived)) { + foreach ($arrProductPhotoDerived as $pPhotoDerivedItem) { + $this->InfoBokunData_model->ibd_Itemvalue = $pPhotoDerivedItem->url; + $this->InfoBokunData_model->ibd_ItemType = $pPhotoDerivedItem->name; + $this->InfoBokunData_model->Add(); + } + } + } + } + + + //一些FAQ类的属性,如included,requirements + $this->InfoBokunData_model->ibd_ItemName = "included"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->included; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "excluded"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->excluded; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "requirements"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->requirements; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "attention"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->attention; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "country"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->googlePlace->country; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "city"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->googlePlace->city; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + $this->InfoBokunData_model->ibd_ItemName = "durationText"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->durationText; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + + if ($activityDeatil->noPickupMsg != null && $activityDeatil->noPickupMsg != "") { + $this->InfoBokunData_model->ibd_ItemName = "noPickupMsg"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->noPickupMsg; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + } + + if ($activityDeatil->ticketMsg != null && $activityDeatil->ticketMsg != "") { + $this->InfoBokunData_model->ibd_ItemName = "ticketMsg"; // + $this->InfoBokunData_model->ibd_Itemvalue = $activityDeatil->ticketMsg; + $this->InfoBokunData_model->ibd_ItemType = ""; + $this->InfoBokunData_model->Add(); + } + + $arrAgendaItems = $activityDeatil->agendaItems; //保存产品行程里面的派生图片 + if (is_array($arrAgendaItems)) { + foreach ($arrAgendaItems as $agendaItem) { + if ($agendaItem->keyPhoto != null && $agendaItem->keyPhoto != "") { + $this->InfoBokunData_model->ibd_ItemName = "AgendaPhoto"; + $this->InfoBokunData_model->ibd_Itemvalue = $agendaItem->keyPhoto->originalUrl; + $this->InfoBokunData_model->ibd_ItemDescription = $$agendaItem->keyPhoto->description; + $this->InfoBokunData_model->ibd_ItemType = "originalUrl"; + $this->InfoBokunData_model->Add(); + } + + $arrAgendaItemPhotos = $agendaItem->photos; + if (is_array($arrAgendaItemPhotos)) { + foreach ($arrAgendaItemPhotos as $agendaPhotoItem) { + $this->InfoBokunData_model->ibd_ItemName = "AgendaPhoto"; + $this->InfoBokunData_model->ibd_Itemvalue = $agendaPhotoItem->originalUrl; + $this->InfoBokunData_model->ibd_ItemType = "originalUrl"; + $this->InfoBokunData_model->ibd_ItemDescription = $agendaPhotoItem->description; + $this->InfoBokunData_model->Add(); + } + } + } + } + } else { + $result["status"] = "error"; + echo json_encode($result); + } + + //5. 返回成功信息 + $result["status"] = "ok"; + $result["ic_id"] = $ic_id; + echo json_encode($result); + } + } + + /** + * @description: 根据城市名称,获取对应的is_id,判断产品放到信息平台的位置 + * @param {type} + * @return: int is_id :城市所在信息平台的Id + * @Date Changed: + */ + function get_isid_byCity($CityName) + { + $cityUrl = "/" . str_replace("'", "", str_replace(' ', '-', strtolower($CityName))) . "-" . "tours/"; + $row = $this->tpBokun_model->getInfomationAll($cityUrl); + if (isset($row)) { + $result = $row->is_id; + } else { + $result = $this->tpBokun_model->is_topId; + } + return $result; + } + + /** + * @description: 为了方便,首先循环添加所有的城市目录 + * @param {type} + * @return: + * @Date Changed: + */ + function checkAllCity() + { + $str_return = ""; + $result = $this->bokun_lib->get_all_product_list(); + //print_r($result); + $result = json_decode($result); + if (is_array($result) && count($result) > 0) { + //productlist是所有产品,按城市分类,然后child里面是类别分类 + foreach ($result as $pItem) { + $cityName = $pItem->title; //城市名称,用来判断信息平台是否有该城市 + if (isset($cityName)) { + $infoCity = json_decode($this->doInfoCity($cityName)); //获取导入的城市名称为父类,下面的产品在信息平台里面放在这个的下面 + if ($infoCity->type == "new") { + $str_return .= $infoCity->cityname . ","; + } + } + } + } + if ($str_return != "") { + echo "新城市添加:" . $str_return."\r\n"; + } else { + echo "没有新的城市"."\r\n"; + } + } + + + /** + * @description: 判断信息平台是否有该城市的记录,没有则添加。/beijing-tours/ + * @param {type} + * @return: 返回info的is_id ,作为父类ID + * @Date Changed: + */ + function doInfoCity($CityName) + { + $cityUrl = "/" . str_replace("'", "", str_replace(' ', '-', strtolower($CityName))) . "-" . "tours/"; + $infoDetail = $this->tpBokun_model->getInfomationAll($cityUrl); + if (isset($infoDetail)) { + //如果存在 + $result["Id"] = $infoDetail->is_id; + $result["cityname"] = $infoDetail->ic_title; + $result["type"] = "old"; + } else { + //如果不存在就录入 + $this->tpBokun_model->ic_title = ucwords($CityName) . " Tours"; + $this->tpBokun_model->ic_url_title = ucwords($CityName) . " Tours"; + $this->tpBokun_model->ic_url = $cityUrl; + $tempData = json_decode($this->tpBokun_model->addInfo($this->tpBokun_model->is_topId)); + if (is_array($tempData)) { + $result["Id"] = $tempData[0]->value->is_id; + $result["cityname"] = $CityName; + $result["type"] = "new"; + } else { + $result["Id"] = 0; + $result["cityname"] = ""; + $result["type"] = "error"; + } + } + + return json_encode($result); + } + + + /** + * @description: 网前只抓取信息平台的信息。由于产品的翰特编码都是yong bk_activityid的规则组成,所以分开更新是可能的。这样可以保证不需要理会本地和网前的处理速度 + * @param sring $city : 城市名称 。用来单独更新某个城市 + * @return: + * @Date Changed: + */ + function onlyUpdateInfo($city = "") + { + //先进行对应城市的更新 + $this->checkAllCity(); + + //循环接口开始 + $result = $this->bokun_lib->get_all_product_list(); + //print_r($result); + $result = json_decode($result); + if (is_array($result) && count($result) > 0) { + //productlist是所有产品,按城市分类,然后child里面是类别分类 + foreach ($result as $pItem) { + $cityName = str_replace("'", "", $pItem->title); //城市名称,用来判断信息平台是否有该城市 + if (isset($cityName)) { + if ($city != "" && strtolower($city) != strtolower($cityName)) { + continue; //如果设置了指定抓取城市 + } else { + + $list_id = $pItem->id; + $pchild_Detail = $this->bokun_lib->get_product_list_detail($list_id); + $data_pchild_Detail = json_decode($pchild_Detail); //类别详细 + foreach ($data_pchild_Detail->items as $pcdItem) { //循环类别 + $activityData = $pcdItem->activity; //产品详细内容 + //解析后获取需要的参数 + $activityId = $activityData->id; //产品的activityId,可以获取对应的产品详细内容。 + //先判断是否是新产品 + $checkNew = json_decode($this->tpBokun_model->checkActivityId($activityId)); + if ($checkNew->return == "yes") { + continue; + } + //提交网前接口 + $PAGCode = "bk_" . $activityId; + $checkCode = "cits"; //用来防止参数被破解 + $PassParam["activityid"] = $activityId; + $PassParam["PAG_Code"] = $PAGCode; + $PassParam["CityName"] = $cityName; + $PassParam["checkCode"] = $checkCode; + $strPass = base64_encode(json_encode($PassParam)); + $this->addActivity($strPass); + echo "\r\n" ; + } + } + } + } + echo ("抓取完成!\r\n"); + } else { + echo "无接口数据!\r\n"; + } + } +} + +/* End of file webgetbokun.php */ diff --git a/application/third_party/tpmanage/models/iContent_model.php b/application/third_party/tpmanage/models/iContent_model.php new file mode 100644 index 00000000..49ce4cfc --- /dev/null +++ b/application/third_party/tpmanage/models/iContent_model.php @@ -0,0 +1,168 @@ +HT = $this->load->database('HT', TRUE); + } + + function Add($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords, + $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages, + $ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author) + { + $ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url3'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_org2'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace('#textarea#', 'textarea',$ic_content); + $sql = "INSERT INTO infoContents \n" + . " ( \n" + . " ic_url, ic_url_title, ic_type, ic_title, ic_content, ic_summary, ic_seo_title, \n" + . " ic_seo_description, ic_seo_keywords, ic_show_bread_crumbs, ic_status, \n" + . " ic_template, ic_photo,ic_photo_width,ic_photo_height, ic_sitecode, ic_recommend_tours, ic_recommend_packages, \n" + . " ic_ht_area_id, ic_ht_area_type,ic_ht_product_id,ic_ht_product_type,ic_author, ic_datetime \n" + . " ) \n" + . "VALUES \n" + . " ( N?,N?,?,N?,N?,N?,N?,N?,N?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,getdate() )"; + $query = $this->HT->query($sql, + array($ic_url, $ic_url_title, $ic_type, $ic_title, str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'), + $ic_content), + $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status, + $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, "trippest", $ic_recommend_tours, $ic_recommend_packages, + $ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author)); + $this->insert_id = $this->HT->last_id('infoContents'); + return $query; + } + + function Update($ic_id, $ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, $ic_seo_title, $ic_seo_description, $ic_seo_keywords, + $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, $ic_recommend_tours, $ic_recommend_packages, + $ic_ht_area_id, $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author) + { + $ic_content=str_replace('http:'.$this->config->item('site_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url2'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_org'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_remote'), $this->config->item('site_image_url'),$ic_content); + $ic_content=str_replace($this->config->item('media_image_url_remote2'), $this->config->item('site_image_url'),$ic_content); + $sql = "UPDATE infoContents \n" + . "SET ic_url = N?, \n" + . " ic_url_title = N?, \n" + . " ic_type = ?, \n" + . " ic_title = N?, \n" + . " ic_content = N?, \n" + . " ic_summary = N?, \n" + . " ic_seo_title = N?, \n" + . " ic_seo_description = N?, \n" + . " ic_seo_keywords = N?, \n" + . " ic_show_bread_crumbs = ?, \n" + . " ic_status = ?, \n" + . " ic_template = ?, \n" + . " ic_photo = ?, \n" + . " ic_photo_width = ?, \n" + . " ic_photo_height = ?, \n" + . " ic_recommend_tours = ?, \n" + . " ic_recommend_packages = ?, \n" + . " ic_datetime = GETDATE() , \n" + . " ic_ht_area_id = ?, \n" + . " ic_ht_area_type = ?, \n" + . " ic_ht_product_id = ?, \n" + . " ic_ht_product_type = ?, \n" + . " ic_author = ? \n" + . "WHERE ic_id = ? \n" + . "AND ic_sitecode = ? "; + $query = $this->HT->query($sql, + array($ic_url, $ic_url_title, $ic_type, $ic_title, $ic_content, $ic_summary, + $ic_seo_title, $ic_seo_description, $ic_seo_keywords, $ic_show_bread_crumbs, $ic_status, $ic_template, $ic_photo, $ic_photo_width, $ic_photo_height, + $ic_recommend_tours, $ic_recommend_packages, $ic_ht_area_id, + $ic_ht_area_type, $ic_ht_product_id, $ic_ht_product_type,$ic_author, $ic_id,"trippest")); + return $query; + } + + //删除信息 + function force_update($ic_id, $ic_content) + { + $sql = "UPDATE infoContents SET ic_content = N? WHERE ic_id = ?"; + $query = $this->HT->query($sql, array($ic_content, $ic_id)); + return $query; + } + + //删除信息 + function Delete($ic_id) + { + $sql = "DELETE \n" + . "FROM infoContents \n" + . "WHERE ic_id = ?"; + $query = $this->HT->query($sql, array($ic_id)); + return $query; + } + + //递增浏览量 + function inc_views($sitecode,$page_url) + { + //查询信息需要过滤url上的域名 + if($page_url && $sitecode) + { + $page_url=substr($page_url,strpos($page_url,'/',8));//过滤掉url前面的http:// + $sql = "UPDATE infoContents \n" + . "SET ic_view = ISNULL(ic_view,0) + 1 \n" + . "WHERE ic_sitecode = ? AND ic_url = N?"; + return $this->HT->query($sql,array($sitecode,$page_url)); + } + } + + public function get_ic_contents($ic_id) + { + $sql="SELECT top 1 ic_id from infoContents where ic_id=?"; + $query=$this->HT->query($sql,array($ic_id)); + if ($query->result()) + { + $row = $query->row(); + return $row; + } + else + { + return FALSE; + } + } + + public function get_ic_contents2($ic_id) + { + $sql="SELECT top 1 ic_id, ic_content, ic_title, ic_url, ic_photo, ic_sitecode, ic_seo_description from infoContents where ic_id=?"; + $query=$this->HT->query($sql,array($ic_id)); + if ($query->result()) + { + $row = $query->row(); + return $row; + } + else + { + return FALSE; + } + } + + public function get_ic_contents_by_list($ic_id_list) + { + $ic_id_list=trim($ic_id_list); + $ic_id_list.=0; + $sql="SELECT * from infoContents where ic_id in ($ic_id_list) order by charindex(','+ltrim(ic_id)+',', ',$ic_id_list,')"; + $query=$this->HT->query($sql); + if ($query->result()) + { + $row = $query->result(); + return $row; + } + else + { + return FALSE; + } + } +} \ No newline at end of file diff --git a/application/third_party/tpmanage/models/iStructures_model.php b/application/third_party/tpmanage/models/iStructures_model.php new file mode 100644 index 00000000..9fa18643 --- /dev/null +++ b/application/third_party/tpmanage/models/iStructures_model.php @@ -0,0 +1,219 @@ +HT = $this->load->database('HT', TRUE); + } + + function Detail($is_id) + { + $sql = "SELECT TOP 1 is1.is_id, \n" + . " is1.is_parent_id, \n" + . " is1.is_path, \n" + . " is1.is_level, \n" + . " is1.is_sort, \n" + . " is1.is_sitecode, \n" + . " is1.is_datetime, \n" + . " is1.is_ic_id \n" + . "FROM infoStructures is1 \n" + . "WHERE is1.is_id = ?"; + $query = $this->HT->query($sql, array($is_id)); + //print_r($this->HT->queries); + if ($query->result()) + { + $row = $query->row(); + return $row; + } + else + { + return FALSE; + } + } + + function Add($is_parent_id, $is_ic_id=-1) + { + if ($is_parent_id == 0) + { + $is_path = ''; + $is_level = 1; + $is_sort = 999; + } + else + { + $infoStructure = $this->Detail($is_parent_id); + if ($infoStructure) + { + $is_path = $infoStructure->is_path; + $is_level = $infoStructure->is_level + 1; + $is_sort = 999; + } + else + { + return false; + } + } + $sql = "INSERT INTO infoStructures \n" + . " ( \n" + . " is_parent_id, is_path, is_level, is_sort, is_sitecode, is_datetime, is_ic_id \n" + . " ) \n" + . "VALUES \n" + . " ( \n" + . " ?, ?, ?, ?, ?, getdate(), ? \n" + . " )"; + $query = $this->HT->query($sql, array($is_parent_id, $is_path, $is_level, $is_sort, "trippest", $is_ic_id)); + $this->insert_id = $this->HT->last_id('infoStructures'); + //把自己的ID加到path上 + $set_sql = "UPDATE infoStructures \n" + . "SET is_path = is_path + CONVERT(VARCHAR(200), is_id) + ',' \n" + . "WHERE is_id = ?"; + $query = $this->HT->query($set_sql, array($this->insert_id)); + + return $this->insert_id; + } + + function GetParent($is_path, $level=1) + { + if ($is_path == '') + { + return false; + } + $sql = "SELECT TOP 1 is1.is_id, \n" + . " is1.is_parent_id, \n" + . " is1.is_path, \n" + . " is1.is_level, \n" + . " is1.is_sort, \n" + . " is1.is_sitecode, \n" + . " is1.is_datetime, \n" + . " is1.is_ic_id \n" + . "FROM infoStructures is1 \n" + . "WHERE is1.is_level = ? \n" + . " AND is1.is_id IN ($is_path 0) \n" + . "ORDER BY \n" + . " is1.is_id ASC"; + $query = $this->HT->query($sql, array($level)); + // print_r($this->HT->queries); + if ($query->result()) + { + $row = $query->row(); + return $row; + } + else + { + return FALSE; + } + } + + //查询节点的根节点 + function get_root($is_id) + { + $detail = $this->Detail($is_id); + $root = $this->GetParent($detail->is_path, 1); + if ($root) + { + return $root; + } + else + { //没有根节点则返回本节点 + return $detail; + } + } + + //判断是否有子节点 + function HasChild($is_id) + { + $sql = "SELECT TOP 1 is1.is_id \n" + . "FROM infoStructures is1 \n" + . "WHERE is1.is_parent_id = ?"; + $query = $this->HT->query($sql, array($is_id)); + if ($query->result()) + { + return true; + } + else + { + return FALSE; + } + } + + //删除节点 + function Delete($is_id) + { + $sql = "DELETE \n" + . "FROM infoStructures \n" + . "WHERE is_id = ?"; + $query = $this->HT->query($sql, array($is_id)); + return $query; + } + + //设置排序 + function set_sort($is_id, $sort) + { + $sql = "UPDATE infoStructures \n" + . "SET is_datetime = GETDATE(), \n" + . " is_sort = ? \n" + . "WHERE is_id = ?"; + $query = $this->HT->query($sql, array($sort, $is_id)); + //print_r($this->HT->queries); + return $query; + } + + //设置路径 + function set_path($parent_id, $is_id) + { + $structure = $this->Detail($is_id); + //如果父级相同则不需要重新设置path + if ($parent_id == $structure->is_parent_id) + { + return true; + } + $parent = $this->Detail($parent_id); + //设置当前节点 + $set_parent_id = $parent->is_id; + $set_level = $parent->is_level + 1; + $set_path = $parent->is_path . $is_id . ','; + + $set_sql = "UPDATE infoStructures \n" + . "SET is_parent_id = ?, \n" + . " is_level = ?, \n" + . " is_path = ? \n" + . "WHERE is_id = ?"; + $this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $is_id)); + + $structure = $this->Detail($is_id); + + //查询当前节点的所有子节点 + $sql = "SELECT is1.is_id, \n" + . " is1.is_parent_id, \n" + . " is1.is_path, \n" + . " is1.is_level, \n" + . " is1.is_sort \n" + . "FROM infoStructures is1 \n" + . "WHERE ',' + is1.is_path LIKE '%,$structure->is_id,%' \n" + . "ORDER BY \n" + . " is1.is_level ASC "; + $query = $this->HT->query($sql); + foreach ($query->result() as $item) + { + if ($item->is_parent_id != $structure->is_id) + { + $structure = $this->Detail($item->is_parent_id); + } + $set_parent_id = $structure->is_id; + $set_level = $structure->is_level + 1; + $set_path = $structure->is_path . $item->is_id . ','; + $set_sql = "UPDATE infoStructures \n" + . "SET is_parent_id = ?, \n" + . " is_level = ?, \n" + . " is_path = ? \n" + . "WHERE is_id = ?"; + $this->HT->query($set_sql, array($set_parent_id, $set_level, $set_path, $item->is_id)); + } + } + +} \ No newline at end of file diff --git a/application/third_party/tpmanage/models/tpBokun_model.php b/application/third_party/tpmanage/models/tpBokun_model.php new file mode 100644 index 00000000..fc160794 --- /dev/null +++ b/application/third_party/tpmanage/models/tpBokun_model.php @@ -0,0 +1,292 @@ +HT = $this->load->database('HT', TRUE); + $this->load->model("IContent_model"); + $this->load->model("IStructures_model"); + $CI = &get_instance(); + } + + /** + * 获取信息平台的内容,所有信息,包含发布和没发布的 + */ + function getInfomationAll($guideurl) + { + // $sql = "select top 1 * from infoContents a inner join infoStructures b on a.ic_id=b.is_ic_id where ic_URL='".$guideurl."' and ic_status=1 and is_siteCode='ct'"; + $sql = "select top 1 * from infoContents a inner join infoStructures b on a.ic_id=b.is_ic_id where ic_URL='" . $guideurl . "' and is_siteCode='" . Site_Code . "'"; + $query = $this->HT->query($sql); + if ($query->num_rows() > 0) { + return $query->row(); + } else { + return null; + } + } + + /** + * @description: 检查是否是新的bokun产品,根据infobokundata表的activityid记录 + * @param {type} + * @return: + * @Date Changed: + */ + function checkActivityId($activityid) + { + $sql = "select top 1 * from infobokundata where ibd_itemname='ActivityID' and CONVERT(varchar(100),ibd_itemvalue)=?"; + $query = $this->HT->query($sql, array($activityid)); + if ($query->num_rows() > 0) { + $result["return"] = "yes"; + } else { + $result["return"] = "no"; + } + return json_encode($result); + } + + + + /** + * @description: 根据城市名称获取城市ID + * @param string $cityname:城市名称 + * @return: + * @Date Changed: + */ + function getCityIdByName($cityname) + { + $sql = "select top 1 CII2_CII_SN from CItyInfo2 where CII2_Name = '" . $cityname . "' and CII2_LGC=1"; + $query = $this->HT->query($sql); + if ($query->num_rows() > 0) { + return $query->row(); + } else { + return null; + } + } + + /**-------------------抓取程序------------------------- */ + var $is_topId = "278000665"; //产品的最高级父类 + + //ic_content表的字段 + var $ic_url = ""; + var $ic_url_title = "New Information"; + var $ic_type = ""; + var $ic_title = ""; + var $ic_content = ""; + var $ic_summary = ""; + var $ic_seo_title = ""; + var $ic_seo_description = ""; + var $ic_seo_keywords = ""; + var $ic_show_bread_crumbs = 0; + var $ic_status = 0; + var $ic_template = ""; + var $ic_photo = ""; + var $ic_photo_width = 0; + var $ic_photo_height = 0; + var $ic_recommend_tours = ""; + var $ic_recommend_packages = ""; + var $ic_ht_area_id = 0; + var $ic_ht_area_type = ""; + var $ic_ht_product_id = 0; + var $ic_ht_product_type = ""; + var $ic_author = ""; + + /** + * @description: 添加一条信息平台信息 + * @param string $PAG_Code 翰特产品的编码 + * @return: + * @Date Changed: + */ + public function addInfo($is_parent_id, $PAG_Code = "") + { + + if ($is_parent_id == $this->is_topId) { + //这个是城市级别的数据添加 + + } else { + //产品添加 + } + + //添加. + $this->IContent_model->Add( + $this->ic_url, + $this->ic_url_title, + $this->ic_type, + $this->ic_title, + $this->ic_content, + $this->ic_summary, + $this->ic_seo_title, + $this->ic_seo_description, + $this->ic_seo_keywords, + $this->ic_show_bread_crumbs, + $this->ic_status, + $this->ic_template, + $this->ic_photo, + $this->ic_photo_width, + $this->ic_photo_height, + $this->ic_recommend_tours, + $this->ic_recommend_packages, + $this->ic_ht_area_id, + $this->ic_ht_area_type, + $this->ic_ht_product_id, + $this->ic_ht_product_type, + $this->ic_author + ); + $infocontent = $this->IContent_model->get_ic_contents($this->IContent_model->insert_id); + if (!empty($infocontent) && $this->IStructures_model->Add($is_parent_id, $this->IContent_model->insert_id)) { + $is_id = $this->IStructures_model->insert_id; + $InfoStructures = $this->IStructures_model->Detail($is_id); + $InfoStructures->is_id = $is_id; + $InfoStructures->ic_id = $infocontent->ic_id; + $data[] = array('name' => 'ok', 'value' => $InfoStructures); + } else { + $data[] = array('name' => 'no', 'value' => 'form_info_error'); + } + return json_encode($data); + } + + /**---------Meta表的操作----------- */ + function addMeta($im_ic_id, $im_key, $im_value) + { + $sql = "INSERT INTO infoMetas \n" + . " ( \n" + . " im_ic_id, im_key, im_value \n" + . " ) \n" + . "VALUES \n" + . " ( \n" + . " ?, ?, N? \n" + . " )"; + return $this->HT->query($sql, array($im_ic_id, $im_key, (string) $im_value)); + } + + + /**----------翰特入库--------------- */ + var $pag_sn; + var $PAG_CII_SN = 0; + var $PAG_Code = ""; + var $PAG_Scheme = "1,2,3,4,5,6,7"; + var $PAG_Title = ""; + var $PAG_DEI_SN = "34"; + var $PAG_PPI_SN = 0; //存放activityid + + var $PAG2_LGC = 1; + var $PAG2_Name = ""; + var $PAG2_Title = ""; + + + /** + * @description: 添加产品信息到翰特 + * @param {type} + * @return: + * @Date Changed: + */ + function AddProductToHT() + { + $sql = " + INSERT INTO [BIZ_PackageInfo] + ([PAG_CII_SN] + ,[PAG_Code] + ,[PAG_Scheme] + ,[CreatTime] + ,[PAG_Title] + ,[PAG_DEI_SN] + ,[PAG_PPI_SN] + ) + VALUES + ( ?,?,?,GETDATE(),?,?,?) + "; + + $query = $this->HT->query($sql, array( + $this->PAG_CII_SN, + $this->PAG_Code, + $this->PAG_Scheme, + $this->PAG_Title, + $this->PAG_DEI_SN, + $this->PAG_PPI_SN + )); + $this->pag_sn = $this->HT->query("select max(pag_sn) as pag_sn from BIZ_PackageInfo")->row("pag_sn"); + + //插入语种表 + + + $sql2 = " + INSERT INTO [BIZ_PackageInfo2] + ([PAG2_PAG_SN] + ,[PAG2_LGC] + ,[PAG2_Name] + ,[PAG2_Title] + ) + VALUES + (?,?,?,?) + "; + + //录入中,英两个语种 + for ($i = 1; $i < 3; $i++) { + $this->HT->query($sql2, array( + $this->pag_sn, + $i, + $this->PAG2_Name, + $this->PAG2_Title + )); + } + + return $this->pag_sn; + } + + + + + /**------其它一些公用函数--- */ + + /** + * @description: 抓取页面程序 + * @param string $url 抓取地址 + * @param string $data 传递的参数 + * @return: + * @Date Changed: + */ + function getCrulData($url, $data = '', $method = 'GET') + { + $curl = curl_init(); // 启动一个CURL会话 + curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 + curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 + curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer + if ($method == 'POST' && !empty($data)) { + curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 + curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); + } + curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_TIMEOUT_MS, 40000); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 + $tmpInfo = curl_exec($curl); // 执行操作 + $errno = curl_errno($curl); + if ($errno !== 0) { + return false; + echo $errno . curl_error($curl); //记录错误日志 + } + curl_close($curl); //关闭CURL会话 + return $tmpInfo; //返回数据 + } + + /** + * @description: 过滤掉特殊字符 + * @param {type} + * @return: + * @Date Changed: + */ + function match_chinese($chars,$encoding='utf8'){ + $pattern =($encoding=='utf8')?'/[\x{4e00}-\x{9fa5}a-zA-Z0-9]/u':'/[\x80-\xFF]/'; + preg_match_all($pattern,$chars,$result); + return join('',$result[0]); + } +} + +/* End of file TpBokun_model.php */ diff --git a/application/third_party/tpmanage/views/getindex.php b/application/third_party/tpmanage/views/getindex.php new file mode 100644 index 00000000..fc90e13e --- /dev/null +++ b/application/third_party/tpmanage/views/getindex.php @@ -0,0 +1,55 @@ ++ |
+
+
+
+
+
+
+
+ |
+
+ 由于涉及HT,所以更新主程序需要运行在本地:http://202.103.68.144:65008/info.php/thirdparty/tpmanage/getbokun/,网前信息平台的有另外单独的更新程序。 +第一步,可以先单独抓取更新所有的城市信息,这样可以先保证城市信息的完整。 + + + + |
+
+ | 请等待:当前进度:0% | ++ |
+ |