|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380 |
- <?php
- /**
- * 本类是用于开发或运维人员手动设置酒店的mapping
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm SetController.php
- * Create By 2017/4/13 9:30 $
- */
-
-
- namespace backend\modules\hotel\controllers;
-
- use backend\modules\hotel\models\ChannelHotel;
- use backend\modules\hotel\models\CtripOrder;
- use backend\modules\hotel\models\HotelRelation;
- use backend\modules\hotel\models\OperaHotel;
- use backend\modules\hotel\models\OperaHotelRoom;
- use backend\modules\hotel\models\RoomRelation;
- use backend\modules\hotel\models\SetService;
- use backend\modules\hotel\models\OrderChannelInfo;
- use backend\modules\hotel\models\OrderMain;
- use yii\db\Exception;
- use yii\db\Expression;
- use common\components\zOfficeWechat;
- use yii\filters\AccessControl;
-
- class SetController extends BaseController
- {
- public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
- public $enableCsrfValidation = false;
- public $service = null;
-
- // public $layout = false;
-
- /* public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'except' => [""],
- 'rules' => [
- [
- 'ips' => ['127.0.0.1', '106.14.56.77', '180.168.4.58', '139.224.30.29' //蜘蛛IP访问白名单
- ,"183.157.15.208","125.118.58.113","115.216.25.157","183.128.189.216" //杭州IP
- , '116.236.255.166', //小黑鱼IP
- ],
- 'allow' => true,
- ],
- ],
- ],
- ];
- }*/
-
- public function service()
- {
- if ($this->service == null) {
- $this->service = new SetService();
- }
- return $this->service;
- }
-
- public function actionClearRoom()
- {
- $hotel_list = \Yii::$app->request->post('hotel_list');
- $hotel_list = explode(',', $hotel_list);
- $channelHotelRelation = new HotelRelation();
- $tran = \Yii::$app->db->beginTransaction();
- $flag = true;
- try {
- foreach ($hotel_list as $item) {
- $params = [
- 'channelHotelId' => $item,
- 'channelId' => \Yii::$app->params['ctrip']['relation_supplier_id'],
- ];
- $flag = $flag && $channelHotelRelation->clearRoom($params);
- }
- if ($flag)
- $tran->commit();
- else {
- $tran->rollBack();
- echo 'false';
- }
- } catch (Exception $e) {
- $tran->rollBack();
- echo 'false';
- }
- }
-
- /**
- * Des:操作页面
- * Name: actionIndex
- * @return string
- * @author 倪宗锋
- */
- public function actionIndex($user = null)
- {
- // $list = $this->service()->getChannelHotelList();
- $searchModel = new ChannelHotel();
- $dataProvider = $searchModel->search(\Yii::$app->request->queryParams, $user);
-
- $id = \Yii::$app->request->get('id', '');//渠道酒店ID
- $hotel_list = OperaHotel::find()
- ->joinWith('hotelRelation')
- ->andFilterWhere([
- 'CANCEL_FLAG' => 0,
- 'HOTEL_STATUS' => 1,
- 'PRINCIPAL' => $user
- ])
- ->andWhere('HotelId is null')
- ->orderBy(new Expression('CONVERT(HOTEL_NAME USING GBK)'))
- ->all();
- return $this->render('index', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
- 'id' => $id,
- 'hotel_list' => $hotel_list
- ]);
- // return '';
- }
-
- /**
- * Des:操作页面
- * Name: actionIndex
- * @return string
- * @author 倪宗锋
- */
- public function actionRoomList()
- {
- $hotelId = \Yii::$app->request->get('id', '');//渠道酒店ID
- $getHotrlId = $this->service()->getHotelIdByChannelHotelId($hotelId);
- $room_id = \Yii::$app->request->get('room_id', '');//本地房型ID
- $list = $this->service()->getRoomListByHotelId($hotelId);
- $room_waiting_list = OperaHotelRoom::find()
- ->addSelect(['ID', 'concat(ROOM_NAME, \'|\', INNER_IDENTIFY) as ROOM_NAME'])
- ->leftJoin(RoomRelation::tableName(), ['ID' => new Expression('RoomId')])
- ->where([
- 'HOTEL_ID' => $getHotrlId['HOTEL_ID'],
- 'CANCEL_FLAG' => 0,
- 'IS_ONSALE' => 1,
- ])
- ->andWhere('RoomId is null')
- ->orderBy(new Expression('CONVERT(ROOM_NAME USING GBK)'))
- ->all();
- return $this->render('room', [
- 'hotelId' => $hotelId,
- 'getHotrlId' => $getHotrlId,
- 'room_id' => $room_id,
- 'list' => $list,
- 'room_waiting_list' => $room_waiting_list
- ]);
- // include (__DIR__) . '/../views/set/room.phtml';
- // return '';
- }
-
- /**
- * Des:更新酒店数据
- * Name: actionUpJd
- * @return string
- * @author 倪宗锋
- */
- public function actionUpHotel()
- {
- $upRes = $this->service()->upJD();
- return json_encode($upRes);
- }
-
- /**
- * Des:更新房间数据
- * Name: actionUpRoom
- * @return string
- * @author 倪宗锋
- */
- public function actionUpRoom()
- {
- $params = [
- 'channelHotelId' => \Yii::$app->request->post('channelHotelId', '2652602'),//渠道酒店ID
- 'channelId' => \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']),//渠道ID
- ];
- $upRes = $this->service()->upRoom($params);
- return json_encode($upRes);
- }
-
- /**
- * Des:关联酒店
- * Name: actionMappingJd
- * @return string
- * @author 倪宗锋
- */
- public function actionMappingHotel()
- {
- $params = [
- 'channelHotelId' => \Yii::$app->request->post('channelHotelId', ''),//渠道酒店ID
- 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
- 'hotelId' => \Yii::$app->request->post('hotelId', ''),//酒店ID
- ];
- $mappingDes = $this->service()->mappingJd($params);
- return json_encode($mappingDes);
- }
-
- /**
- * Des:解绑酒店
- * Name: unMappingHotel
- * @param $setType integer -3:仅取消 -4:取消且删除价格
- * @return string
- * @author 倪宗锋
- */
- public function actionUnMappingHotel($setType = RoomRelation::MAPPING_SET_TYPE_DELETE_HOTEL)
- {
- $params = [
- 'channelHotelId' => \Yii::$app->request->post('channelHotelId', ''),//渠道房型ID
- 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
- ];
- $mappingDes = $this->service()->unMappingHotel($params, $setType);
- return json_encode($mappingDes);
- }
-
- /**
- * Des:关联房型
- * Name: actionMappingRoom
- * @param $setType integer
- * @return string
- * @author 倪宗锋
- */
- public function actionMappingRoom($setType = RoomRelation::MAPPING_SET_TYPE_NEW)
- {
- $params = [
- 'channelRoomId' => \Yii::$app->request->post('channelRoomId', ''),//渠道房型ID
- 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
- 'roomId' => \Yii::$app->request->post('roomId', ''),//房型ID
- ];
- $mappingDes = $this->service()->mappingRoom($params, $setType);
- return json_encode($mappingDes);
- }
-
- /**
- * Des:解除关联操作
- * Name: actionUnMappingRoom
- * @param $setType integer
- * @return string
- * @author 倪宗锋
- */
- public function actionUnMappingRoom($setType = RoomRelation::MAPPING_SET_TYPE_DELETE_ROOM)
- {
- $params = [
- 'channelRoomId' => \Yii::$app->request->post('channelRoomId', ''),//渠道房型ID
- 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
- 'roomId' => \Yii::$app->request->post('roomId', ''),//房型ID
- ];
- $mappingDes = $this->service()->unMappingRoom($params, $setType);
- return json_encode($mappingDes);
- }
-
- /**
- * Des:校验mapping信息
- * Name: actionCheckMapping
- * @return array
- * @author 倪宗锋
- */
- public function actionCheckMapping()
- {
- $checkMapping = $this->service()->checkMapping();
- return json_encode($checkMapping);
- }
-
- /**
- * Des:推送订单状态
- * Name: actionSetOrderStatus
- * @return string
- * @author 倪宗锋
- */
- public function actionSetOrderStatus()
- {
-
- $params = [
- 'OrderID' => \Yii::$app->request->post('OrderID', ''),//订单ID
- 'InterfaceConfirmNo' => \Yii::$app->request->post('InterfaceConfirmNo', ''),//酒店确认号
- 'OrderStatus' => \Yii::$app->request->post('OrderStatus', ''),//订单状态 3:确认;4:拒绝
- 'InterFaceSendID' => \Yii::$app->request->post('InterFaceSendID', ''),//订单接口发送号
- 'ResultCode' => \Yii::$app->request->post('ResultCode', ''),
- 'Message' => \Yii::$app->request->post('Message', ''),
- 'channelId' => \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']),
- ];
- /*$params = [
- 'OrderID' => '4710796222',//订单ID
- 'InterfaceConfirmNo' => '3387620972,3389705049,3387086919',//酒店确认号
- 'OrderStatus' => '3',//订单状态 3:确认;4:拒绝
- 'InterFaceSendID' => 145441316,//订单接口发送号
- 'channelId' => '669',//渠道ID
- ];*/
- $order_id = \Yii::$app->request->post('OrderID', '');
- $b = \Yii::$app->request->post('InterfaceConfirmNo', '');
- $OrderStatus = \Yii::$app->request->post('OrderStatus', '');
- $InterFaceSendID = \Yii::$app->request->post('InterFaceSendID', '');
- $channelId = \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']);
- if ($channelId != 669) {
- $arr = array(
- "agentid" => 1000002,
- "title" => '客服接单',
- "msg" => $order_id . '-' . $b . '-' . $OrderStatus . '-' . $InterFaceSendID . '-' . $channelId,
- "touser" => 'shifp|wanglg',
- );
- zOfficeWechat::sendMsg($arr);
- }
-
- $setDes = $this->service()->setOrderStatus($params);
- if ($setDes['flag'] == false) {
- $return = ['code' => 1, 'info' => $setDes['msg']];
- } else {
- $return = ['code' => 0, 'info' => 'success'];
- }
- return json_encode($return);
- }
-
-
- /**
- * User:Steven
- * Desc:
- * @param $url
- * @param array $param
- * @return array|mixed
- */
- function httpsPostParam($url, $param = array())
- {
- $ch = curl_init(); // 初始化一个 cURL 对象
- curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
- curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
- // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
- ));
- $rtn = curl_exec($ch); // 运行cURL,请求网页
- if ($errno = curl_errno($ch)) {
- return array('code' => '1', 'info' => '接口调用失败!');
- }
- curl_close($ch); // 关闭URL请求
- return json_decode($rtn, true); // 返回获取的数据
- // return array('code'=> '0','info'=> '对接成功');
- }
-
-
- /**
- * User:Steven
- * Desc:手动推送订单状态
- */
- public function actionPushCtripStatus()
- {
- $a = array(1842200);
- foreach ($a as $v) {
- $order_id = $v;
- $rs = OrderMain::find()->select(['OUTSIDE_ORDER_NO', 'ORDER_CONFIRM_CODE'])->where(['PARENT_ORDER_ID' => 0, 'ORDER_ID' => $order_id])->asArray()->one();
- $ctrip_order_id = $rs['OUTSIDE_ORDER_NO'];
- $ORDER_CONFIRM_CODE = $rs['ORDER_CONFIRM_CODE'];
- $res = OrderChannelInfo::find()->select(['InterFaceSendID'])->where(['ORDER_ID' => $order_id, 'CANCEL_FLAG' => 0])->asArray()->one();
- $InterfaceConfirmNo = $res['InterFaceSendID'];
- $param = array(
- 'OrderID' => $ctrip_order_id,
- 'InterfaceConfirmNo' => $ORDER_CONFIRM_CODE,
- 'OrderStatus' => CtripOrder::ORDER_STATUS_REFUSED,
- 'InterFaceSendID' => $InterfaceConfirmNo,
- 'ResultCode' => CtripOrder::RETURN_CODE_STOCK_FAIL,
- 'Message' => CtripOrder::RETURN_MSG[CtripOrder::RETURN_CODE_STOCK_FAIL],
- 'channelId' => \Yii::$app->params['ctrip']['relation_supplier_id'] //携程
- );
- $set = new SetService();
- $setDes = $set->setOrderStatus($param);
- }
-
- }
- }
|