|
- <?php
-
- namespace backend\modules\hotel\models;
-
- use Yii;
- use yii\data\ActiveDataProvider;
-
- /**
- * This is the model class for table "ctrip_hotel_list".
- *
- * @property integer $ID
- * @property integer $create_user_id
- * @property string $create_time
- * @property integer $update_user_id
- * @property string $update_time
- * @property integer $cancel_flag
- * @property integer $city_id
- * @property string $city_name
- * @property string $hotel_name
- * @property string $hotel_star
- * @property integer $star_licence
- * @property string $hotel_address
- * @property string $hotel_address_en
- * @property string $hotel_phone
- * @property integer $master_hotel_id
- * @property integer $can_add_hotel
- * @property double $glat
- * @property double $glng
- * @property double $gDlat
- * @property double $gDlng
- * @property double $bDlat
- * @property double $bDlng
- */
- class CtripHotelList extends \yii\db\ActiveRecord
- {
- public $country_id;
- public $channel_name;
- public $zz_hotel_id;
- public $switch_hotel_id;
- public $channel_id;
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'ctrip_hotel_list';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['create_user_id', 'create_time', 'city_id', 'city_name', 'hotel_name', 'master_hotel_id'], 'required'],
- [['create_user_id', 'update_user_id', 'cancel_flag', 'city_id', 'star_licence', 'master_hotel_id', 'can_add_hotel'], 'integer'],
- [['create_time', 'update_time'], 'safe'],
- [['glat', 'glng', 'gDlat', 'gDlng', 'bDlat', 'bDlng'], 'number'],
- [['city_name'], 'string', 'max' => 50],
- [['hotel_name', 'hotel_address', 'hotel_address_en'], 'string', 'max' => 255],
- [['hotel_star'], 'string', 'max' => 10],
- [['hotel_phone'], 'string', 'max' => 20],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => 'ID',
- 'create_user_id' => '记录创建人',
- 'create_time' => '记录创建时间',
- 'update_user_id' => '记录更新人',
- 'update_time' => '记录更新时间',
- 'cancel_flag' => '有效标示 0:有效 1:无效',
- 'city_id' => '城市ID',
- 'city_name' => '名称',
- 'hotel_name' => '酒店名称',
- 'hotel_star' => '星级',
- 'star_licence' => '是否确认为挂牌星级 0:不挂牌星级 1:挂牌星级',
- 'hotel_address' => '酒店地址',
- 'hotel_address_en' => '英文酒店地址',
- 'hotel_phone' => '电话',
- 'master_hotel_id' => '母酒店ID',
- 'can_add_hotel' => '是否可添加子酒店 0:不能 1:能',
- 'glat' => 'google纬度',
- 'glng' => 'google经度',
- 'gDlat' => '高德纬度',
- 'gDlng' => '高德经度',
- 'bDlat' => '百度纬度对应表的lat字段',
- 'bDlng' => '百度经度对应表的lon字段',
- ];
- }
-
- public function getCtripCityList()
- {
- return $this->hasOne(CtripCityList::className(), ['city_id' => 'city_id']);
- }
-
- public function getMasterHotelList($params)
- {
- //todo:这里关联的时候需要加入渠道的筛选
- $query = self::find()
- ->joinWith('ctripCityList', false)
- ->leftJoin('channel_hotel_mapping', 'a.master_hotel_id=channel_hotel_mapping.master_hotel_id and channel_hotel_mapping.channel_id='.$params['channel_id'])
- ->leftJoin('base_supplier', 'channel_hotel_mapping.channel_id=base_supplier.ID and base_supplier.SUPPLIER_TYPE=301')
- ->from('ctrip_hotel_list a')
- ->where(['a.cancel_flag' => 0, 'ctrip_city_list.cancel_flag' => 0]);
- $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',
- 'channel_hotel_mapping.channel_id as channel_id',
- ]);
-
- if($params['country_id']) {
- $query->andFilterWhere(['ctrip_city_list.country_id' => $params['country_id']]);
- }
-
- if($params['city_id'] || $params['city_id'] == 'empty') {
- $query->andFilterWhere(['ctrip_city_list.city_id' => $params['city_id']]);
- }
-
- if($params['hotel_name']) {
- $query->andFilterWhere(['like', 'a.hotel_name', trim($params['hotel_name'])]);
- }
-
- // 根据当前渠道查询母酒店数据信息
- $sql=$query->createCommand()->getRawSql();
-
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => false,
- 'pagination' => [
- 'pagesize' => 25,
- ],
- ]);
- return $dataProvider;
- }
-
- }
|