|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2017/10/10
- * Time: 14:42
- *
- * 阿里-飞猪(酒店)对接
- */
-
- namespace backend\modules\hotel\controllers;
-
- use backend\common\Utils;
- use backend\modules\hotel\models\Ali\XhotelRatesIncrementRequest;
- use backend\modules\hotel\models\Ali\XhotelRoomtypeUpdateRequest;
- use backend\modules\hotel\models\Ali\XhotelUpdateRequest;
- use backend\modules\hotel\models\HotelRelation;
- use backend\modules\hotel\models\OperaHotel;
- use backend\modules\hotel\models\OperaHotelBaseRoom;
- use backend\modules\hotel\models\OperaHotelRoom;
- use backend\modules\hotel\models\RoomRelation;
- use backend\modules\hotel\models\Ali\XhotelRateplanUpdateRequest;
- use backend\modules\hotel\models\Ali\XhotelRateUpdateRequest;
- use backend\modules\hotel\models\Ali\XhotelRatesUpdateRequest;
- use backend\modules\hotel\models\Ali\XhotelRateRelationshipwithroomGetRequest;
- use backend\modules\hotel\models\Ali\AliExecute;
- use backend\modules\hotel\models\Ali\TopLogger;
- use backend\modules\hotel\models\RunHotelDistrib;
- use common\models\Msg;
- use Yii;
- use yii\filters\AccessControl;
- use backend\modules\hotel\models\Ali\XhotelOrderUpdateRequest;
-
-
- class AliController extends BaseController
- {
- public $enableCsrfValidation = false;
- public $agent_id = self::AGENT_ALI_HOTEL_ID;
-
- /*public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'ips' => ['101.226.248.76' //阿里IP访问白名单
- ,'127.0.0.1', '106.14.56.77', '180.168.4.58', '139.224.30.29'
- ],
- 'allow' => true,
- ],
- ],
- ],
- ];
- }*/
-
- /**
- * Author:Steven
- * Desc:添加酒店或更新酒店
- * taobao.xhotel.add (酒店新增接口(ID重复自动更新))
- */
- public function actionAddHotel($hotel_id = 0)
- {
- $id = empty($hotel_id) ? Yii::$app->request->get('hotel_id') : $hotel_id;
- $hotel = new OperaHotel();
- $hotel_info = $hotel->getPushHotelInfo($id);
- //判断该酒店的直连渠道有没有阿里
- $channel_arr = explode(',', $hotel_info['DRIECT_CONNNECT_CHANNEL']);
- if (!in_array(Yii::$app->params['ali']['relation_supplier_id'], $channel_arr)) {
- return json_encode(['code' => 203, 'msg' => '该酒店的直连渠道中不包含阿里飞猪,请确认', 'data' => '']);
- }
- // 转换星级表示
- $star = $this->hotelStarConversions($hotel_info['STAR_LEVEL']);
- // 酒店直连信息查询
- $already_connenct = HotelRelation::findOne(['HotelId' => $id, 'ChannelId' => Yii::$app->params['ali']['relation_supplier_id']]);
-
- $param = ['outer_id' => "{$hotel_info['HOTEL_ID']}", 'name' => "{$hotel_info['HOTEL_NAME']}", 'city' => "{$hotel_info['POSTCODE']}", 'address' => "{$hotel_info['HOTEL_ADDRESS']}", 'tel' => '021-33280550', 'star' => "$star"];
- if ($already_connenct) {
- $param['status'] = $hotel_info['HOTEL_STATUS'] == 0 ? -2 : 0;
- $req = new XhotelUpdateRequest(['scenario' => 'update_hotel']);
- } else {
- $req = new XhotelUpdateRequest();
- $already_connenct = new HotelRelation();
- }
-
- if ($req->load($param, '') && $req->validate()) {
- $rs = new AliExecute();
- $res = $rs->execute($req, true);
- if (!$res->xhotel) {
- return json_encode(['code' => $res->code, 'msg' => XhotelUpdateRequest::ERROR_MSG[$res->code], 'data' => '']);
- }
-
- // 阿里直连成功,本地建立关联关系
- $params = array('ChannelHotelId' => (string)$res->xhotel->hid, 'HotelId' => $id, 'ChannelId' => Yii::$app->params['ali']['relation_supplier_id']);
- if ($already_connenct->load($params, '') && $already_connenct->validate()) {
- if ($already_connenct->save()) {
- $logger = new TopLogger;
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '阿里渠道新增直连酒店:' . __FUNCTION__ . json_encode($res)
- ));
- $result = ['code' => 0, 'msg' => '推送酒店成功', 'data' => $res];
- } else {
- $result = ['code' => 204, 'msg' => 'mapping失败', 'data' => $res];
- }
- return json_encode($result);
- }
- } else {
- $logger = new TopLogger;
- $msg = '';
- if (!empty($req->getFirstErrors())) {
- $msg = $req->getErrorMsg();
- }
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '参数验证失败:' . __FUNCTION__ . $msg
- ));
- }
- }
-
- /**
- * @Author wanglg
- * @Desc 房型添加、修改接口(新房型添加,重复房型修改)
- * @param hotel_id // 酒店ID
- * @param PARENT_ROOM_TYPE // 基础房型房型ID
- * @param room_type // 子房型ID
- */
- public function actionRoomUpdate(array $params = [])
- {
- $request = empty($params) ? Yii::$app->request->post() : $params;
-
- // 通过渠道基础房型和子房型type查询房型,将子房型信息推送( 推送前判断是否直连,直连则解除关联,未直连则推送)
- $hotel_is_mapping = HotelRelation::findOne(['HotelId' => $request['hotel_id'], 'ChannelId' => Yii::$app->params['ali']['relation_supplier_id']]);
-
- // 首先判断酒店是否直连
- if (!$hotel_is_mapping) {
- return json_encode(array('code' => 207, 'msg' => '该房型所属酒店还未直连', 'data' => ''));
- }
-
- //推送基础房型
- $room_info = OperaHotelBaseRoom::find()
- ->select(['a.MAIN_ID', 'a.HOTEL_ID', 'a.BASE_ROOM_NAME', 'a.BED_TYPE', 'b.ChannelRoomId', 'c.HOTEL_NAME'])
- ->leftJoin('channel_room_relation as b', 'a.MAIN_ID=b.RoomId and b.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('opera_hotel c', 'a.HOTEL_ID=c.HOTEL_ID and a.cancel_flag=0')
- ->where(['a.MAIN_ID' => $request['parent_room_type'], 'a.HOTEL_ID' => $request['hotel_id']])
- ->from('opera_hotel_base_room as a')
- // -> createCommand() -> getRawSql();
- ->asArray()->one();
-
- $bed_name = $this->getBedTypeName($room_info['BED_TYPE']);
-
- $param = array('outer_id' => (string)$room_info['MAIN_ID'], 'hotel_code' => (string)$room_info['HOTEL_ID'], 'name' => $room_info['BASE_ROOM_NAME'], 'bed_type' => $bed_name);
-
- if ($room_info['ChannelRoomId']) {
- $param['status'] = $room_info['IS_ONSALE'] == 1 ? 0 : -2;
- $scenario = 'update_room';
- } else {
- $scenario = 'add_room';
- }
-
- $room = new XhotelRoomtypeUpdateRequest(['scenario' => $scenario]);
-
- if ($room->load($param, '') && $room->validate()) {
- $rs = new AliExecute();
- $res = $rs->execute($room, true);
- if ($res->code != 0) {
- return json_encode(['code' => 1, 'msg' => XhotelRoomtypeUpdateRequest::ERROR_MSG[$res->code], 'data' => '']);
- }
- $logger = new TopLogger;
- if (!$room_info['ChannelRoomId']) // 推送成功且未直连添加本地记录
- {
- $channel_room_relation = new RoomRelation();
- $save_arr = array('channelRoomId' => (string)$res->xroomtype->rid, 'channelId' => Yii::$app->params['ali']['relation_supplier_id'], 'roomId' => $room_info['MAIN_ID']);
- $room_res = $channel_room_relation->mapping($save_arr);
- if ($room_res) {
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '阿里渠道直连房型成功:' . __FUNCTION__ . json_encode($res)
- ));
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => $res]);
- } else {
- $this->sendAliMsgToRtx('【阿里直连】阿里渠道直连房型成功,建立本地关联关系失败,渠道房型id:',
- "酒店名称:" . $room_info['HOTEL_NAME'] . "\n房型名称:" . $room_info['BASE_ROOM_NAME'] . "\n渠道房型ID:" . $res->xroomtype->rid, 2);
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '阿里渠道直连房型失败:' . __FUNCTION__ . json_encode($res)
- ));
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => $res]);
- }
- } /*else {
- if ($is_connect->delete()) {
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '阿里渠道解除直连房型成功:' . __FUNCTION__ . json_encode($res)
- ));
- return json_encode(['code' => 200, 'msg' => '阿里渠道解除直连房型成功', 'data' => $res]);
- } else {
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '阿里渠道解除直连房型失败, 本地记录删除失败:' . __FUNCTION__ . json_encode($res)
- ));
- return json_encode(['code' => 205, 'msg' => '阿里渠道解除直连房型失败', 'data' => $res]);
- }
- }*/
- } else {
- $logger = new TopLogger;
- $msg = '';
- if (!empty($room->getFirstErrors())) {
- $msg = $room->getErrorMsg();
- }
-
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '参数验证失败:' . __FUNCTION__ . $msg
- ));
-
- return json_encode(['code' => 1, 'msg' => $msg]);
- }
- }
-
- /**
- * Author:Steven
- * @Desc 产品库接口 支持房价信息的新增和修改
- * taobao.xhotel.rateplan.add
- * 接口返回值 rpid
- * @param hotel_id //酒店ID
- * @param parent_room_type //基础房型ID
- * @param room_type //子房型ID
- * @return bool
- */
- public function actionUpdateRateplan()
- {
- //当修改子房型、变更子房型的直连开关的时候需要调用该接口
- $request = Yii::$app->request->post();
- if (!isset($request['hotel_id']) || !isset($request['parent_room_type']) || !isset($request['room_type'])) {
- return json_encode(['code' => 207, 'msg' => '参数错误', 'data' => '']);
- }
- $user_id = empty(Yii::$app->user->id) ? $request['user_id'] : Yii::$app->user->id;
- //先判断酒店是否与渠道直连,房型是否直连
- $diret = OperaHotelRoom::find()->select(['a.ID', 'a.HOTEL_ID', 'a.PARENT_ROOM_TYPE', 'c.ChannelHotelId', 'b.ChannelRoomId', 'a.RP_ID'])
- ->leftJoin('channel_room_relation b', 'a.PARENT_ROOM_TYPE=RoomId and b.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('channel_hotel_relation c', 'a.HOTEL_ID=c.HotelId and c.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->from('opera_hotel_room a')
- ->where([
- 'a.HOTEL_ID' => $request['hotel_id'],
- 'a.PARENT_ROOM_TYPE' => $request['parent_room_type'],
- 'a.ROOM_TYPE' => $request['room_type'],
- 'a.CANCEL_FLAG' => 0
- ])->asArray()->one();
- if (is_null($diret['ChannelHotelId']) || is_null($diret['ChannelRoomId'])) {
- $msg = is_null($diret['ChannelHotelId']) ? '【阿里】该酒店未直连' : (is_null($diret['ChannelRoomId']) ? '【阿里】该房型未直连' : '');
- return json_encode(['code' => 1, 'msg' => $msg, 'data' => '']);
- }
- //构造RP接口需要的数据 // 1 为 开启,2为关闭//借助参数修改rp,不能根据RP是否存在判断打开或关闭RP,存在修改的情况
- $status = empty($request['status']) || is_null($request['status']) ? 1 : $request['status'];
- $ohr = OperaHotelRoom::find()->select(['a.ID', 'a.HOTEL_ID', 'a.PARENT_ROOM_TYPE', 'a.ROOM_TYPE', 'a.ROOM_NAME', 'a.OCCUPANCY_LIMIT', 'a.BREAKFAST_INCLUDE', 'a.IS_ONSALE',
- 'a.LASTEST_BOOK_TIME', 'a.LASTEST_CANCEL_DAY', 'a.INNER_IDENTIFY', 'c.EARLIEST_CHECKIN_TIME', 'c.LASTEST_BOOK_TIME as REMAIN_TIME', 'c.HOTEL_NAME', 'a.INNER_IDENTIFY', 'd.DISTRIB_ROOM_NAME'])
- ->leftJoin('opera_hotel c', 'a.HOTEL_ID=c.HOTEL_ID and c.cancel_flag=0')
- ->leftJoin('opera_room_distrib d', 'a.ID=d.ROOM_ID and d.CANCEL_FLAG=0 and d.DISTRIB_ID=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->where(['a.HOTEL_ID' => $request['hotel_id'],
- 'a.PARENT_ROOM_TYPE' => $request['parent_room_type'],
- 'a.ROOM_TYPE' => $request['room_type'],
- 'a.CANCEL_FLAG' => 0])->from('opera_hotel_room a')->asArray()->one();
-
- $rp_name = '';
- // 判断如果有渠道房型名称RP名称就不使用酒店内部标识
- if (empty($ohr['DISTRIB_ROOM_NAME'])) {
- $ohr['INNER_IDENTIFY'] = str_replace(')', ')', str_replace('(', '(', $ohr['INNER_IDENTIFY']));
- preg_match_all("#\((.*?)\)#us", $ohr['INNER_IDENTIFY'], $inner_identify);
- foreach ($inner_identify[1] as $item) {
- $rp_name .= $item . ' ';
- }
- } else {
- $rp_name = $ohr['DISTRIB_ROOM_NAME'];
- }
-
- $min_adv_hours = Utils::timeHour($ohr['LASTEST_BOOK_TIME']);
- $param = array(
- 'rateplan_code' => "{$ohr['ID']}",
- 'name' => $rp_name == '' ? $ohr['INNER_IDENTIFY'] : $rp_name,
- 'payment_type' => '1', //只支持:1:预付5:现付6: 信用住7:预付在线预约8:信用住在线预约。其中5,6,7,8四种类型需要申请权限
- 'breakfast_count' => $ohr['BREAKFAST_INCLUDE'],
- 'min_adv_hours' => "{$min_adv_hours}",//最小提前预定小时数,从入住当天的24点往前计算。例如如果这个字段设置了48,代表必须至少提前两天预定,那么如果想预定24号入住,,必须在23号零点前下单。
- 'end_time' => '', //产品每日结束销售时间
- 'cancel_policy' => '{"cancelPolicyType":2}',
- 'status' => "{$status}", //1:开启(默认)2:关闭。如果没传值那么默认默认值为1
- 'breakfast_cal' => '{"date": null,"startDate": "' . date('Y-m-d', time()) . '","endDate": "' . date('Y-m-d', strtotime('+3 month')) . '","breakfast_count":' . $ohr['BREAKFAST_INCLUDE'] . '}',
- 'guarantee_type' => '0', // 担保类型,只支持: 0 无担保 1 峰时首晚担保 2峰时全额担保 3全天首晚担保 4全天全额担保
- 'out_rid' => "{$ohr['PARENT_ROOM_TYPE']}", //外部房型id 基础房型ID
- 'out_hid' => "{$ohr['HOTEL_ID']}", // 外部酒店id
- 'operator' => Yii::$app->params['ali']['operator'],
- 'common_allot_release_time' => Utils::timeHour($ohr['REMAIN_TIME'])
- );
- $rateplan = new XhotelRateplanUpdateRequest(['scenario' => 'create']);
-
- if ($rateplan->load($param, '') && $rateplan->validate()) {
- $rs = new AliExecute();
- $res = $rs->execute($rateplan, true);
- if ($res->code != 0) {
- return json_encode(['code' => 0, 'msg' => XhotelRateplanUpdateRequest::ERROR_MSG[$res->code], 'data' => '']);
- }
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => $res->rpid]);
- } else {
- $logger = new TopLogger;
- $msg = '';
- if (!empty($rateplan->getFirstErrors())) {
- $msg = $rateplan->getErrorMsg();
- }
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '参数验证失败:' . __FUNCTION__ . $msg . '--' . $user_id
- ));
- }
- }
-
-
- /**
- * Author:Steven
- * Desc:单个房型和房价的全量价格更新接口 第一次设置RP的时候会推送
- */
- public function actionRateUpdate()
- {
- $request = Yii::$app->request->post();
-
- if (!isset($request['hotel_id']) || !isset($request['parent_room_type']) || !isset($request['room_type'])) {
- return json_encode(['code' => 207, 'msg' => '参数错误', 'data' => '']);
- }
- $user_id = empty(Yii::$app->user->id) ? $request['user_id'] : Yii::$app->user->id;
- //先判断酒店是否与渠道直连,房型是否直连
- $res = OperaHotelRoom::find()->select(['a.ID', 'a.HOTEL_ID', 'a.PARENT_ROOM_TYPE', 'c.ChannelHotelId', 'b.ChannelRoomId', 'a.RP_ID', 'd.HOTEL_NAME', 'a.ROOM_NAME', 'a.INNER_IDENTIFY'])
- ->leftJoin('channel_room_relation b', 'a.PARENT_ROOM_TYPE=RoomId and b.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('channel_hotel_relation c', 'a.HOTEL_ID=c.HotelId and c.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('opera_hotel d', 'a.HOTEL_ID=d.HOTEL_ID and d.cancel_flag=0')
- ->from('opera_hotel_room a')
- ->where([
- 'a.HOTEL_ID' => $request['hotel_id'],
- 'a.PARENT_ROOM_TYPE' => $request['parent_room_type'],
- 'a.ROOM_TYPE' => $request['room_type'],
- 'a.CANCEL_FLAG' => 0
- ])
- // -> createCommand() -> getRawSql();
- ->asArray()->one();
-
- if (is_null($res['ChannelHotelId']) || is_null($res['ChannelRoomId']) || empty($res['RP_ID'])) {
- //酒店或者房型未直连
- $msg = is_null($res['ChannelHotelId']) ? '【阿里】该酒店未直连' : (is_null($res['ChannelRoomId']) ? '【阿里】该房型未直连' : '');
- return json_encode(['code' => 1, 'msg' => $msg, 'data' => '']);
- }
-
- $begin_date = date('Y-m-d', time());
- $end_date = date('Y-m-d', strtotime('+3month'));
-
- // 查出该子房型的信息及渠道房型信息
- $model = new RunHotelDistrib();
- $data = $model->getAvailProduct($res['ID'], $begin_date, $end_date);
- if (empty($data)) {
- return false;
- }
-
- //构造接口需要的数据
- foreach ($data as $item) {
- $inventory_price[] = array(
- 'date' => $item['RUN_DATE'], //日期必须为 T---T+180 日内的日期(T为当天),且不能重复
- 'quota' => $item['REMAINING_COUNT'],//库存 int 类型 取值范围 0-999(数量库存)60000(状态库存关) 61000(状态库存开)
- 'price' => $item['PROD_PRICE'] * 100,//价格 int类型 取值范围1-99999999 单位为分
- );
- if ($item['IS_ONSALE'] == 0 || $item['RUN_STATUS'] == 329 || $item['AUTHORITY_STATUS'] == 0 || $item['ROOM_IS_ONSALE'] == 0
- || $item['ROOM_RUN_STATUS'] == 0) {// 当子房型下线|渠道关房|渠道未授权|子房型关房,关闭价格
- $rate_status = 0;
- } else {
- $rate_status = 1;
- }
- $rate_switch_cal[] = array(
- "date" => $item['RUN_DATE'], //开关状态控制的那一天
- "rate_status" => $rate_status, //开关状态(0,关闭;1,打开)
- );
- }
-
- if (!isset($inventory_price)) {
- return false;
- }
-
- $inventory_price = array( //每日价格和房价专有库存信息
- 'use_room_inventory' => false, //是否使用房型共享库存 ,false时:使用房价专有库存 此时要求价格和库存必填
- 'inventory_price' => $inventory_price
- );
- $param = array(
- 'out_rid' => "{$res['PARENT_ROOM_TYPE']}", //卖家房型ID
- 'rateplan_code' => "{$res['ID']}", //商家价格计划编码
- 'inventory_price' => json_encode($inventory_price),
- 'rate_switch_cal' => json_encode($rate_switch_cal)
- );
-
- $model = new XhotelRateUpdateRequest();
- if ($model->load($param, '') && $model->validate()) {
- $rs = new AliExecute();
- $exec_res = $rs->execute($model, true);
- if ($exec_res->code != 0) {
- return json_encode(['code' => 1, 'msg' => XhotelRateUpdateRequest::ERROR_MSG[$exec_res->code], 'data' => '']);
- }
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => '']);
- } else {
- $logger = new TopLogger;
- $msg = '';
- if (!empty($model->getFirstErrors())) {
- $msg = $model->getErrorMsg();
- }
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '参数验证失败:' . __FUNCTION__ . $msg
- ));
- }
- }
-
- /**
- * Author:Steven
- * Desc:多个房型和房价的价格更新接口
- * @param $flag 当flag为true的时候,全量更新,当flag=false时,增量更新
- * @return bool
- */
- public function actionRatesUpdate(array $param = [], $flag = false)
- {
- $request = empty(Yii::$app->request->post()) ? $param : Yii::$app->request->post();
- if (!isset($request['room_info'])) {
- return json_encode(['code' => 207, 'msg' => '参数错误', 'data' => '']);
- }
- $room_info = json_decode($request['room_info'], true);
- /*$room_info = [
- 0 => [
- 'hotel_id' => '81',
- 'parent_room_type' => '100076',
- 'room_type' => '82',
- 'begin_date' => '2017-11-22',
- 'end_date' => '2017-11-25'
- ],
- 1 => [
- 'hotel_id' => '197',
- 'parent_room_type' => '150246',
- 'room_type' => '9',
- 'begin_date' => '2017-10-30',
- 'end_date' => '2017-11-11'
- ]
- ];*/
- //先判断酒店是否与渠道直连,房型是否直连
- $res = OperaHotelRoom::find()->select(['a.ID', 'a.HOTEL_ID', 'a.PARENT_ROOM_TYPE', 'a.ROOM_TYPE', 'c.ChannelHotelId', 'b.ChannelRoomId', 'a.RP_ID', 'd.HOTEL_NAME', 'a.ROOM_NAME', 'a.INNER_IDENTIFY'])
- ->leftJoin('channel_room_relation b', 'a.PARENT_ROOM_TYPE=RoomId and b.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('channel_hotel_relation c', 'a.HOTEL_ID=c.HotelId and c.ChannelId=' . Yii::$app->params['ali']['relation_supplier_id'])
- ->leftJoin('opera_hotel d', 'a.HOTEL_ID=d.HOTEL_ID and d.cancel_flag=0')
- ->from('opera_hotel_room a');
- // ->andFilterWhere(['in', 'a.ID', [1897, 2284]]);
- foreach ($room_info as $item) {
- $res->orFilterWhere(['a.HOTEL_ID' => $item['hotel_id'], 'a.PARENT_ROOM_TYPE' => $item['parent_room_type'], 'a.ROOM_TYPE' => $item['room_type'], 'a.CANCEL_FLAG' => 0]);
- }
- $user_id = empty(Yii::$app->user->id) ? $room_info[0]['user_id'] : Yii::$app->user->id;
- $res = $res->asArray()->all();
- $diret_hid = [];
- foreach ($res as $item) {
- if (!is_null($item['ChannelHotelId']) && !is_null($item['ChannelRoomId']) && !empty($item['RP_ID'])) { //酒店和房型都直连
- foreach ($room_info as $v) {
- if ($item['HOTEL_ID'] == $v['hotel_id'] && $item['PARENT_ROOM_TYPE'] == $v['parent_room_type'] && $item['ROOM_TYPE'] == $v['room_type']) {
- $diret_hid[] = array(
- 'ID' => $item['ID'],
- 'BEGIN_DATE' => $v['begin_date'],
- 'END_DATE' => $v['end_date']
- );
- }
- }
- }
- }
- if (empty($diret_hid)) {
- return json_encode(['code' => 1, 'msg' => '暂无可推送数据', 'data' => '']);
- }
- $run_hotel_distrib = new RunHotelDistrib();
- foreach ($diret_hid as $room) {
- // 查询该房型在某日期段房态信息
- $data = $run_hotel_distrib->getAvailProduct($room['ID'], $room['BEGIN_DATE'], $room['END_DATE']);
- foreach ($data as $value) {
- $rs['rateplan_code'] = $value['RP_CODE'];
- $rs['vendor'] = "";
- $rs['lock_start_time'] = "";
- $rs['lock_end_time'] = "";
- $data = [
- "date" => $value['RUN_DATE'], //:date 日期必须为 T---T+180 日内的日期(T为当天),不能重复
- "quota" => $value['REMAINING_COUNT'], //房价专有库存 int 类型 取值范围 0-999(数量库存) 60000(状态库存关) 61000(状态库存开)
- "price" => $value['PROD_PRICE'] * 100, //价格 int类型 取值范围1-99999999 单位为分
- "status" => ($value['IS_ONSALE'] == 0 || $value['RUN_STATUS'] == 329 || $value['AUTHORITY_STATUS'] == 0 || $value['ROOM_IS_ONSALE'] == 0 || $value['ROOM_RUN_STATUS'] == 0) ? 0 : 1//status 价格开关,0为关,1为开
- ];
- $rs['out_rid'] = $value['PARENT_ROOM_TYPE'];
- $rs['data']['inventory_price'][] = $data;
- $rs['data']['use_room_inventory'] = false;
- }
-
- if (empty($rs['data']['inventory_price'])) {
- continue;
- }
- $req[] = $rs;
- }
-
- if (empty($req[0]['data']['inventory_price'])) {
- return json_encode(['code' => 2, 'msg' => '子房型:' . $req[0]['rateplan_code'] . '推送失败', 'data' => json_encode($req)]);
- }
-
- $param['rate_inventory_price_map'] = json_encode($req);
- $model = $flag ? new XhotelRatesUpdateRequest() : new XhotelRatesIncrementRequest;
- if ($model->load($param, '') && $model->validate()) {
- $rs = new AliExecute();
- $exec_res = $rs->execute($model, true);
- if ($exec_res->code != 0) {
- return json_encode(['code' => $exec_res->code, 'msg' => XhotelRatesIncrementRequest::ERROR_MSG[$exec_res->code], 'data' => '']);
- }
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => '']);
- } else {
- $logger = new TopLogger;
- $msg = '';
- if (!empty($model->getFirstErrors())) {
- $msg = $model->getErrorMsg();
- }
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '参数验证失败:' . __FUNCTION__ . $msg
- ));
- }
-
- }
-
- /**
- * @Author wanglg
- * @Desc获取阿里后台的Rpid
- */
- public function actionGetRpid($request)
- {
- $xmotel = new XhotelRateRelationshipwithroomGetRequest();
- if ($xmotel->load($request, '') && $xmotel->validate()) {
- $rs = new AliExecute();
- $exec_res = $rs->execute($xmotel, true);
-
- if ($exec_res->code != 0 || $exec_res->total_results == 0) {
- return false;
- }
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Author:Steven
- * Desc:酒店订单发货接口 即确认订单或者拒绝订单
- * @param $tid
- * @param $opt_type
- * @return string
- */
- public function actionConfirmOrder($tid, $opt_type)
- {
- $model = new XhotelOrderUpdateRequest();
- $logger = new TopLogger;
- //操作的类型:1.确认无房(取消预订,710发送短信提醒买家申请退款),2.确认预订 这里的订单号是指淘宝订单号
- $param = ['tid' => "{$tid}", 'opt_type' => $opt_type];
- $logger->log([date("Y-m-d H:i:s"), '酒店确认,未通过参数验证,渠道订单号:' . $tid . "\n" . PHP_EOL], 'ali/error');
- if ($model->load($param, '') && $model->validate()) {
- $logger->log([date("Y-m-d H:i:s"), '酒店确认,通过参数验证,渠道订单号:' . $tid . "\n" . PHP_EOL], 'ali/error');
- $exec = new AliExecute();
- $res = $exec->execute($model, true);
- if ($res->code != 0) {
- //失败消息提醒开发人员的企业微信
- $this->sendAliMsgToRtx('【阿里直连】确认订单失败:', $res->sub_msg . "\n" . '渠道单号:' . $tid, 4);
- return json_encode(['code' => 0, 'msg' => $res->sub_msg . $tid, 'data' => '']);
- }
- $logger->log([date("Y-m-d H:i:s"), '酒店确认, 确认阿里订单成功:' . $tid . "\n" . PHP_EOL], 'ali/error');
- //确认成功
- return json_encode(['code' => 0, 'msg' => 'success', 'data' => $res->rpid]);
- } else {
- $this->sendAliMsgToRtx('【阿里直连】确认订单失败:', '参数验证失败,渠道单号:' . $tid);
- $logger = new TopLogger;
- $msg = '';
- if (!empty($model->getFirstErrors())) {
- $msg = $model->getErrorMsg();
- }
- $logger->log(array(date("Y-m-d H:i:s"), '参数验证失败:' . __FUNCTION__ . $msg));
-
- return json_encode(['code' => 0, 'msg' => 'fail']);
- }
- }
-
- /**
- * @Author wanglg
- * @Desc 酒店星级转化
- * @param $star
- * @return int|string
- */
- public function hotelStarConversions($star)
- {
- switch ($star) {
- case 33:
- $star_level = 1;
- break;
- case 35:
- $star_level = 2;
- break;
- case 37:
- $star_level = 3;
- break;
- case 38:
- $star_level = 4;
- break;
- case 39:
- $star_level = 5;
- break;
- case 40:
- $star_level = 6;
- break;
- case 41:
- $star_level = 7;
- break;
- case 34:
- $star_level = 1.5;
- break;
- case 36:
- $star_level = 2.5;
- break;
- default:
- $star_level = 1;
- }
-
- return $star_level;
- }
-
- /**
- * @Author wanglg
- * @Desc获取床型名称
- * @param $str床型id拼接的字符串
- * @return string 床型名称字符串
- */
- public function getBedTypeName($str)
- {
- $bed_name = '';
- $bed_types = explode(',', $str);
- $bed_name .= in_array(1, $bed_types) ? '大床' : '';
- $bed_name .= in_array(2, $bed_types) ? '双床' : '';
- $bed_name .= in_array(10, $bed_types) ? '多床' : '';
- return $bed_name;
-
- }
-
- /**
- * Author:Steven
- * Desc:阿里酒店直连回调地址
- */
- public function actionCallback()
- {
- $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
- $logger = new TopLogger;
- $logger->conf["log_file"] = dirname(dirname(dirname(__DIR__))) . "/runtime/logs/Ali/callback.log";
- $logger->log(array(
- date("Y-m-d H:i:s"),
- $url
- ));
- }
-
- /**
- * Author:Steven
- * Desc:阿里控制台创建的应用,未上线sessionKey有效期为1天,上线后为三个月,
- */
- public function actionCheckExpireTime()
- {
- $exec = new AliExecute();
- $res = $exec->checkExpireTime();
- if ($res > 85) {
- $this->sendAliMsgToRtx('【阿里直连】sessionKey过期通知::', "sessionKey即将过期,请及时获取最新的sesionKey;\nhttps://open.alitrip.com/docs/doc.htm?spm=a21tt.7629140.0.0.mhPqhk&treeId=164&articleId=104995&docType=1", '');
- $send_txt = "【蜘蛛出行】SessionKey过期通知:sessionKey即将过期,请及时获取最新的sesionKey;\nhttps://open.alitrip.com/docs/doc.htm?spm=a21tt.7629140.0.0.mhPqhk&treeId=164&articleId=104995&docType=1";
- // $send_mobile = "17602134075,18691077519,18257110363,18667946782,18855970997";
- // Msg::sendTelMsg($send_mobile, $send_txt);
- }
- return $res;
-
- }
-
-
- }
-
- ?>
|