You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

95 lines
4.2 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2017/10/18
  6. * Time: 15:57
  7. */
  8. namespace backend\modules\hotel\controllers;
  9. use backend\modules\hotel\models\ChannelHotel;
  10. use backend\modules\hotel\models\OperaHotel;
  11. use yii\filters\AccessControl;
  12. use yii\filters\ContentNegotiator;
  13. use yii\web\Response;
  14. use common\components\zController;
  15. class QunarController extends zController
  16. {
  17. public $enableCsrfValidation = false;
  18. public function behaviors()
  19. {
  20. $behaviors = parent::behaviors();
  21. unset($behaviors['authenticator']);
  22. $behaviors['corsFilter'] = [
  23. 'class' => \yii\filters\Cors::className(),
  24. 'cors' => [ // restrict access to
  25. 'Access-Control-Request-Method' => ['*'], // Allow only POST and PUT methods
  26. 'Access-Control-Request-Headers' => ['*'], // Allow only headers 'X-Wsse'
  27. 'Access-Control-Allow-Credentials' => true, // Allow OPTIONS caching
  28. 'Access-Control-Max-Age' => 3600, // Allow the X-Pagination-Current-Page header to be exposed to the browser.
  29. 'Access-Control-Expose-Headers' => ['X-Pagination-Current-Page'],
  30. ],
  31. ];
  32. //配置ContentNegotiator支持JSON和XML响应格式
  33. /*$behaviors['contentNegotiator'] = [
  34. 'class' => ContentNegotiator::className(), 'formats' => [
  35. 'application/xml' => Response::FORMAT_XML
  36. ]
  37. ];*/
  38. $behaviors['access'] = [
  39. 'class' => AccessControl::className(),
  40. 'rules' => [
  41. [
  42. 'ips' => ['119.254.26.*', //去哪儿IP访问白名单
  43. '127.0.0.1','106.14.56.77','180.168.4.58' //蜘蛛及本地IP访问白名单
  44. ], 'allow' => true,
  45. ],
  46. ],
  47. ];
  48. return $behaviors;
  49. }
  50. /**
  51. * Author:Steven
  52. * Desc:酒店静态数据接口 Qunar会定期通过此接口获取代理商可以售卖的酒店列表。酒店静态属性主要包括:酒店ID、酒店名称、城市、地址、电话
  53. */
  54. public function actiongetFullHotelInfo()
  55. {
  56. //获取所有在阿里飞猪上售卖的房型列表
  57. $res = ChannelHotel::find()
  58. ->joinWith('operaHotel b', false)
  59. ->leftJoin('base_area c', 'b.AREA_ID=c.ID and c.CANCEL_FLAG=0')
  60. ->select(['a.ChannelHotelId', 'b.*', 'c.AREA_NAME'])
  61. ->where(['a.ChannelId' => 1, 'b.CANCEL_FLAG' => 0, 'c.CANCEL_FLAG' => 0])
  62. ->from('channel_hotel_relation a')->asArray()->all();
  63. /*return \Yii::createObject([
  64. 'class' => 'yii\web\Response',
  65. 'format' => \yii\web\Response::FORMAT_XML,
  66. 'formatters' => [
  67. \yii\web\Response::FORMAT_XML => [
  68. 'class' => 'yii\web\XmlResponseFormatter',
  69. 'rootTag' => 'list', //根节点
  70. 'itemTag' => 'hotel', //单元
  71. ],
  72. ],
  73. 'data' => [ //要输出的数据
  74. ['remarks'=>'<remark value=""/>'],
  75. ],
  76. ]);*/
  77. $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
  78. $xml = "<list>";
  79. foreach ($res as $item) {
  80. $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>";
  81. }
  82. $xml .= "</list>";
  83. $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>";
  84. echo $xml;
  85. }
  86. }
  87. ?>