You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/third_party/tpmanage/controllers/getbokun.php

289 lines
12 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
defined('BASEPATH') or exit('No direct script access allowed');
class getbokun extends CI_Controller
{
var $webUrl = "http://localhost:105";
public function __construct()
{
parent::__construct();
$this->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": "<ul><li></li></ul> ", //包含
"excluded": "<ul><li></li></ul> ",//不包含
"requirements": "<ul><li></li></ul> ", //需求
"attention": "<ul><li></li></ul> ", //景点条例与上面4个合并到
"country": "China",
"city": "Beijing",
"durationText": "2 days",
"agendaItems": [{
"title": "",
"excerpt": "",
"body": "",
"day": 1,
"keyPhoto":{}
"photos":[{}]
}
], //行程描述,合并后放信息平台的详细内容里面,其中行程图片和整个产品图片一样,放头部
}
}
*/
/**
* @description: 获取bokunapi的所有产品数据按城市,类别,产品一步步的循环录入
* @param string $city 城市名称
* @return:
*/
function getAll_Bokun($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; //产品详细内容
$this->doActivity($activityData, $cityName);
}
}
}
}
} else {
echo "无接口数据!";
}
}
/**
* @description: 处理每个产品activity),分析及入库
* @param {type} $ActivityData: 产品的JSON数据
* @param string $CityName:因为activity里面的城市名称和总分类的名称可能不一样比如bagan,详细里面是old bagan。直接传递
* @param bool $OverWrive:是否覆盖已导入的产品
* @return:
* @Date Changed:
*/
function doActivity($ActivityData, $CityName = "", $OverWrive = false)
{
// print_r($ActivityData);
// die();
//解析后获取需要的参数
$activityId = $ActivityData->id; //产品的activityId可以获取对应的产品详细内容。
//先判断是否是新产品
$checkNewUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/checkActivityId/$activityId/";
$checkNew = json_decode($this->tpBokun_model->getCrulData($checkNewUrl));
if ($checkNew->return == "yes" && $OverWrive == false) {
return;
}
//提交网前接口
$PAGCode = "bk_" . $activityId;
$checkCode = "cits"; //用来防止参数被破解
$PassParam["activityid"] = $activityId;
$PassParam["PAG_Code"] = $PAGCode;
$PassParam["CityName"] = $CityName;
$PassParam["checkCode"] = $checkCode;
$strPass = base64_encode(json_encode($PassParam));
$AddUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/addActivity/$strPass/";
$addInfo = json_decode($this->tpBokun_model->getCrulData($AddUrl));
//echo($addInfo);
if ($addInfo->status == "ok") {
//提交本地翰特保存
if ($CityName == "") {
$CityName = $ActivityData->googlePlace->city; //如果没有传递城市名称参数就获取activity数据中的
}
$PAG_CII_SN = $this->tpBokun_model->getCityIdByName($CityName);
if ($PAG_CII_SN != null) {
$this->tpBokun_model->PAG_CII_SN = $PAG_CII_SN->CII2_CII_SN;
}
$this->tpBokun_model->PAG_Code = $PAGCode;
$this->tpBokun_model->PAG_Title = $ActivityData->title;
$this->tpBokun_model->PAG_PPI_SN = $ActivityData->id;
$this->tpBokun_model->PAG2_Name = $ActivityData->title;
$this->tpBokun_model->PAG2_Title = $ActivityData->description;
$pagsn = $this->tpBokun_model->AddProductToHT();
}
}
/**
* @description: 提交到前端接口,执行更新所有城市的操作
* @param {type}
* @return:
* @Date Changed:
*/
function checkAllCity()
{
$url = "/guide.php/thirdparty/tpmanage/webgetbokun/checkAllCity/";
$str = $this->tpBokun_model->getCrulData($url);
echo $str;
}
/**
* @description: 只更新翰特的产品信息
* @param {type}
* @return:
* @Date Changed:
*/
function onlyUpdateHT($city = "")
{
//循环接口开始
$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; //产品详细内容
//提交本地翰特保存
if ($cityName == "") {
$cityName = $activityData->googlePlace->city; //如果没有传递城市名称参数就获取activity数据中的
}
$PAG_CII_SN = $this->tpBokun_model->getCityIdByName($cityName);
if ($PAG_CII_SN != null) {
$this->tpBokun_model->PAG_CII_SN = $PAG_CII_SN->CII2_CII_SN;
}
//解析后获取需要的参数
$activityId = $activityData->id; //产品的activityId可以获取对应的产品详细内容。
//先判断是否是新产品
$checkNewUrl = $this->webUrl . "/guide.php/thirdparty/tpmanage/webgetbokun/checkActivityId/$activityId/";
$checkNew = json_decode($this->tpBokun_model->getCrulData($checkNewUrl));
if ($checkNew->return == "yes") {
continue;
}
$PAGCode = "bk_" . $activityId;
$this->tpBokun_model->PAG_Code = $PAGCode;
$this->tpBokun_model->PAG_Title = $activityData->title;
$this->tpBokun_model->PAG_PPI_SN = $activityData->id;
$this->tpBokun_model->PAG2_Name = $activityData->title;
$this->tpBokun_model->PAG2_Title = $activityData->description;
$pagsn = $this->tpBokun_model->AddProductToHT();
echo("添加:".$PAGCode."\r\n");
}
}
}
}
echo ("抓取完成 \r\n");
} else {
echo "无接口数据!";
}
}
}
/* End of file getbokun.php */