|
- <?php
- /**
- * Created by PhpStorm.
- * User: wangxj
- * Date: 2017/4/12
- * Time: 13:54
- * $OrderID, $InterFaceSendID, $Hotel, $HotelName, $Arrival, $Departure,
- * $EarlyArrivalTime, $LastArrivalTime, $Person, $Notice, $IsHoldRoom,
- * $IsFlashLive, $Guests, $mobilePhone, $Currency, $Amount, $CNYAmount, $GuaranteeType, $BalanceType,
- * $Room, $RoomPerson, $RoomName, $Quantity, $CostAmount, $CNYCostAmount,
- * $RoomPrices, $AddOptionals, $InterFaceConfirmNo, $HotelConfirmNo, $InterFaceAmount, $ReturnCode, $ReturnDescript,
- * $OrderStatus, $FGToPP, $DepositAmount, $IsFreeSale
- */
-
- namespace backend\modules\hotel\models;
-
- use backend\common\Utils;
- use Yii;
- use common\models\BaseSupplier;
- use common\models\BaseSupplierSale;
- use yii\base\Model;
-
- class CtripRoomInfo extends Model
- {
- public $relation_supplier_id;
- public $Spider_hotel; //蜘蛛的酒店id,opera_hotel HOTEL_ID
- public $Spider_room; //蜘蛛的房型id,opera_hotel_room ID
- public $Spider_room_type; //蜘蛛的房型id,opera_hotel_room ROOM_TYPE
-
- public $RoomID; //Ctrip房型ID
- public $StartDate; //开始时间
- public $EndDate; //结束时间
- public $Editer; //提交人:集团名拼音
-
- public $RoomInfoItems = []; //保留房用最晚预订时间
- public $defaultItem; //一个房态的默认值
- public $ChangeDefault; //Boolean 是否同时修改房态默认值(F-否,T-是)
- public $HoldDeadline; //【现付产品使用】9999 无规定
- public $UserLimited; //【现付产品使用】2-超时担保,3-一律担保,9999-无限制
- public $Note; // 备注
- public $ReserveTime; //小时数,例如 1 为一小时 。计算公式:订单入住日24点向 后推算
- public $Roomstatus; //G良好 N满房
- public $RoomsInv; // 临时保留房总数
- public $Guarantee; //担保 默认:空字符
- public $GuaranteeLCT; //担保最晚取消时间 【现付产品使用】小时数,不可 取消设置为23988
- public $PrepayLCT; //预付最晚取消时间【预付产品使用】小时数,不可 取消设置为23988
- // public $AllNeedGuarantee; //需要担保的类型 【现付产品使用】全额/峰时担保(F-否,T-全额担保,B-峰时担 保)
- public $LateReserveTime; //订单最晚预定时间
- public $DeductType; //预付房型扣款类型 【预付产品使用】(C-全部扣款,F-首日扣款)
- public $BlanceType; //付款类型 推送对应的现付,预付,和PKG的CODE
-
- public function __construct(array $config = [])
- {
- $this->relation_supplier_id = Yii::$app->params['ctrip']['relation_supplier_id'];
- $this->defaultItem['Stays'] = '1';
- $this->defaultItem['ChangeDefault'] = 'F';
- $this->defaultItem['Recommend'] = '2';
- $this->defaultItem['Recommend_Intl'] = '2';
- $this->defaultItem['HoldDeadline'] = '9999'; //现付产品使用
- $this->defaultItem['UserLimited'] = '9999';
- $this->defaultItem['Note'] = '';
- $this->defaultItem['Restorable'] = 'T';
- $this->defaultItem['Guarantee'] = '';
- $this->defaultItem['CheckType'] = 'S';
- $this->defaultItem['GuaranteeLCT'] = '23988';
- $this->defaultItem['AllNeedGuarantee'] = 'F';
- // $this->defaultItem['RoomGiftID'] = '';
- $this->defaultItem['DeductType'] = 'C';
- //Roomstatus N满房 G良好
- //RoomsInv 房间数量
- //Note 备注
- //ReserveTime 保留房最晚预订时间
- //PrepayLCT 预付订单 最晚取消时间
- //LateReserveTime 订单最晚预订时间
- parent::__construct($config);
- }
-
- public function rules()
- {
- return [
- [[
- 'RoomID', 'StartDate', 'EndDate', 'defaultItem', 'RoomInfoItems',
- ], 'required'],
- [['RoomInfoItems'], 'validateItems'],
- [['RoomID'], 'validatePrimary', 'params' => ['message' => '获取mapping失败']],
-
- ];
- }
-
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'RoomID' => '渠道房型ID',
- 'RoomInfoItems' => '房态数组',
- 'StartDate' => '起始时间',
- 'EndDate' => '结束时间',
- 'defaultItem' => '房态默认值',
- ];
- }
-
- /**
- * User: wangxj
- *
- * 加载数据
- *
- * @param array $post
- * @param null $formName
- * @return bool
- */
- public function load($data, $formName = null)
- {
- $scope = $formName === null ? $this->formName() : $formName;
- if ($scope === '' && !empty($data)) {
- $this->setAttributes($data, false);
- $this->RoomID = RoomRelation::getChannelId($this->Spider_room, Yii::$app->params['ctrip']['relation_supplier_id']);
- $startDate = $data['StartDate'];
- $endDate = $data['EndDate'];
- //mapping酒店 id和房型id
- $room = OperaHotelRoom::findOne($data['Spider_room']);
- if (empty($room)) {
- return false;
- }
- /*$hotel = OperaHotel::findOne(['HOTEL_ID' => $room['HOTEL_ID']]);
- if (empty($hotel)) {
- return false;
- }*/
- $stocks = RunHotelDistrib::find()
- ->select(['DISTINCT(RUN_DATE)', 'a.CREATE_USER_ID', 'a.CREATE_TIME', 'a.UPDATE_USER_ID', 'a.UPDATE_TIME', 'a.DISTRIB_ID', 'a.HOTEL_ID', 'a.BASE_ROOM_TYPE', 'a.ROOM_TYPE',
- 'a.REMAINING_COUNT', 'a.SALED_COUNT', 'a.PROD_PRICE', 'a.CUS_PRICE', 'a.RUN_STATUS', 'a.OVERSELL_FLAG', 'a.CONSUME_STOCK_TYPE', 'b.AUTHORITY_STATUS', 'b.LATEST_COMFIRM_TIME'])
- ->leftJoin('opera_room_distrib b', 'b.DISTRIB_ID = a.DISTRIB_ID AND b.ROOM_ID=' . $room['ID'])
- ->where(['a.DISTRIB_ID' => Yii::$app->params['ctrip']['supplier_id'], 'a.HOTEL_ID' => $room['HOTEL_ID'], 'a.BASE_ROOM_TYPE' => $room['PARENT_ROOM_TYPE'], 'a.ROOM_TYPE' => $room['ROOM_TYPE']])
- ->andFilterWhere(['between', 'a.RUN_DATE', $startDate, $endDate])
- ->from('run_hotel_distrib a')
- ->orderBy('a.RUN_DATE')
- // -> createCommand() -> getRawSql();
- ->asArray()->all();
- foreach ($stocks as $stock) {
- $subRoom = RunHotelSubRoom::findOne(['HOTEL_ID' => $room['HOTEL_ID'], 'BASE_ROOM_TYPE' => $room['PARENT_ROOM_TYPE'],
- 'ROOM_TYPE' => $room['ROOM_TYPE'], 'RUN_DATE' => $stock['RUN_DATE']]);
- $item = $this->defaultItem;
- $item['Roomstatus'] = (
- $room->IS_ONSALE == OperaHotelRoom::IS_ONSALE &&
- $stock['RUN_STATUS'] == RunHotelDistrib::ROOM_STATUS_SALE &&
- $subRoom->RUN_STATUS == RunHotelSubRoom::RUN_STATUS_OPEN &&
- $stock['AUTHORITY_STATUS'] == RunHotelDistrib::AUTHORITY_STATUS_ON
- ) ? 'G' : 'N';
- //如果超卖关了,设置为只销售保留房
- if ($item['Roomstatus'] == 'G' && $stock['OVERSELL_FLAG'] == RunHotelDistrib::OVERSELL_OFF) {
- if ($stock['REMAINING_COUNT'] <= 0) {
- $item['Roomstatus'] = 'N';
- } else
- $item['Roomstatus'] = 'L';
- }
- $item['RoomsInv'] = ($room->IS_ONSALE == OperaHotelRoom::IS_OFFSALE || $stock['RUN_STATUS'] == RunHotelDistrib::ROOM_STATUS_CLOSE) ? 0 : $stock['REMAINING_COUNT'];
- //保留房最晚预订时间
- $item['ReserveTime'] = Utils::timeHour($stock['LATEST_COMFIRM_TIME']);
- $item['PrepayLCT'] = Utils::timeHour($room->LASTEST_CANCEL_DAY, 'rule');
- $item['LateReserveTime'] = Utils::timeHour($room->LASTEST_BOOK_TIME);
- $this->RoomInfoItems[] = ['RoomInfoItem' => $item];
- }
-
- return true;
- } elseif (isset($data[$scope])) {
- $this->setAttributes($data[$scope]);
-
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * User: wangxj
- *
- * 检查mapping的酒店房型是否正常
- *
- * @param $attribute
- * @param $params
- */
- public function validatePrimary($attribute, $params)
- {
- if ($this->Spider_room == 0 || $this->RoomID == 0) {
- $this->addError($attribute, $params['message']);
- }
- }
-
- /**
- * User: wangxj
- *
- * 检查房态数据是否正常
- *
- * @param $attribute
- // * @param $params
- */
- public function validateItems($attribute)
- {
- if (count($this->$attribute) <= 0) {
- $this->addError($attribute, '无法获取日期');
- } else {
- //判断一下时间是否对应,startDate to endDate中的日期,是否都一一对应
- $start = strtotime($this->StartDate);
- $end = strtotime($this->EndDate);
- $day_count = ($end - $start) / (3600 * 24);
- if ($day_count >= 120) {
- $this->addError($attribute, '一次最多推送120天数据');
- } elseif ($day_count + 1 != count($this->$attribute)) {
- $this->addError($attribute, '房态数据没有一一对应');
- } else {
- foreach ($this->$attribute as $key => $item) {
-
- }
-
- }
- }
- }
- }
|