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.
 
 
 
 
 
 

141 lines
4.8 KiB

  1. <?php
  2. namespace backend\modules\hotel\models;
  3. use Yii;
  4. use yii\data\ActiveDataProvider;
  5. /**
  6. * This is the model class for table "ctrip_hotel_list".
  7. *
  8. * @property integer $ID
  9. * @property integer $create_user_id
  10. * @property string $create_time
  11. * @property integer $update_user_id
  12. * @property string $update_time
  13. * @property integer $cancel_flag
  14. * @property integer $city_id
  15. * @property string $city_name
  16. * @property string $hotel_name
  17. * @property string $hotel_star
  18. * @property integer $star_licence
  19. * @property string $hotel_address
  20. * @property string $hotel_address_en
  21. * @property string $hotel_phone
  22. * @property integer $master_hotel_id
  23. * @property integer $can_add_hotel
  24. * @property double $glat
  25. * @property double $glng
  26. * @property double $gDlat
  27. * @property double $gDlng
  28. * @property double $bDlat
  29. * @property double $bDlng
  30. */
  31. class CtripHotelList extends \yii\db\ActiveRecord
  32. {
  33. public $country_id;
  34. public $channel_name;
  35. public $zz_hotel_id;
  36. public $switch_hotel_id;
  37. public $channel_id;
  38. /**
  39. * @inheritdoc
  40. */
  41. public static function tableName()
  42. {
  43. return 'ctrip_hotel_list';
  44. }
  45. /**
  46. * @inheritdoc
  47. */
  48. public function rules()
  49. {
  50. return [
  51. [['create_user_id', 'create_time', 'city_id', 'city_name', 'hotel_name', 'master_hotel_id'], 'required'],
  52. [['create_user_id', 'update_user_id', 'cancel_flag', 'city_id', 'star_licence', 'master_hotel_id', 'can_add_hotel'], 'integer'],
  53. [['create_time', 'update_time'], 'safe'],
  54. [['glat', 'glng', 'gDlat', 'gDlng', 'bDlat', 'bDlng'], 'number'],
  55. [['city_name'], 'string', 'max' => 50],
  56. [['hotel_name', 'hotel_address', 'hotel_address_en'], 'string', 'max' => 255],
  57. [['hotel_star'], 'string', 'max' => 10],
  58. [['hotel_phone'], 'string', 'max' => 20],
  59. ];
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. public function attributeLabels()
  65. {
  66. return [
  67. 'ID' => 'ID',
  68. 'create_user_id' => '记录创建人',
  69. 'create_time' => '记录创建时间',
  70. 'update_user_id' => '记录更新人',
  71. 'update_time' => '记录更新时间',
  72. 'cancel_flag' => '有效标示 0:有效 1:无效',
  73. 'city_id' => '城市ID',
  74. 'city_name' => '名称',
  75. 'hotel_name' => '酒店名称',
  76. 'hotel_star' => '星级',
  77. 'star_licence' => '是否确认为挂牌星级 0:不挂牌星级 1:挂牌星级',
  78. 'hotel_address' => '酒店地址',
  79. 'hotel_address_en' => '英文酒店地址',
  80. 'hotel_phone' => '电话',
  81. 'master_hotel_id' => '母酒店ID',
  82. 'can_add_hotel' => '是否可添加子酒店 0:不能 1:能',
  83. 'glat' => 'google纬度',
  84. 'glng' => 'google经度',
  85. 'gDlat' => '高德纬度',
  86. 'gDlng' => '高德经度',
  87. 'bDlat' => '百度纬度对应表的lat字段',
  88. 'bDlng' => '百度经度对应表的lon字段',
  89. ];
  90. }
  91. public function getCtripCityList()
  92. {
  93. return $this->hasOne(CtripCityList::className(), ['city_id' => 'city_id']);
  94. }
  95. public function getMasterHotelList($params)
  96. {
  97. //todo:这里关联的时候需要加入渠道的筛选
  98. $query = self::find()
  99. ->joinWith('ctripCityList', false)
  100. ->leftJoin('channel_hotel_mapping', 'a.master_hotel_id=channel_hotel_mapping.master_hotel_id and channel_hotel_mapping.channel_id='.$params['channel_id'])
  101. ->leftJoin('base_supplier', 'channel_hotel_mapping.channel_id=base_supplier.ID and base_supplier.SUPPLIER_TYPE=301')
  102. ->from('ctrip_hotel_list a')
  103. ->where(['a.cancel_flag' => 0, 'ctrip_city_list.cancel_flag' => 0]);
  104. $query -> select(['a.*', 'base_supplier.SUPPLIER_NAME as channel_name', 'channel_hotel_mapping.sub_hotel_id as switch_hotel_id', 'channel_hotel_mapping.hotel_id as zz_hotel_id',
  105. 'channel_hotel_mapping.channel_id as channel_id',
  106. ]);
  107. if($params['country_id']) {
  108. $query->andFilterWhere(['ctrip_city_list.country_id' => $params['country_id']]);
  109. }
  110. if($params['city_id'] || $params['city_id'] == 'empty') {
  111. $query->andFilterWhere(['ctrip_city_list.city_id' => $params['city_id']]);
  112. }
  113. if($params['hotel_name']) {
  114. $query->andFilterWhere(['like', 'a.hotel_name', trim($params['hotel_name'])]);
  115. }
  116. // 根据当前渠道查询母酒店数据信息
  117. $sql=$query->createCommand()->getRawSql();
  118. $dataProvider = new ActiveDataProvider([
  119. 'query' => $query,
  120. 'sort' => false,
  121. 'pagination' => [
  122. 'pagesize' => 25,
  123. ],
  124. ]);
  125. return $dataProvider;
  126. }
  127. }