|
- <?php
-
- namespace backend\modules\hotel\models;
-
- use Yii;
- use yii\db\ActiveRecord;
- use yii\db\Exception;
-
- /**
- * This is the model class for table "opera_room_distrib".
- *
- * @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 string $DISTRIB_ROOM_NAME
- * @property integer $ROOM_ID
- * @property integer $DISTRIB_ID
- * @property string $LATEST_COMFIRM_TIME
- * @property integer $AUTHORITY_STATUS
- * @property string $CHANNEL_MAPPING_ID
- */
- class OperaRoomDistrib extends ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return 'opera_room_distrib';
- }
-
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['CREATE_USER_ID', 'UPDATE_USER_ID', 'CANCEL_FLAG', 'ROOM_ID', 'DISTRIB_ID', 'AUTHORITY_STATUS'], 'integer'],
- [['UPDATE_TIME'], 'safe'],
- [['DISTRIB_ID'], 'required'],
- [['CREATE_TIME', 'LATEST_COMFIRM_TIME'], 'string', 'max' => 20],
- [['DISTRIB_ROOM_NAME'], 'string', 'max' => 255],
- [['CHANNEL_MAPPING_ID'], 'string', 'max' => 100],
- [['ROOM_ID', 'DISTRIB_ID'], 'unique', 'targetAttribute' => ['ROOM_ID', 'DISTRIB_ID'], 'message' => 'The combination of 房型ID 对应opera_hotel_room的ID and 渠道ID has already been taken.'],
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'ID' => Yii::t('app', 'ID'),
- 'CREATE_USER_ID' => Yii::t('app', '记录创建用户ID'),
- 'CREATE_TIME' => Yii::t('app', '记录创建时间'),
- 'UPDATE_USER_ID' => Yii::t('app', '记录最后更新用户ID'),
- 'UPDATE_TIME' => Yii::t('app', '记录最后更新时间'),
- 'CANCEL_FLAG' => Yii::t('app', '记录有效性标记,0:记录有效;1:记录已删除'),
- 'DISTRIB_ROOM_NAME' => Yii::t('app', '针对渠道设置的子房型名称'),
- 'ROOM_ID' => Yii::t('app', '房型ID 对应opera_hotel_room的ID'),
- 'DISTRIB_ID' => Yii::t('app', '渠道ID'),
- 'LATEST_COMFIRM_TIME' => Yii::t('app', '最晚立即确认时间(即保留房库存取消时间)'),
- 'AUTHORITY_STATUS' => Yii::t('app', '授权状态 1:授权 0:关闭授权'),
- 'CHANNEL_MAPPING_ID' => Yii::t('app', '渠道直连房型ID(携程:房型ID,阿里:RP ID)'),
- ];
- }
-
- public function getOperaHotelRoom()
- {
- return $this->hasOne(OperaHotelRoom::className(), ['ID' => 'ROOM_ID']);
- }
-
- /**
- * Notes:获取所有设置过保留房失效时间的房型
- * User: Steven
- * Date: 2018/1/8
- * Time: 17:40
- * @return array|\yii\db\ActiveRecord[]
- */
- public function getNeedClearReservingRoom()
- {
- $query = self::find()->joinWith('operaHotelRoom b')->where([
- 'a.CANCEL_FLAG' => 0
- ])->from('opera_room_distrib a')->select([
- 'a.ROOM_ID',
- 'a.DISTRIB_ID',
- 'a.LATEST_COMFIRM_TIME',
- 'b.HOTEL_ID',
- 'b.PARENT_ROOM_TYPE',
- 'b.ROOM_TYPE'
- ]);
- $query->andFilterWhere(['<>', 'a.LATEST_COMFIRM_TIME', '-1'])->andFilterWhere(['<>', 'a.DISTRIB_ID', Yii::$app->params['ctrip']['supplier_id']]);
- // $sql = $query->createCommand()->getRawSql();
- $data = $query->asArray()->all();
- return $data;
- }
-
- /**
- * Created by PhpStorm.
- * NOTES:获取渠道房型信息
- * User: Steven
- * Date: 2018/4/28
- * Time: 9:42
- * Class getRoomDistrib
- * @param $room_id
- * @param $distrib_id
- * @return OperaRoomDistrib
- */
- public function getRoomDistrib($room_id, $distrib_id)
- {
- return self::findOne(['ROOM_ID' => $room_id, 'DISTRIB_ID' => $distrib_id, 'CANCEL_FLAG' => 0]);
- }
-
- /**
- * Des:代理通添加房型关联关系
- * Name: addRow
- * @param $data
- * @param $channel_arr
- * @author 倪宗锋
- */
- public function addRow($data, $channel_arr)
- {
- //获取cookies
- $cookies = Yii::$app->request->cookies;
- //账号权限
- $user_id = $cookies->getValue('user_id');
- foreach ($channel_arr as $channel_id) {
- try {
- $values = [
- 'CREATE_TIME' => date('Y-m-d H:i:s'),
- 'CREATE_USER_ID' => empty($user_id) ? 0 : $user_id,
- 'DISTRIB_ID' => $channel_id,
- 'DISTRIB_ROOM_NAME' => $data['DISTRIB_ROOM_NAME'],
- 'ROOM_ID' => $data['ROOM_ID'],
- 'CHANNEL_MAPPING_ID' => (string) $data['CHANNEL_MAPPING_ID']
- ];
- if (empty($basicRoomTyp) == false) {
- $values['base_room_is_add'] = 1;
- }
- $table = clone $this;
- $where = [
- 'ROOM_ID' => $data['ROOM_ID'],
- 'DISTRIB_ID' => $channel_id,
- 'CANCEL_FLAG' => 0
- ];
- $result = $table->findOne($where);
- if ($result == null) {
- $table->setAttributes($values);
- $flag = $table->save();
- }else{
- $result->setAttributes($values);
- $flag = $result->save();
- }
- if ($flag == false) {
- // $error = $result->getErrors();
- }
- } catch (Exception $e) {
- }
- }
- }
-
- /**
- * Des:修改代理通房型关联关系
- * Name: editRow
- * @param $data
- * @param $channel_arr
- * @author 倪宗锋
- */
- public function editRow($data, $channel_arr)
- {
- $params = [
- 'update_time' => date('Y-m-d H:i:s'),
- 'CHANNEL_MAPPING_ID' => $data['CHANNEL_MAPPING_ID'],
- 'DISTRIB_ROOM_NAME' => $data['DISTRIB_ROOM_NAME'],
- ];
- $where = [
- 'ROOM_ID' => $data['ROOM_ID'],
- 'DISTRIB_ID' => $channel_arr
- ];
- self::updateAll($params,$where);
- }
-
- /**
- * Function Description:根据渠道和渠道直连ID获取房型ID
- * Function Name: getRoomIdByMappingId
- * @param $distrib_id
- * @param $mapping_id
- *
- * @return mixed
- *
- * @author 娄梦宁
- */
- public function getRoomIdByMappingId($distrib_id,$mapping_id){
- $result=self::find()->select('ROOM_ID')->from(self::tableName())
- ->where(['and',['=','cancel_flag',0],['=','distrib_id',$distrib_id],['=','channel_mapping_id',$mapping_id]])
- ->asArray()->one();
- return $result['ROOM_ID'];
- }
- }
|