'人民币'); /** * @inheritdoc */ public static function tableName() { return '{{%opera_hotel_base_room}}'; } /** * @inheritdoc */ public function rules() { return [ [['CREATE_USER_ID', 'CANCEL_FLAG', 'HOTEL_ID', 'BASE_ROOM_TYPE', 'CURRENCY_CODE'], 'integer'], [['CREATE_TIME', 'UPDATE_TIME', 'BASE_ROOM_NAME', 'BED_TYPE', 'AREA_SIZE'], 'string', 'max' => 50], [['BASE_ROOM_NAME'], 'required'], [['BED_TYPE'], 'required', 'on' => 'set_bed_type', 'message' => '床型不能为空'], [['CURRENCY_CODE'], 'required', 'on' => 'set_bed_type', 'message' => '币种不能为空'], ]; } /** * @inheritdoc */ public function attributeLabels() { return [ 'MAIN_ID' => '基础房型ID', 'CREATE_TIME' => 'Create Time', 'CREATE_USER_ID' => 'Create User ID', 'UPDATE_TIME' => 'Update Time', 'CANCEL_FLAG' => 'Cancel Flag', 'HOTEL_ID' => '酒店ID', 'BASE_ROOM_TYPE' => '基础房型ID(历史数据)', 'BASE_ROOM_NAME' => '基础房型名称', 'BED_TYPE' => '床型', 'CURRENCY_CODE' => '币种', 'AREA_SIZE' => '房型面积', 'ROOM_IMG' => '基础房型图片', ]; } //新增基本房型 public function AddBaseroom($name, $user_id, $hotel_id) { $hotel_id = isset($hotel_id) ? $hotel_id : 0; $sql = "insert into opera_hotel_base_room (hotel_id,base_room_type,base_room_name,create_user_id,create_time,update_time) VALUES ('$hotel_id',0,'$name','$user_id',now(),now())"; writeLog(__FUNCTION__ . " sql= " . $sql); $res = $this->DBTool->execSql($sql); return $res; } /** * 根据酒店查询出基础房型和可售房型,然后处理判断 * */ public function getBaseRoomAll($hotel_id) { $res = OperaHotel::findOne(['HOTEL_ID' => $hotel_id]); $hotel_type_all = explode(',', $res['ROOM_TYPE_ALL']); // $hotel_type_sale = explode(',', $res['ROOM_TYPE_SALE']); $rs = OperaHotelBaseRoom::find() ->select(['MAIN_ID', 'BED_TYPE', 'CURRENCY_CODE', 'BASE_ROOM_NAME', 'case when MAIN_ID in (' . $res['ROOM_TYPE_SALE'] . ') then 1 else 0 end as checked']) ->where(['CANCEL_FLAG' => 0, 'MAIN_ID' => $hotel_type_all]) // -> asArray() ->all(); return $rs; } public function getBedType($base_room) { $rs = OperaHotelBaseRoom::find() ->select(['MAIN_ID', 'BED_TYPE', 'CURRENCY_CODE', 'BASE_ROOM_NAME', 'case when BED_TYPE in (1,2,10) then 1 else 0 end as checked']) ->where(['CANCEL_FLAG' => 0, 'MAIN_ID' => $base_room]) // -> asArray() ->all(); return $rs; } //根据基本房型名称查询res_id public function getUpId($name, $hotel_id) { $sql = "select main_id as res_id from opera_hotel_base_room where base_room_name ='$name' and cancel_flag = 0 and hotel_id = '$hotel_id'"; writeLog(__FUNCTION__ . " sql= " . $sql); $res = $this->DBTool->queryBySql($sql); return $res; } // 根据hotelid查询该酒店所有的基础房型 public function getHotelBaseRoom($hotel) { $res = OperaHotelBaseRoom::find() ->where(['HOTEL_ID' => $hotel, 'CANCEL_FLAG' => 0])->all(); // -> asArray() -> all(); return $res; } // 根据hotelid查询该酒店所有的基础房型 public function getHotelBaseRoomForSelect($hotel, $channel_id) { $where = [ 'and', ['=', 'a.HOTEL_ID', $hotel], ['=', 'a.CANCEL_FLAG', 0], ['is', 'b.base_room_id', null] ]; $res = self::find() ->from(self::tableName() . ' a') ->leftJoin(ChannelBaseRoomMapping::tableName() . ' b', 'a.MAIN_ID = b.base_room_id and b.channel_id = ' . $channel_id) ->where($where) ->all(); return $res; } /** * @Author wanglg * @Desc 生成不重复的文件名称 * @param $path 文件路径 * @param $suffix 文件后缀 * @return string */ public static function getImgName($path, $suffix) { $flag = true; $str = 'abcdefghijkmnpqrstwxyzABCDEFGHIJKMNPQRSTWXYZ23456789'; while ($flag) { $name = str_shuffle(substr(str_shuffle($str), 0, 10) . time() . rand(10000, 999999)); if (!file_exists("$path$name$suffix")) { $flag = false; } } return $name . $suffix; } public function beforeSave($insert) { if ($this->isNewRecord) { $this->CREATE_TIME = date('Y-m-d H:i:s'); $this->CREATE_USER_ID = Yii::$app->user->id; } else { $this->UPDATE_TIME = date('Y-m-d H:i:s'); } return parent::beforeSave($insert); } /** * Des:获取cs基础房型数据 * Name: getRoomInfo * @param $roomId * @param $channel_id * @return array * @author 倪宗锋 */ public function getRoomInfo($roomId, $channel_id) { $select = [ 'a.MAIN_ID', 'a.BASE_ROOM_NAME', 'a.HOTEL_ID', 'b.sub_base_room_id', 'c.sub_hotel_id' ]; $where = [ 'and', ['=', 'a.CANCEL_FLAG', 0], ['=', 'a.MAIN_ID', $roomId] ]; $getInfo = self::find()->select($select) ->from(self::tableName() . ' a') ->leftJoin(ChannelBaseRoomMapping::tableName() . ' b', 'a.MAIN_ID = b.base_room_id and b.channel_id = ' . $channel_id) ->leftJoin(ChannelHotelMapping::tableName() . ' c', 'a.HOTEL_ID = c.hotel_id and c.channel_id = ' . $channel_id) ->where($where) ->asArray() ->one(); return $getInfo; } }