|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2017/10/18
- * Time: 15:57
- */
- namespace backend\modules\hotel\controllers;
-
- use backend\modules\hotel\models\ChannelHotel;
- use backend\modules\hotel\models\OperaHotel;
- use yii\filters\AccessControl;
- use yii\filters\ContentNegotiator;
- use yii\web\Response;
- use common\components\zController;
-
- class QunarController extends zController
- {
- public $enableCsrfValidation = false;
-
-
- public function behaviors()
- {
- $behaviors = parent::behaviors();
- unset($behaviors['authenticator']);
- $behaviors['corsFilter'] = [
- 'class' => \yii\filters\Cors::className(),
- 'cors' => [ // restrict access to
- 'Access-Control-Request-Method' => ['*'], // Allow only POST and PUT methods
- 'Access-Control-Request-Headers' => ['*'], // Allow only headers 'X-Wsse'
- 'Access-Control-Allow-Credentials' => true, // Allow OPTIONS caching
- 'Access-Control-Max-Age' => 3600, // Allow the X-Pagination-Current-Page header to be exposed to the browser.
- 'Access-Control-Expose-Headers' => ['X-Pagination-Current-Page'],
- ],
- ];
- //配置ContentNegotiator支持JSON和XML响应格式
- /*$behaviors['contentNegotiator'] = [
- 'class' => ContentNegotiator::className(), 'formats' => [
- 'application/xml' => Response::FORMAT_XML
- ]
- ];*/
- $behaviors['access'] = [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'ips' => ['119.254.26.*', //去哪儿IP访问白名单
- '127.0.0.1','106.14.56.77','180.168.4.58' //蜘蛛及本地IP访问白名单
- ], 'allow' => true,
- ],
- ],
- ];
- return $behaviors;
- }
-
- /**
- * Author:Steven
- * Desc:酒店静态数据接口 Qunar会定期通过此接口获取代理商可以售卖的酒店列表。酒店静态属性主要包括:酒店ID、酒店名称、城市、地址、电话
- */
- public function actiongetFullHotelInfo()
- {
- //获取所有在阿里飞猪上售卖的房型列表
- $res = ChannelHotel::find()
- ->joinWith('operaHotel b', false)
- ->leftJoin('base_area c', 'b.AREA_ID=c.ID and c.CANCEL_FLAG=0')
- ->select(['a.ChannelHotelId', 'b.*', 'c.AREA_NAME'])
- ->where(['a.ChannelId' => 1, 'b.CANCEL_FLAG' => 0, 'c.CANCEL_FLAG' => 0])
- ->from('channel_hotel_relation a')->asArray()->all();
- /*return \Yii::createObject([
- 'class' => 'yii\web\Response',
- 'format' => \yii\web\Response::FORMAT_XML,
- 'formatters' => [
- \yii\web\Response::FORMAT_XML => [
- 'class' => 'yii\web\XmlResponseFormatter',
- 'rootTag' => 'list', //根节点
- 'itemTag' => 'hotel', //单元
- ],
- ],
- 'data' => [ //要输出的数据
- ['remarks'=>'<remark value=""/>'],
- ],
- ]);*/
- $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
- $xml = "<list>";
- foreach ($res as $item) {
- $xml .= "<hotel id=\"" . $item['HOTEL_ID'] . "\" city=\"" . $item['AREA_NAME'] . "\" name=\"" . $item['HOTEL_NAME'] . "\" address=\"" . $item['HOTEL_ADDRESS'] . "\" tel=\"021-33280550\"><remarks><remark value=\"该酒店入住时间为" . $item['EARLIEST_CHECKIN_TIME'] . "之后\"></remark></remarks></hotel>";
- }
- $xml .= "</list>";
- $xml="<? xml version = \"1.0\" encoding = \"UTF-8\"?>\n<list><hotel id=\"1\" city=\"beijing_city\" name=\"北京大饭店\" address=\"苏州街\" tel=\"010-66666666\"><remarks><remark value=\"本酒店不接受外宾\"/><remark value=\"将视酒店入住情况尽量安排,无法确保。\"/><remark value=\"所有酒店入住时间为下午14:00后。\"/></remarks></hotel><hotel id=\"2\" city=\"beijing_city\" name=\"北京大饭店2\" address=\"苏州街2\" tel=\"010-88888888\"><remarks><remark value=\"所有酒店入住时间为下午14:00后。\"/></remarks></hotel></list>";
- echo $xml;
- }
-
- }
-
- ?>
|