|
- <?php
-
- namespace backend\modules\hotel\models;
-
- use backend\modules\api\models\BaseArea;
- use backend\modules\api\models\BaseResource;
- use common\models\BaseUserAuth;
- use common\models\BaseSupplierSale;
- use Yii;
- use common\models\BaseSupplierPurchase;
- use yii\data\ActiveDataProvider;
- use yii\db\Expression;
- use common\models\BaseAreaView;
- use backend\modules\api\models\DictType;
- use yii\base;
- use yii\db\ActiveRecord;
-
-
- /**
- * This is the model class for table "opera_hotel".
- *
- * @property integer $HOTEL_ID
- * @property integer $CREATE_USER_ID
- * @property string $CREATE_TIME
- * @property integer $UPDATE_USER_ID
- * @property string $UPDATE_TIME
- * @property integer $CANCEL_FLAG
- * @property string $HOTEL_NAME
- * @property integer $STAR_LEVEL
- * @property integer $AREA_ID
- * @property string $HOTEL_ADDRESS
- * @property integer $SUPPLIER_ID
- * @property integer $HOTEL_STATUS
- * @property string $ROOM_TYPE_ALL
- * @property string $ROOM_TYPE_SALE
- * @property string $EARLIEST_CHECKIN_TIME
- * @property integer $CONFIRM_FROM
- * @property string $PURCHASE_NAME
- * @property string $PRINCIPAL
- * @property string $BUSINESS_AREA
- * @property string $DRIECT_CONNNECT_CHANNEL
- * @property string $RESERVATION_NOTES
- * @property string $INTRODUCTION
- * @property string $PERIPHERAL_TRAFFIC
- * @property integer $IS_PROMOTION
- * @property string $HOTEL_LABEL
- * @property string $SALE_LABEL
- * @property string $RECOMMEND_LEVEL
- * @property string $HOTEL_IMAGE
- */
- class OperaHotel extends \yii\db\ActiveRecord
- {
- public $province = 791;
- public $city;
- public $country;
- public $star_name;
- public $base_room = array();
- public $hotel_gift = array();
- // 星级
- const START_LEVEL = 30;
- // 酒店品牌
- const HOTEL_BRAND = 712;
- // 酒店类型:舒适、豪华等
- const HOTEL_TYPE = 711;
- // 酒店标签:WiFi、泳池等
- const HOTEL_LABEL = 709;
- // 售卖标签:促销、热卖等
- const SALE_LABEL = 710;
-
- // 在职运营负责人
- const EXIST_PRINCIPAL = array('35' => '杨晓婷', '276' => '潘历俊', "768" => "徐志浩", "879" => "罗萍");
- // 所有运营负责人
- const ALL_PRINCIPAL = array('35' => '杨晓婷', '274' => '王晓云', '276' => '潘历俊', '283' => '陈娟', '284' => '徐安', '300' => '李少斌', '301' => '路逢源', '669' => '党晴晴',
- '697' => '罗萍', '554' => '马志涛', '586' => '王楠', '728' => '尚璇璇', '746' => '王龙', '751' => '朱佳伟', '752' => '王思邈', '753' => '于洋', '768' => '徐志浩', '769' => '肖强',
- '771' => '陈雨婷', '773' => '孙浩', '777' => '程珊珊', '797' => '李华', "879" => "罗萍",);
-
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_hotel';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'STAR_LEVEL', 'AREA_ID', 'SUPPLIER_ID', 'HOTEL_STATUS', 'CONFIRM_FROM', 'PURCHASE_NAME', 'PRINCIPAL', 'IS_PROMOTION', 'RECOMMEND_LEVEL', 'IS_SELL'], 'integer'],
- [['UPDATE_TIME'], 'safe'],
- [['HOTEL_NAME', 'HOTEL_ADDRESS'], 'required'],
- [['CREATE_TIME'], 'string', 'max' => 20],
- [['LONGITUDE', 'LATITUDE'], 'number'],
- [['LONGITUDE', 'LATITUDE'], 'number'],
- [['RESERVATION_NOTES', 'INTRODUCTION', 'PERIPHERAL_TRAFFIC', 'BUSINESS_AREA', 'HOTEL_LABEL', 'SALE_LABEL', 'BRAND', 'HOTEL_TYPE'], 'string'],
- [['HOTEL_NAME', 'HOTEL_ADDRESS', 'ROOM_TYPE_ALL', 'ROOM_TYPE_SALE', 'HOTEL_IMAGE'], 'string', 'max' => 1000],
- [['EARLIEST_CHECKIN_TIME'], 'string', 'max' => 8],
- [['DRIECT_CONNNECT_CHANNEL'], 'string', 'max' => 1000],
- [['HOTEL_NAME'], 'unique', 'targetAttribute' => ['HOTEL_NAME', 'CANCEL_FLAG'], 'message' => '该酒店已经存在!'],
- [['HOTEL_STATUS'], 'required', 'on' => 'putawayHotel', 'message' => '酒店状态不能为空'],
- [['EARLIEST_CHECKIN_TIME'], 'required', 'on' => 'putawayHotel', 'message' => '最早入住时间不能为空'],
- [['ROOM_TYPE_SALE'], 'required', 'on' => 'putawayHotel', 'message' => '基础房型不能为空'],
- [['SUPPLIER_ID'], 'required', 'on' => 'putawayHotel', 'message' => '供应商不能为空'],
- [['PURCHASE_NAME'], 'required', 'on' => 'putawayHotel', 'message' => '采购人不能为空'],
- [['PRINCIPAL'], 'required', 'on' => 'putawayHotel', 'message' => '运营负责人不能为空'],
- [['CONFIRM_FROM'], 'required', 'on' => 'putawayHotel', 'message' => '发单主体不能为空'],
- [['LONGITUDE'], 'required', 'on' => 'addHotel', 'message' => '经度不能为空'],
- [['LATITUDE'], 'required', 'on' => 'addHotel', 'message' => '纬度不能为空'],
- [['DRIECT_CONNNECT_CHANNEL'], 'string', 'max' => 500],
- [['LONGITUDE'], 'match', 'pattern' => '/^[-\+]?((1[0-7]\d{1}|0?\d{1,2})\.\d{1,6}|180\.0{1,6})$/', 'message' => '请输入正确的经度范围(-180,180)1~6位小数 如121.33414', 'skipOnEmpty' => true],
- [['LATITUDE'], 'match', 'pattern' => '/^[-\+]?([0-8]?\d{1}\.\d{1,6}|90\.0{1,6})$/', 'message' => '请输入正确的纬度范围(-90,90)1~6位小数 如31.192376', 'skipOnEmpty' => true],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'HOTEL_ID' => '酒店ID',
- 'CREATE_USER_ID' => '记录创建用户ID',
- 'CREATE_TIME' => '记录创建时间',
- 'UPDATE_USER_ID' => '记录最后更新用户ID',
- 'UPDATE_TIME' => '记录最后更新时间',
- 'CANCEL_FLAG' => '记录有效性标记,0:记录有效;1:记录已删除',
- 'HOTEL_NAME' => '酒店名称',
- 'STAR_LEVEL' => '星级',
- 'AREA_ID' => '酒店所属区域,对应base_area.id',
- 'HOTEL_ADDRESS' => '酒店地址',
- 'SUPPLIER_ID' => '供应商',
- 'HOTEL_STATUS' => '酒店状态',
- 'ROOM_TYPE_ALL' => '基础房型',
- 'ROOM_TYPE_SALE' => '可售基础房型',
- 'EARLIEST_CHECKIN_TIME' => '最早入住时间',
- 'CONFIRM_FROM' => '发单主体',
- 'PURCHASE_NAME' => '采购人',
- 'PRINCIPAL' => '运营负责人',
- 'DRIECT_CONNNECT_CHANNEL' => '直连渠道',
- 'BUSINESS_AREA' => '商圈信息',
- 'RESERVATION_NOTES' => '酒店预订须知',
- 'INTRODUCTION' => '酒店介绍',
- 'PERIPHERAL_TRAFFIC' => '周边交通',
- 'IS_PROMOTION' => '是否促销',
- 'HOTEL_LABEL' => '酒店标签',
- 'SALE_LABEL' => '售卖标签',
- 'RECOMMEND_LEVEL' => '推荐等级',
- 'HOTEL_IMAGE' => '酒店图片',
- 'LONGITUDE' => '经度',
- 'LATITUDE' => '纬度',
- 'BRAND' => '酒店品牌',
- 'HOTEL_TYPE' => '酒店类型',
- 'base_room' => '基础房型信息',
- 'hotel_gift' => '礼盒信息',
- 'IS_SELL' => '是否上架',
- ];
- }
-
- /**
- * @return \yii\db\ActiveQuery 酒店
- */
- public function getBaseUser()
- {
- return $this->hasOne(User::className(), ['ID' => 'PRINCIPAL']);
- }
-
- public function getPurcharse()
- {
- return $this->hasOne(User::className(), ['ID' => 'PURCHASE_NAME']);
- }
-
- public function getConfirmOrganization()
- {
- return $this->hasOne(BaseConfirmOrganization::className(), ['ID' => 'CONFIRM_FROM']);
- }
-
- /**
- * User:Steven
- * Desc:酒店价格报警关联表 on条件
- * @return \yii\db\ActiveQuery
- */
- public function getHotelRelation()
- {
- return $this->hasOne(HotelRelation::className(), ['HotelId' => 'HOTEL_ID'])->andOnCondition(['ChannelId' => new Expression(Yii::$app->params['ctrip']['relation_supplier_id'])]);
- }
-
- /**
- * 酒店关联地区
- */
- public function getBaseAreaView()
- {
- return $this->hasOne(BaseAreaView::className(), ['AREA_ID' => 'AREA_ID']);
- }
-
- public function getBaseArea()
- {
- return $this->hasOne(BaseArea::className(), ['ID' => 'AREA_ID']);
- }
-
- /**
- * 酒店关联星级
- */
- public function getDictType()
- {
- return $this->hasOne(DictType::className(), ['ID' => 'STAR_LEVEL']);
- }
-
- /**
- * @Author wanglg
- * @Desc 获取酒店资源信息:品牌、售卖标签、酒店标签;
- * @return array|ActiveRecord[]
- */
- public static function getConfigList($parent_id)
- {
- $star_list = BaseResource::find()->select(['a.ID', 'a.RES_NAME as TYPE_NAME'])
- // ->leftJoin('dict_type b', 'a.RES_TYPE_ID=b.ID')
- ->from('base_resource a')->where(['a.IF_DISABLED' => 0, 'a.RES_TYPE_ID' => $parent_id])
- ->asArray()->all();
-
- return $star_list;
- }
-
- /**
- * 根据酒店id获取酒店信息
- * @param $id
- * @return static
- */
- public function findHotel($id)
- {
- if (($model = OperaHotel::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
-
- /**
- * User:Steven
- * Desc:
- * @return \yii\db\ActiveQuery
- */
- public function getBaseSupplier()
- {
- return $this->hasOne(BaseSupplier::className(), ['ID' => 'SUPPLIER_ID']);
- }
-
- /**
- * User:Steven
- * Desc:
- * @return \yii\db\ActiveQuery
- */
- public function getBaseSupplierPurchase()
- {
- return $this->hasOne(BaseSupplierPurchase::className(), ['ID' => 'PURCHASE_NAME']);
- }
-
- /**
- * 运营负责人列表
- * @return array|ActiveRecord[]
- */
-
- public static function getPrincipal()
- {
- $query = OperaHotel::find()->select(['PRINCIPAL', 'TRUE_NAME'])->joinWith('baseUser b', false);
- $query->where(['!=', 'PRINCIPAL', '']);
- if(BaseUserAuth::HOTEL_PURCHASE == Yii::$app->user->identity['USER_ROLE']){
- $query->andFilterWhere(['PURCHASE_NAME' => Yii::$app->user->id]);
- }
- $query->groupBy(['PRINCIPAL']);
- $res = $query->asArray()->all();
-
- return $res;
- }
-
- /**
- * 采购负责人列表
- * @return array
- */
- public static function getPurchase()
- {
- $query = OperaHotel::find()->select(['PURCHASE_NAME', 'TRUE_NAME'])->joinWith('purcharse')->where(['!=', 'TRUE_NAME', '']);
- if(BaseUserAuth::HOTEL_PURCHASE == Yii::$app->user->identity['USER_ROLE']){
- $query->andFilterWhere(['PURCHASE_NAME' => Yii::$app->user->id]);
- }
- $res = $query->groupBy(['base_user.ID'])->asArray()->all();
-
- return $res;
- }
-
- /**
- * User:Steven
- * Desc:获取酒店列表
- * @return ActiveDataProvider
- */
- public function getHotel()
- {
- $res = $this->getPrincipal();
- $query = OperaHotel::find()
- ->joinWith('baseSupplier')
- ->joinWith('baseUser a')
- ->joinWith('purcharse b')
- ->from('opera_hotel')
- ->where(['opera_hotel.CANCEL_FLAG' => 0, 'IS_SELL' => 1]);
- //-> createCommand() -> getSql();
- $query->andFilterWhere(['or', ['!=', 'opera_hotel.PRINCIPAL', ''], ['!=', 'opera_hotel.PURCHASE_NAME', ''], ['!=', 'opera_hotel.SUPPLIER_ID', '0']]);
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'pagination' => [
- 'pageSize' => 25,
- ],
- ]);
-
- #region 功能描述数据权限
- //酒店采购负责人只能看到自己采购的酒店订单,其他(酒店运营人员、酒店管理人员、酒店客服人员、酒店客服管理人员)数据均可见
- $user_role = Yii::$app->user->identity->USER_ROLE; //获取当前用户的角色
- if ($user_role == BaseUserAuth::HOTEL_PURCHASE) { //酒店采购负责人
- $query->andFilterWhere([
- 'PURCHASE_NAME' => Yii::$app->user->id,
- ]);
- }
- #endregion
-
-
- if ($this->HOTEL_NAME != null) {
- $query->andFilterWhere(['like', 'HOTEL_NAME', $this->HOTEL_NAME]);
- }
- if ($this->HOTEL_STATUS !== null) {
- $query->andFilterWhere(['HOTEL_STATUS' => $this->HOTEL_STATUS]);
- }
- if ($this->PRINCIPAL !== null && $this->PRINCIPAL != -1) {
- $query->andFilterWhere(['PRINCIPAL' => $this->PRINCIPAL]);
- }
-
- return $dataProvider;
- }
-
- public function getHotelist($params)
- {
- $query = OperaHotel::find()
- ->select(['a.HOTEL_ID', 'a.hotel_name as HOTEL_NAME', 'c.type_name as star_name', 'a.hotel_address as HOTEL_ADDRESS', 'concat(b.parent_area_name, b.area_name) as city', 'a.hotel_status as HOTEL_STATUS'])
- ->joinWith('dictType as c')
- ->joinWith('baseAreaView as b')
- ->from('opera_hotel as a')
- ->where(['a.cancel_flag' => 0])->orderBy(['a.CREATE_TIME' => SORT_DESC]);
- // -> createCommand() ->getSql();
-
- $this->load($params);
-
- #region 功能描述数据权限
- //酒店运营人员只能看到自己运营的酒店订单,酒店采购负责人只能看到自己采购的酒店订单,其他(酒店管理人员、酒店客服人员、酒店客服管理人员)数据均可见
- $user_role = Yii::$app->user->identity->USER_ROLE; //获取当前用户的角色
- if ($user_role == BaseUserAuth::HOTEL_OPERATOR) { //酒店运营人员
- $query->andFilterWhere([
- 'a.PRINCIPAL' => Yii::$app->user->id,
- ]);
- } else if ($user_role == BaseUserAuth::HOTEL_PURCHASE) { //酒店采购负责人
- $query->andFilterWhere([
- 'a.PURCHASE_NAME' => Yii::$app->user->id,
- ]);
- } else if ($user_role == BaseUserAuth::HOTEL_CUSTOMER || $user_role == BaseUserAuth::HOTEL_CUS_ADMIN) { //酒店客服人员
- $dataProvider = new ActiveDataProvider([
- 'query' => $query->andFilterWhere([
- 'a.HOTEL_ID' => -1, //表示当前角色没有任何酒店的权限
- ]),
- 'sort' => false,
- 'pagination' => [
- 'pagesize' => 25,
- ],
- ]);
- return $dataProvider;
- }
- #endregion
-
- if ($this->HOTEL_NAME != null) {
- $query->andFilterWhere(['like', 'HOTEL_NAME', $this->HOTEL_NAME]);
- }
-
- if ($this->HOTEL_STATUS != null) {
- $query->andFilterWhere(['HOTEL_STATUS' => $this->HOTEL_STATUS]);
- }
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => false,
- 'pagination' => [
- 'pagesize' => 25,
- ],
- ]);
-
- return $dataProvider;
- }
-
- /**
- * 获取默认酒店(选中第一个)
- */
- public function getFirstHotel()
- {
- $res = OperaHotel::find()
- ->select(['HOTEL_ID'])
- ->where(['CANCEL_FLAG' => 0, 'IS_SELL' => 0])
- ->limit(1)
- ->asArray()->all();
-
- return $res;
- }
-
- /**
- * 获取一个酒店的信息
- */
- public function getOneHotelInfo($hotel_id)
- {
- $info = OperaHotel::find()
- ->select(['a.HOTEL_ID', 'a.HOTEL_NAME', 'a.ROOM_TYPE_SALE', 'a.EARLIEST_CHECKIN_TIME', 'a.HOTEL_STATUS', 'a.SUPPLIER_ID', 'a.PURCHASE_NAME', 'a.CONFIRM_FROM', 'a.PRINCIPAL', 'a.DRIECT_CONNNECT_CHANNEL'])
- ->joinWith('baseSupplier')
- ->joinWith('baseUser')
- ->joinWith('baseSupplierPurchase')
- ->joinWith('baseSupplierPurchase.userName')->from('opera_hotel as a')
- ->where(['a.HOTEL_ID' => $hotel_id, 'a.CANCEL_FLAG' => 0])->one();
-
- return $info;
- }
-
- /**
- * 获取上下架酒店列表
- * @param $params
- * @return ActiveDataProvider
- *
- */
- public function upDownHoteList()
- {
- $query = OperaHotel::find()
- ->joinWith('baseSupplier')
- ->joinWith('purcharse')
- ->from('opera_hotel')
- ->where(['opera_hotel.cancel_flag' => 0])->orderBy(['opera_hotel.CREATE_TIME' => SORT_DESC]);
- // -> createCommand() ->getRawSql();
-
- #region 功能描述数据权限
- //酒店运营人员只能看到自己运营的酒店,酒店采购负责人只能看到自己采购的酒店,其他(酒店管理人员、酒店客服人员、酒店客服管理人员)数据均可见
- $user_role = Yii::$app->user->identity->USER_ROLE; //获取当前用户的角色
- /*if ($user_role == BaseUserAuth::HOTEL_OPERATOR) { //酒店运营人员
- $query->andFilterWhere([
- 'PRINCIPAL' => Yii::$app->user->id,
- ]);
- } else */
- if ($user_role == BaseUserAuth::HOTEL_PURCHASE) { //酒店采购负责人
- $query->andFilterWhere([
- 'PURCHASE_NAME' => Yii::$app->user->id,
- ]);
- }
- #endregion
-
- if ($this->HOTEL_NAME != null) {
- $query->andFilterWhere(['like', 'HOTEL_NAME', $this->HOTEL_NAME]);
- }
-
- if ($this->HOTEL_STATUS != null && $this->HOTEL_STATUS != -1) {
- $query->andFilterWhere(['HOTEL_STATUS' => $this->HOTEL_STATUS]);
- }
-
- if ($this->PRINCIPAL !== null && $this->PRINCIPAL != -1) {
- $query->andFilterWhere(['PRINCIPAL' => $this->PRINCIPAL]);
- }
-
- if ($this->PURCHASE_NAME !== null && $this->PURCHASE_NAME != -1) {
- $query->andFilterWhere(['PURCHASE_NAME' => $this->PURCHASE_NAME]);
- }
-
- $sql = $query->createCommand()->getRawSql();
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => false,
- 'pagination' => [
- 'pagesize' => 25,
- ],
- ]);
-
- return $dataProvider;
- }
-
- public function getPushHotelInfo($hotel_id)
- {
- $res = OperaHotel::find()
- ->select(['a.HOTEL_ID', 'a.HOTEL_NAME', 'a.AREA_ID', 'a.HOTEL_ADDRESS', 'a.HOTEL_STATUS', 'a.STAR_LEVEL', 'a.DRIECT_CONNNECT_CHANNEL', 'IFNULL(c.SL_POSTCODE, c.POSTCODE) POSTCODE'])
- ->joinWith('baseAreaView as b', false)
- ->leftJoin('base_area as c', 'b.PARENT_AREA_ID=c.ID and c.CANCEL_FLAG=0')
- ->from('opera_hotel as a')
- ->where(['a.HOTEL_ID' => $hotel_id, 'a.CANCEL_FLAG' => 0])->asArray()->one();
-
- return $res;
- }
-
-
- /**
- * 添加酒店之前
- */
- public function beforeSave($insert)
- {
- //联系地址的省市
- if ($this->isNewRecord) {
- // $this->AREA_ID = $this->country ? $this->country : $this->city;
- $this->CREATE_TIME = date('Y-m-d H:i:s', time());
- $this->CREATE_USER_ID = Yii::$app->user->id;
- $this->PURCHASE_NAME = 0;
- } else {
- $this->UPDATE_USER_ID = Yii::$app->user->id;
- $this->UPDATE_TIME = date('Y-m-d H:i:s', time());
- }
-
- return parent::beforeSave($insert);
- }
-
- /**
- * Des:获取酒店信息
- * Name: getInfo
- * @param $hotel_id
- * @return array
- * @author 倪宗锋
- */
- public function getInfo($hotel_id)
- {
- $select = [
- //酒店图片
- 'hotel_name' => new Expression("ifnull(HOTEL_NAME,'')"),//酒店名称
- 'star_level' => new Expression("ifnull((select if(star_level=31,'',TYPE_NAME) from dict_type where id=star_level),'')"),//星级
- 'hotel_address' => new Expression("ifnull(HOTEL_ADDRESS,'')"),//酒店地址
- //酒店图片数量
- 'hotel_label' => new Expression("ifnull((select GROUP_CONCAT(res_name) from base_resource where instr((select SALE_LABEL from opera_hotel where hotel_id=a.hotel_id),RES_ID) and res_type_id=709 GROUP BY res_type_id),'')"),//酒店标签 酒店设施
- 'sale_label' => new Expression("ifnull((select GROUP_CONCAT(res_name) from base_resource where instr((select SALE_LABEL from opera_hotel where hotel_id=a.hotel_id),RES_ID) and res_type_id=710 GROUP BY res_type_id),'')"),//售卖标签
- 'reservation_notes' => new Expression("ifnull(RESERVATION_NOTES,'')"),//酒店预订须知
- 'introduction' => new Expression("ifnull(INTRODUCTION,'')"),//酒店介绍
- 'peripheral_traffic' => new Expression("ifnull(PERIPHERAL_TRAFFIC,'')"),//周边交通
- 'business_area' => new Expression("ifnull(BUSINESS_AREA,'')"),//商圈信息
- 'LONGITUDE' => new Expression("ifnull(LONGITUDE,'')"),//经度
- 'LATITUDE' => new Expression("ifnull(LATITUDE,'')"),//纬度
- 'hotel_img' => new Expression("ifnull(HOTEL_IMAGE,'')"),//酒店图片
- //酒店图片
- 'imgs' => new Expression("(SELECT group_CONCAT(IMG_URL SEPARATOR '||') from base_img WHERE IMG_TYPE = 25 and PRODUCT_ID = HOTEL_ID and cancel_flag=0)"),
- 'in_time' => 'EARLIEST_CHECKIN_TIME',//入住时间
- ];
- $where = ['=', 'HOTEL_ID', $hotel_id];
- $getInfo = self::find()->select($select)
- ->from(self::tableName().' a')
- ->where($where)
- ->asArray()
- ->one();
-
- return $getInfo;
- }
-
- /**
- * Function Description:查找酒店的area_name和area_id
- * Function Name: getHotelArea
- * @return array
- * @author 田玲菲
- */
- public function getHotelArea()
- {
- $conn = Yii::$app->db;
- $sql = "SELECT DISTINCT c.area_name, c.id FROM opera_hotel AS a LEFT JOIN base_area AS b ON a.AREA_ID = b.ID JOIN base_area AS c ON b.PARENT_ID = c.ID AND c.CANCEL_FLAG = 0 AND ( c.PARENT_ID <> 0 OR c.SL_POSTCODE IS NOT NULL ) AND( c.PARENT_ID NOT IN (SELECT d.id FROM base_area AS d WHERE d.SL_POSTCODE IS NOT NULL) ) ORDER BY CONVERT (c.AREA_NAME USING gbk) ASC";
- $result = $conn->createCommand($sql)->queryAll();
-
- return $result;
- }
-
- /**
- * @Author wanglg
- * @Desc酒店基础房型验证规则
- * @param $attribute
- */
- public function VBaseRoom($attribute)
- {
- if (count($this->$attribute) <= 0) {
- $this->addError($attribute, '基础房型信息不能为空');
- } else {
- //验证每个基础房型信息
- foreach ($this->$attribute as $key => $room) {
- if (empty($room['BASE_ROOM_NAME']) || empty($room['BED_TYPE']) || empty($room['AREA_SIZE'])) {
- $this->addError($attribute, '基础房型有必填写信息');
- }
- }
-
- }
- }
-
- /**
- * Des:获取官网酒店列表
- * Name: getWwwHotelList
- * @param $DistribID
- * @return array
- * @author 倪宗锋
- */
- public function getWwwHotelList($DistribID)
- {
- $baseSupplierSale = new BaseSupplierSale();
- $price = $baseSupplierSale->getSaleType($DistribID);
- $select = [
- 'a.hotel_id',
- 'a.hotel_name',
- 'show_img' => new Expression("CONCAT(a.HOTEL_IMAGE,'.370x326',RIGHT(a.HOTEL_IMAGE,LOCATE('.', REVERSE(a.HOTEL_IMAGE))))"),
- 'min_price' => new Expression("IFNULL((
- SELECT MIN(b.{$price}) from run_hotel_distrib b
- INNER JOIN run_hotel_sub_room f on b.HOTEL_ID=f.HOTEL_ID and b.BASE_ROOM_TYPE=f.BASE_ROOM_TYPE and b.ROOM_TYPE=f.ROOM_TYPE and b.RUN_DATE=f.RUN_DATE and f.IS_ONSALE = 1
- INNER JOIN run_hotel g on b.HOTEL_ID=g.HOTEL_ID and b.BASE_ROOM_TYPE=g.BASE_ROOM_TYPE and b.RUN_DATE=g.RUN_DATE and g.IS_ONSALE = 1
- WHERE b.HOTEL_ID = a.HOTEL_ID and b.{$price} not in(-1,0,1) and b.RUN_DATE >= NOW() and b.RUN_DATE < DATE_ADD(NOW(),INTERVAL 1 MONTH)
- and f.RUN_DATE >= NOW() and f.RUN_DATE < DATE_ADD(NOW(),INTERVAL 1 MONTH)
- and g.RUN_DATE >= NOW() and g.RUN_DATE < DATE_ADD(NOW(),INTERVAL 1 MONTH)
- and b.RUN_STATUS=326 and b.DISTRIB_ID = {$DistribID}
- ),0)"),
- ];
- $where = [
- 'and',
- ['=', 'a.CANCEL_FLAG', 0],
- ['>', 'a.RECOMMEND_LEVEL', 0],
- ['=', 'a.HOTEL_STATUS', 1],
- ['is not', 'a.HOTEL_IMAGE', null],
- ];
- $getList = self::find()->select($select)
- ->from(static::tableName() . ' a')
- ->where($where)
- ->having(['!=', 'min_price', 0])
- ->orderBy('a.RECOMMEND_LEVEL desc')
- ->asArray()
- ->all();
- if (empty($getList[0]['hotel_id'])) {
- return [];
- }
-
- return $getList;
- }
-
- }
-
- ?>
|