|
- <?php
- /**
- * Created by PhpStorm.
- * User: Steven
- * Date: 2017/12/14
- * Time: 10:54
- */
-
- namespace backend\modules\hotel\controllers;
-
- use backend\common\Utils;
- use backend\modules\api\logic\BaseBalance;
- use backend\modules\api\util\Util;
- use backend\modules\hotel\models\Ali\AliOrder;
- use backend\modules\hotel\models\Ali\TopLogger;
- use backend\modules\hotel\models\ApiService;
- use backend\modules\hotel\models\OperaHotel;
- use backend\modules\hotel\models\OperaHotelRoom;
- use backend\modules\hotel\models\OperaRoomDistrib;
- use backend\modules\hotel\models\CommonOrder;
- use backend\modules\hotel\models\OrderMain;
- use backend\modules\hotel\models\RunHotelDistrib;
- use backend\modules\hotel\pinyin\Pinyin;
- use phpDocumentor\Reflection\DocBlock\Tags\Return_;
- use Yii;
- use yii\base\Request;
- use yii\filters\AccessControl;
- use yii\filters\ContentNegotiator;
- use yii\web\Response;
- use backend\modules\hotel\models\CtripOrder;
-
- class ApiController extends BaseController
- {
- public $enableCsrfValidation = false;
- public $request_params;
-
- private $service = null;
-
- private function service()
- {
- if ($this->service == null) {
- $this->service = new ApiService();
- }
-
- return $this->service;
- }
-
- /**
- * Notes:
- * User: Steven
- * Date: 2018/1/17
- * Time: 13:12
- * @param $action
- * @return bool
- * @throws \yii\web\BadRequestHttpException
- */
- public function beforeAction($action)
- {
- //如果传入的是json串,由于在main中配置了JsonParser,所以接收到的json串都会转成数组 因此,这个控制器中的方法,接受json和数组都行
- if (Yii::$app->request->isPost) {
- $this->request_params = empty(Yii::$app->request->post()) ?
- [] : Yii::$app->request->post();
- }
-
- return parent::beforeAction($action);
- }
-
- public function behaviors()
- {
- //配置ContentNegotiator支持JSON和XML响应格式
- $behaviors['contentNegotiator'] = [
- 'class' => ContentNegotiator::className(),
- 'formats' => [
- 'application/xml' => Response::FORMAT_JSON,
- ],
- // 'only' => ['index'],//指定只是针对于index有效
- // 'except'=>[''] //只想剔除某个action
- /*$behaviors['access'] = [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- ],
- ],
- ];*/
- ];
-
- return $behaviors;
- }
-
- /**
- * Author:Steven
- * Desc:
- * @return array
- */
- public function actionIndex()
- {
- //需要传入区域ID、住离店日期、酒店名称(模糊)
-
- return ['name' => 'shifupeng', 'age' => 12];
- }
-
-
- /**
- * Created by PhpStorm.
- * Desc: * Desc:对于设置了保留房的取消时间,即最晚立即确认时间的渠道房型,应该轮询清除符合条件的库存
- * 1、到达失效日期后,该子房型-渠道,满足清除库存日期的库存(固定数量),需清零
- * 2、对于该子房型所属的基础房型的库存,需要按照先保留,再买断的顺序进行库存的扣除
- * 3、注意:这里一定要去除阿里渠道,因为阿里是没有保留房的,都是一单一询,但是要想售卖,必须设置库存,所以对于阿里来说,这里的库存只是为了正常售卖,因此没有保留房的概念,所以不需要库存的扣除
- * User: Steven
- * Date: 2018/2/28jiu
- * Time: 14:05
- * Class actionClearReservingRoom
- * @return bool
- * @throws \yii\db\Exception
- */
- public function actionClearReservingRoom()
- {
- $room_distrib = new OperaRoomDistrib();
- $data = $room_distrib->getNeedClearReservingRoom();
- foreach ($data as $item) {
- if ($item['DISTRIB_ID'] == Yii::$app->params['ali']['supplier_id']) { //阿里渠道无保留房概念之说,所以不做库存的扣除
- continue;
- }
- $time_now = date('H:i');
- $Invalid_time = explode(',', $item['LATEST_COMFIRM_TIME']);
- if ($time_now < $Invalid_time[1]) {
- continue;
- }
- $end_date = date('Y-m-d', strtotime("+ $Invalid_time[0] day"));
- $run_hotel_distrib = new RunHotelDistrib();
- $res = $run_hotel_distrib->clearReservingRoom($item['DISTRIB_ID'], $end_date, $item['HOTEL_ID'], $item['PARENT_ROOM_TYPE'], $item['ROOM_TYPE']);
- if (!$res) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * Author:Steven
- * @param $HOTEL_ID //酒店ID
- * Desc:下单前的可定检查
- * @param $ROOM_ID //房型ID,oprea_hotel_room的 ID
- * @param $ROOM_NUM //预定间数
- * @param $CHECK_IN //入住日期
- * @param $CHECK_OUT //离店日期
- * @param $DISTRIB_ID //渠道ID
- * @param $ROOM_PRICES /价格日历
- * @param $IF_CHECK_PRICE //是否需要校验价格
- * @return array
- */
- public function actionCheckRoomAvail()
- {
- /*$param = [
- 'HotelID' => '339',
- 'RoomID' => '2474',
- 'RoomNum' => '3',
- 'CheckIn' => '2018-01-18',
- 'CheckOut' => '2018-01-20',
- 'DistribID' => 1536,
- 'CreateUserID' => 713,
- 'RoomPrices' => [
- 0 => [
- 'RunDate' => '2018-01-10',
- 'Price' => '100'
- ],
- 1 => [
- 'RunDate' => '2018-01-10',
- 'Price' => '100'
- ],
- ],
- 'IfCheckPrice' => false,
- ];*/
- $newOrder = new CommonOrder(['scenario' => 'CheckRoomAvail']);
- if (!$newOrder->load($this->request_params, '') || !$newOrder->validate()) {
- $error = array_values($newOrder->getFirstErrors());
-
- return ['code' => 1, 'info' => $error[0]];
- } else {
- return $newOrder->checkRoomAvail();
- }
- }
-
- /**
- * Des:获取底价
- * Name: getLowPrice
- * @return array
- * @author 倪宗锋
- */
- public function actionGetLowPrice()
- {
- /*$param = [
- 'HotelID' => '197',
- 'RoomID' => '2284',
- 'RoomNum' => '1',
- 'CheckIn' => '2018-01-12',
- 'CheckOut' => '2018-01-14',
- 'DistribID' => 669,
- 'CreateUserID' => 1,
- 'RoomPrices' => [
- 0 => [
- 'RunDate' => '2018-01-12',
- 'Price' => '150'
- ],
- 1 => [
- 'RunDate' => '2018-01-13',
- 'Price' => '150'
- ]
- ],
- 'IfCheckPrice' => false,
- ];*/
- $newOrder = new CommonOrder(['scenario' => 'CheckRoomAvail']);
- if (!$newOrder->load($this->request_params, '') || !$newOrder->validate()) {
- $error = array_values($newOrder->getFirstErrors());
-
- return ['code' => 1, 'info' => $error[0]];
- } else {
- $check = $newOrder->checkRoomAvail();
- if (isset($check['code']) && $check['code'] == 0) {
- $data['low_price'] = round($check['data']['total_price'] * 0.965, 2);
-
- return ['code' => 0, 'info' => 'success', 'data' => $data];
- } else {
- return $check;
- }
- }
- }
-
- /**
- * Notes:酒店下单接口
- * User: Steven
- * Date: 2017/12/28
- * Time: 15:50
- * @return array
- * @throws \yii\db\Exception
- */
- public function actionBookHotelOrder()
- {
- /*$param = [
- 'CreateUserID' => '259',
- 'OrderID' => '8959468131823000', //渠道订单号
- 'HotelID' => '197', //酒店ID
- 'RoomID' => '2284', //房型ID
- 'DistribID' => 669,//渠道ID
- 'RoomNum' => '1', //房间数量
- 'CheckIn' => '2018-01-12', //入住日期
- 'CheckOut' => '2018-01-13', //离店日期,
- 'TotalPrice' => '150',//订单总价
- 'Currency' => 'RMB', //币种
- 'ContactName' => '石福鹏',//联系人姓名
- 'ContactTel' => '17602134075', //联系人电话
- 'PayType' => 278, // 638:支付宝支付; 221:现金支付 ;275:授信支付;278:微信支付
- 'PayTradeNo' => '2018010221001001590200826788', //支付流水号
- 'OrderGuests' => [
- 0 => [
- 'Name' => '石福鹏',
- ],
- 1 => [
- 'Name' => 'Steven',
- ],
- ], //入住人信息
- 'Comment' => '无', //客人备注
- 'NeedInvoice' => 1,
- 'InvoiceInfos' => [ //发票信息
- 'PostType' => '2', //发票领取方式 1:前台自取 2:邮寄
- 'InvoiceType' => 1, //发票类型 1:增值税普通发票;2:增值税专用发票
- 'Comment' => '代订房费', // 开票项目 一段文本(例如:代订房费、住宿费、会议费、旅游费等)
- 'InvoiceTitle' => '上海蜘蛛行网络科技有限公司',// 发票抬头
- 'CompanyTel' => '021-25684654', //公司电话
- 'CompanyTax' => '50524684554545454545', //公司税号
- 'RegisterAddress' => '上海闵行区虹桥万科中心1号楼', // 公司注册地址
- 'Bank' => '', // 开户行
- 'BankAccount' => '', //银行账号
- 'ReceiverAddress' => '', //邮寄地址
- 'ReceiverName' => '石福鹏', //收件人姓名
- 'ReceiverMobile' => '17602134075', //收件人手机号
- ],
- 'RoomPrices' => [
- 0 => [
- 'RunDate' => '2018-01-12',
- 'Price' => '150'
- ]
- ],
- 'OrderTitleID' => 0 //是否是组合订单,不是传入0,是组合单传入组合单号
- ];*/
- //处理组合订单下单,非组合单,该字段为0
- if (!isset($this->request_params['OrderTitleID'])) {
- $this->request_params['OrderTitleID'] = 0;
- }
-
- $newOrder = new CommonOrder(['scenario' => 'BookHotelOrder']);
- if ($newOrder->load($this->request_params, '') && $newOrder->validate()) {
- $res = $newOrder->bookHotelOrder();
- if ($res['code'] == 0) {
- OrderMain::updateAll(['DOCKING_TYPE' => OrderMain::ORDER_TYPE_CHANNEL, 'CHANNEL_ORDER_STATUS' => OrderMain::ORDER_CHANNEL_STATUS_WAITING, 'UPDATE_TIME' => date('Y-m-d H:i:s', time())],
- ['and', ['CANCEL_FLAG' => 0], ['or', ['ORDER_ID' => $res['data']['order_id']], ['PARENT_ORDER_ID' => $res['data']['order_id']]]]);
- return $res;
- } else {
- return $res;
- }
- } else {
- $error = array_values($newOrder->getFirstErrors());
-
- return ['code' => 1, 'info' => $error[0]];
- }
-
- }
-
- /**
- * Notes: 取消订单
- * User: Steven
- * Date: 2018/1/26
- * Time: 14:29
- * @return array|int
- * @throws \Exception
- * @throws \yii\db\Exception
- */
- public function actionCancelHotelOrder()
- {
- /*$param = [
- 'CreateUserID' => '1',
- 'OrderID' => '11771',
- 'HotelID' => '12',
- 'DistribID' => 164,
- 'RoomID' => '25',
- 'Reason' => '测试取消',
- ];*/
- $newOrder = new CommonOrder(['scenario' => 'CancelHotelOrder']);
- if ($newOrder->load($this->request_params, '') && $newOrder->validate()) {
- $res_code = $newOrder->cancelHotelOrder();
-
- return ['code' => $res_code, 'info' => CommonOrder::RETURN_MSG[$res_code]];
- } else {
- $error = array_values($newOrder->getFirstErrors());
-
- return ['code' => CommonOrder::RETURN_CODE_CANCEL_FAIL, 'info' => $error[0]];
- }
- }
-
- /**
- * 修改订单
- * Notes:这里的修改是指修改与入住需求有关的,比如渠道、日期、间数(但同时也会更新其他辅助信息,如客人姓名等) ,如果只需要更新单个客人姓名、采购价等,单独接口支持
- * 该接口在调用之前,先要请求可定检查接口,确认修改后的房态依然可定
- * User: Steven
- * Date: 2018/1/5
- * Time: 11:48
- * @return array
- * @throws \yii\db\Exception
- */
- public function actionUpdateHotelOrder()
- {
- /*$param = [
- 'CreateUserID' => '713',
- 'ZZ_ORDER_ID' => '2000350', //蜘蛛订单号
- 'OrderID' => '11603', //渠道订单号
- 'HotelID' => '339', //酒店ID
- 'RoomID' => '2474', //房型ID
- 'DistribID' => 1536,//渠道ID
- 'RoomNum' => '3', //房间数量
- 'CheckIn' => '2018-01-18', //入住日期
- 'CheckOut' => '2018-01-19', //离店日期,
- 'TotalPrice' => '600.00',//订单总价
- 'Currency' => 'RMB', //币种
- 'ContactName' => '郑雯 蒋绮嵘 李峥',//联系人姓名
- 'ContactTel' => '13795379620', //联系人电话
- 'OrderGuests' => [
- 0 => [
- 'Name' => '郑雯',
- ],
- 1 => [
- 'Name' => '蒋绮嵘',
- ],
- ], //入住人信息
- 'Comment' => '无', //客人备注
- 'NeedInvoice' => 0,
- 'InvoiceInfos' => [ //发票信息
- 'PostType' => '2', //发票领取方式 1:前台自取 2:邮寄
- 'InvoiceType' => 1, //发票类型 1:增值税普通发票;2:增值税专用发票
- 'Comment' => '代订房费', // 开票项目 一段文本(例如:代订房费、住宿费、会议费、旅游费等)
- 'InvoiceTitle' => '上海蜘蛛行网络科技有限公司',// 发票抬头
- 'CompanyTel' => '021-25684654', //公司电话
- 'CompanyTax' => '50524684554545454545', //公司税号
- 'RegisterAddress' => '上海闵行区虹桥万科中心1号楼', // 公司注册地址
- 'Bank' => '', // 开户行
- 'BankAccount' => '', //银行账号
- 'ReceiverAddress' => '', //邮寄地址
- 'ReceiverName' => '石福鹏', //收件人姓名
- 'ReceiverMobile' => '17602134075', //收件人手机号
- ],
- 'RoomPrices' => [
- 0 => [
- 'RunDate' => '2018-01-18',
- 'Price' => '100',
- ],
- 1 => [
- 'RunDate' => '2018-01-19',
- 'Price' => '100',
- ],
- ],
- ];*/
- $newOrder = new CommonOrder(['scenario' => 'UpdateHotelOrder']);
- if ($newOrder->load($this->request_params, '') && $newOrder->validate()) {
- //if ($newOrder->load($this->request_params, '') && $newOrder->validate()) {
- $res = $newOrder->updateHotelOrder();
- if ($res['code'] == 0) {
- return $res;
- } else {
- return $res;
- }
- } else {
- $error = array_values($newOrder->getFirstErrors());
-
- return ['code' => 1, 'info' => $error[0]];
- }
- }
-
-
- /**
- * Notes:库存共享导致的部分渠道的库存大于基础房型的买断+保留
- * 解决方案:将其他库存大于基础房型买断+保留的渠道库存设置为买断+保留
- * User: Steven
- * Date: 2018/1/9
- * Time: 18:11
- */
- public function actionUpdateStockByShare()
- {
- if (empty($this->request_params['hotel_id']) || empty($this->request_params['check_in']) || empty($this->request_params['check_out']) ||
- empty($this->request_params['distrib_id']) || empty($this->request_params['room_id'])
- ) {
- return ['code' => 3, 'info' => 'params error'];
- }
- $order_main = new OrderMain();
- $order_main->UpdateStockByShare($this->request_params);
-
- }
-
- /**
- * Des:获取酒店的房型列表
- * Name: actionGetHotelRoomList
- * @author 倪宗锋
- */
- public function actionGetHotelRoomListByDate()
- {
- $params = [
- 'hotel_id' => Yii::$app->request->post('hotel_id', ''),//酒店ID 必传
- 'start_date' => Yii::$app->request->post('start_date', ''),//入住日期 必传
- 'end_date' => Yii::$app->request->post('end_date', ''),//离店日期 必传
- 'org_id' => Yii::$app->request->post('org_id', ''),//分销商ID 必传
- 'room_id' => Yii::$app->request->post('room_id', ''),//房型ID 非必传
- ];
- if (empty($params['hotel_id']) || empty($params['start_date']) || empty($params['end_date']) || empty($params['org_id'])) {
- return ['code' => 3, 'info' => 'params error'];
- }
- $getList = $this->service()->getHotelRoomListByDate($params);
-
- return $getList;
- }
-
- /**
- * Des:获取房型基础信息
- * Name: actionGetHotelInfo
- * @return array
- * @author 倪宗锋
- */
- public function actionGetHotelInfo()
- {
- $params = [
- 'hotel_id' => Yii::$app->request->post('hotel_id', ''),//酒店ID 必传
- ];
- if (empty($params['hotel_id'])) {
- return ['code' => 3, 'info' => 'params error'];
- }
- $getList = $this->service()->getHotelInfo($params);
-
- return $getList;
- }
-
- /**
- * 获取酒店的地点
- * @return array
- * 田玲菲
- */
- public function actionGetAreaName()
- {
- $data = array();
- $operaHotel = new OperaHotel();
- $res = $operaHotel->getHotelArea();
- $arr2 = array();
- foreach ($res as $k => $v) {
- $arr2[$k]['id'] = $v['id'];
- $arr2[$k]['area_name'] = str_replace("市", "", $v['area_name']);
- }
- $data['cities'] = $arr2;
- $newArr = array();
- foreach ($res as $v) {
- $firstChar = Pinyin::getShortPinyin(mb_substr($v['area_name'], 0, 1, 'utf-8')); //取出第一个汉字的首字母
- $newArr[strtoupper($firstChar)][] = str_replace("市", "", $v);;//以这个首字母作为key
- }
- ksort($newArr);
- $data['city_list'] = $newArr;
- $data['hot_city'] = [
- [
- 'area_name' => '上海',
- 'id' => 791,
- ],
- [
- 'area_name' => '杭州',
- 'id' => 923,
- ],
- [
- 'area_name' => '舟山',
- 'id' => 999,
- ],
- [
- 'area_name' => '嘉兴',
- 'id' => 961,
- ],
- [
- 'area_name' => '苏州',
- 'id' => 850,
- ],
- ];
-
- return $data;
- }
-
- /**
- * Function Description:微信端获取酒店列表缓存
- * Function Name: actionGetHotelListCache
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function actionGetHotelListCache()
- {
- $getList = $this->service()->getHotelListCache();
-
- return $getList;
- }
-
- /**
- * @Author wanglg
- * @Desc 订单操作相关渠道商供应商预付款接口
- * $type扣款类型,不同扣款类型执行不同操作1.下单操作,2.取消订单,3.修改订单
- * @param int $order_id订单ID
- */
- public function actionSupplierAndChannelPP($type, $order_id)
- {
- if (empty($type) || empty($order_id)) {
- $this->sendAliMsgToRtx('渠道预付款处理失败:', "关联订单号:" . $order_id . "\n错误信息:缺少必要参数", $this->_private);
- }
-
- $model = new CommonOrder();
- $res = $model->previousBalance($type, $order_id);
- if ($res['code'] != 0) {
- $send_msg = "关联订单号:" . $order_id . "\n错误信息:" . $res['msg'];
- $this->sendAliMsgToRtx('渠道预付款处理失败:', $send_msg, $this->_private);
- }
- }
-
- /**
- * Function Description:获取酒店列表筛选条件
- * Function Name: actionGetHotelType
- * @return array
- * @author 李健
- */
- public function actionGetHotelType()
- {
- $getInfo = $this->service()->getHotelType();
-
- return ['code' => 0, 'data' => $getInfo];
- }
-
- /**
- * @Author wanglg
- * @Desc 推送房态接口,统一推送房态接口
- * @param $type1 . 表示携程推送,2. 阿里推送房态信息
- * @param array $param房态数组信息
- */
- public function actionPushRoomInfo(array $param = [])
- {
- $hotel_id = isset($param['hotel_id']) ? $param['hotel_id'] : false;
- $base_room_id = isset($param['parent_room_type']) ? $param['parent_room_type'] : false;
- $room_id = isset($param['room_type']) ? $param['room_type'] : false;
- $param['begin_date'] = empty($param['begin_date']) ? date('Y-m-d') : $param['begin_date'];
- $param['end_date'] = empty($param['end_date']) ? date('Y-m-d', strtotime('+90 days')) : $param['end_date'];
-
- // 判断渠道是否满足目前的直连渠道,不满足则不推送
- if (!in_array($param['channel_id'], [Yii::$app->params['ali']['supplier_id'], Yii::$app->params['ctrip']['supplier_id']])) {
- return false;
- }
-
- if (empty($hotel_id) || empty($base_room_id) || empty($room_id)) {
- $this->sendAliMsgToRtx('房态推送统一接口:', "错误信息:缺少必要参数,酒店信息:" . $hotel_id . ',基础房型信息:' . $base_room_id . ',子房型信息' . $room_id, $this->_private);
-
- return array('code' => 1, 'msg' => '缺少必要参数,酒店信息:' . $hotel_id . ',基础房型信息:' . $base_room_id . ',子房型信息' . $room_id);
- }
-
- $logger = new TopLogger();
- $logger->log(array(
- date("Y-m-d H:i:s"),
- '携程推送参数记录:' . __FUNCTION__ . json_encode($param)
- ));
- $model = new CommonOrder();
- $model->pushRoomStatus($param);
- }
-
- /**
- * @Author wanglg
- * @Desc 获取酒店下单可用库存
- * @param hotel_id酒店id
- * @param parent_room_type酒店基础房型id
- * @param room_type子房型
- * @param channel_id渠道id
- * @param start_date开始日期
- * @param end_date结束日期
- */
- public function actionGetStock()
- {
- /*$param = [
- 'RoomID' => 2474,
- 'DistribID' => 669,
- 'CheckIn' => '2018-01-18',
- 'CheckOut' => '2018-01-21',
- ];*/
- $request = Yii::$app->request->post();
- $orderModel = new CommonOrder(['scenario' => 'Product']);
- if ($orderModel->load($request, '') && $orderModel->validate()) {
- $getStockRes = $orderModel->getMinStock();
-
- return json_encode(array('code' => 0, 'info' => '成功', 'data' => $getStockRes));
- } else {
- $error = array_values($orderModel->getFirstErrors());
-
- return json_encode(['code' => 1, 'info' => $error[0]]);
- }
- }
-
-
- /**
- * Des:返回蜘蛛官网酒店列表
- * Name: actionGetWwwHotelList
- * @return array
- * @author 倪宗锋
- */
- public function actionGetWwwHotelList()
- {
- $DistribID = Yii::$app->request->post('DistribID', '');//分销商ID 必传
- $operaHotel = new OperaHotel();
- $list = $operaHotel->getWwwHotelList($DistribID);
-
- return $list;
- }
-
- public function actionTest()
- {
- $res = AliOrder::findOne(Yii::$app->request->get('id'));
- }
-
- }
-
- ?>
|