|
- <?php
-
- namespace common\models;
-
-
- use yii\mongodb\ActiveRecord;
-
- class MHotel extends ActiveRecord {
- public static function collectionName()
- {
- return ['zzcx','hotel'];
- }
-
- public function attributes()
- {
- return [
- '_id',
- 'hotel_id',
- 'hotel_name',
- 'star_level',
- 'area_id',
- 'area_name',
- 'run_date',
- 'is_promotion',
- 'recommend_level',
- 'sale_label',
- 'hotel_label',
- 'hotel_image',
- 'business_area',
- 'brand',
- 'hotel_type',
- 'room_info',
- 'update_time',
- ];
- }
- public function rules()
- {
- return parent::rules(); // TODO: Change the autogenerated stub
- }
-
- /**
- * Function Description:获取酒店列表
- * Function Name: getHotelList
- * @param $params
- * @param $hotel_select_list
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getHotelList($params,$hotel_select_list)
- {
- //获取数据有效性标志
- $mBaseUnique=new MBaseUnique();
- $time_stamp=$mBaseUnique::find()->select(['time_stamp'])->from('base_unique')->where(['type'=>1])->asArray()->one();
- $where=['and',
- ['=','time_stamp',$time_stamp['time_stamp']],
- ['=','area_id',$params['area_id']],
- ['>=','run_date',$params['start_date']],
- ['<','run_date',$params['end_date']],
- ];
- if($params['search_more']!=''){//名称,商圈,品牌
- $where[]=[
- 'or',
- ['like','hotel_name',$params['search_more']],
- ['like','business_area',$params['search_more']],
- ['like','brand',$params['search_more']],
- ];
- }
- if($params['hotel_label']!=''){//设施服务
- #处理拼接的标签,取出单标签like匹配字段
- $labels=explode(',',$params['hotel_label']);
- $label_where=['and'];
- foreach($labels as $val){
- $tmp_hotel_label=$hotel_select_list[3]['list'][$val]['name'];
- $label_where[]=['like','hotel_label',$tmp_hotel_label];
- }
- $where[]=$label_where;
- }
- if($params['brand']!='0'){//品牌
- $brand=explode(',',$params['brand']);
- $brand_where=['or'];
- foreach($brand as $val){
- $tmp_hotel_brand=$hotel_select_list[2]['list'][$val]['name'];
- $brand_where[]=['like','brand',$tmp_hotel_brand];
- }
- $where[]=$brand_where;
- }
- if($params['star_type']!='0')
- {#星级及类型
- if($params['star_type']=='1' || $params['star_type']=='2')
- {//星级
- if($params['star_type']=='1'){
- $where[]=['=','star_level','39'];
- }else{
- $where[]=['=','star_level','38'];
- }
- }else{//酒店类型
- $where[]=['=','hotel_type',$hotel_select_list['1']['list'][$params['star_type']]['name']];
- }
- }
- $result=self::find()
- ->from('hotel')
- ->where($where)
- ->asArray()
- ->all();
- return $result;
- }
- }
|