You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SetController.php 14 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. /**
  3. * 本类是用于开发或运维人员手动设置酒店的mapping
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm SetController.php
  13. * Create By 2017/4/13 9:30 $
  14. */
  15. namespace backend\modules\hotel\controllers;
  16. use backend\modules\hotel\models\ChannelHotel;
  17. use backend\modules\hotel\models\CtripOrder;
  18. use backend\modules\hotel\models\HotelRelation;
  19. use backend\modules\hotel\models\OperaHotel;
  20. use backend\modules\hotel\models\OperaHotelRoom;
  21. use backend\modules\hotel\models\RoomRelation;
  22. use backend\modules\hotel\models\SetService;
  23. use backend\modules\hotel\models\OrderChannelInfo;
  24. use backend\modules\hotel\models\OrderMain;
  25. use yii\db\Exception;
  26. use yii\db\Expression;
  27. use common\components\zOfficeWechat;
  28. use yii\filters\AccessControl;
  29. class SetController extends BaseController
  30. {
  31. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  32. public $enableCsrfValidation = false;
  33. public $service = null;
  34. // public $layout = false;
  35. /* public function behaviors()
  36. {
  37. return [
  38. 'access' => [
  39. 'class' => AccessControl::className(),
  40. 'except' => [""],
  41. 'rules' => [
  42. [
  43. 'ips' => ['127.0.0.1', '106.14.56.77', '180.168.4.58', '139.224.30.29' //蜘蛛IP访问白名单
  44. ,"183.157.15.208","125.118.58.113","115.216.25.157","183.128.189.216" //杭州IP
  45. , '116.236.255.166', //小黑鱼IP
  46. ],
  47. 'allow' => true,
  48. ],
  49. ],
  50. ],
  51. ];
  52. }*/
  53. public function service()
  54. {
  55. if ($this->service == null) {
  56. $this->service = new SetService();
  57. }
  58. return $this->service;
  59. }
  60. public function actionClearRoom()
  61. {
  62. $hotel_list = \Yii::$app->request->post('hotel_list');
  63. $hotel_list = explode(',', $hotel_list);
  64. $channelHotelRelation = new HotelRelation();
  65. $tran = \Yii::$app->db->beginTransaction();
  66. $flag = true;
  67. try {
  68. foreach ($hotel_list as $item) {
  69. $params = [
  70. 'channelHotelId' => $item,
  71. 'channelId' => \Yii::$app->params['ctrip']['relation_supplier_id'],
  72. ];
  73. $flag = $flag && $channelHotelRelation->clearRoom($params);
  74. }
  75. if ($flag)
  76. $tran->commit();
  77. else {
  78. $tran->rollBack();
  79. echo 'false';
  80. }
  81. } catch (Exception $e) {
  82. $tran->rollBack();
  83. echo 'false';
  84. }
  85. }
  86. /**
  87. * Des:操作页面
  88. * Name: actionIndex
  89. * @return string
  90. * @author 倪宗锋
  91. */
  92. public function actionIndex($user = null)
  93. {
  94. // $list = $this->service()->getChannelHotelList();
  95. $searchModel = new ChannelHotel();
  96. $dataProvider = $searchModel->search(\Yii::$app->request->queryParams, $user);
  97. $id = \Yii::$app->request->get('id', '');//渠道酒店ID
  98. $hotel_list = OperaHotel::find()
  99. ->joinWith('hotelRelation')
  100. ->andFilterWhere([
  101. 'CANCEL_FLAG' => 0,
  102. 'HOTEL_STATUS' => 1,
  103. 'PRINCIPAL' => $user
  104. ])
  105. ->andWhere('HotelId is null')
  106. ->orderBy(new Expression('CONVERT(HOTEL_NAME USING GBK)'))
  107. ->all();
  108. return $this->render('index', [
  109. 'searchModel' => $searchModel,
  110. 'dataProvider' => $dataProvider,
  111. 'id' => $id,
  112. 'hotel_list' => $hotel_list
  113. ]);
  114. // return '';
  115. }
  116. /**
  117. * Des:操作页面
  118. * Name: actionIndex
  119. * @return string
  120. * @author 倪宗锋
  121. */
  122. public function actionRoomList()
  123. {
  124. $hotelId = \Yii::$app->request->get('id', '');//渠道酒店ID
  125. $getHotrlId = $this->service()->getHotelIdByChannelHotelId($hotelId);
  126. $room_id = \Yii::$app->request->get('room_id', '');//本地房型ID
  127. $list = $this->service()->getRoomListByHotelId($hotelId);
  128. $room_waiting_list = OperaHotelRoom::find()
  129. ->addSelect(['ID', 'concat(ROOM_NAME, \'|\', INNER_IDENTIFY) as ROOM_NAME'])
  130. ->leftJoin(RoomRelation::tableName(), ['ID' => new Expression('RoomId')])
  131. ->where([
  132. 'HOTEL_ID' => $getHotrlId['HOTEL_ID'],
  133. 'CANCEL_FLAG' => 0,
  134. 'IS_ONSALE' => 1,
  135. ])
  136. ->andWhere('RoomId is null')
  137. ->orderBy(new Expression('CONVERT(ROOM_NAME USING GBK)'))
  138. ->all();
  139. return $this->render('room', [
  140. 'hotelId' => $hotelId,
  141. 'getHotrlId' => $getHotrlId,
  142. 'room_id' => $room_id,
  143. 'list' => $list,
  144. 'room_waiting_list' => $room_waiting_list
  145. ]);
  146. // include (__DIR__) . '/../views/set/room.phtml';
  147. // return '';
  148. }
  149. /**
  150. * Des:更新酒店数据
  151. * Name: actionUpJd
  152. * @return string
  153. * @author 倪宗锋
  154. */
  155. public function actionUpHotel()
  156. {
  157. $upRes = $this->service()->upJD();
  158. return json_encode($upRes);
  159. }
  160. /**
  161. * Des:更新房间数据
  162. * Name: actionUpRoom
  163. * @return string
  164. * @author 倪宗锋
  165. */
  166. public function actionUpRoom()
  167. {
  168. $params = [
  169. 'channelHotelId' => \Yii::$app->request->post('channelHotelId', '2652602'),//渠道酒店ID
  170. 'channelId' => \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']),//渠道ID
  171. ];
  172. $upRes = $this->service()->upRoom($params);
  173. return json_encode($upRes);
  174. }
  175. /**
  176. * Des:关联酒店
  177. * Name: actionMappingJd
  178. * @return string
  179. * @author 倪宗锋
  180. */
  181. public function actionMappingHotel()
  182. {
  183. $params = [
  184. 'channelHotelId' => \Yii::$app->request->post('channelHotelId', ''),//渠道酒店ID
  185. 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
  186. 'hotelId' => \Yii::$app->request->post('hotelId', ''),//酒店ID
  187. ];
  188. $mappingDes = $this->service()->mappingJd($params);
  189. return json_encode($mappingDes);
  190. }
  191. /**
  192. * Des:解绑酒店
  193. * Name: unMappingHotel
  194. * @param $setType integer -3:仅取消 -4:取消且删除价格
  195. * @return string
  196. * @author 倪宗锋
  197. */
  198. public function actionUnMappingHotel($setType = RoomRelation::MAPPING_SET_TYPE_DELETE_HOTEL)
  199. {
  200. $params = [
  201. 'channelHotelId' => \Yii::$app->request->post('channelHotelId', ''),//渠道房型ID
  202. 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
  203. ];
  204. $mappingDes = $this->service()->unMappingHotel($params, $setType);
  205. return json_encode($mappingDes);
  206. }
  207. /**
  208. * Des:关联房型
  209. * Name: actionMappingRoom
  210. * @param $setType integer
  211. * @return string
  212. * @author 倪宗锋
  213. */
  214. public function actionMappingRoom($setType = RoomRelation::MAPPING_SET_TYPE_NEW)
  215. {
  216. $params = [
  217. 'channelRoomId' => \Yii::$app->request->post('channelRoomId', ''),//渠道房型ID
  218. 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
  219. 'roomId' => \Yii::$app->request->post('roomId', ''),//房型ID
  220. ];
  221. $mappingDes = $this->service()->mappingRoom($params, $setType);
  222. return json_encode($mappingDes);
  223. }
  224. /**
  225. * Des:解除关联操作
  226. * Name: actionUnMappingRoom
  227. * @param $setType integer
  228. * @return string
  229. * @author 倪宗锋
  230. */
  231. public function actionUnMappingRoom($setType = RoomRelation::MAPPING_SET_TYPE_DELETE_ROOM)
  232. {
  233. $params = [
  234. 'channelRoomId' => \Yii::$app->request->post('channelRoomId', ''),//渠道房型ID
  235. 'channelId' => \Yii::$app->request->post('channelId', ''),//渠道ID
  236. 'roomId' => \Yii::$app->request->post('roomId', ''),//房型ID
  237. ];
  238. $mappingDes = $this->service()->unMappingRoom($params, $setType);
  239. return json_encode($mappingDes);
  240. }
  241. /**
  242. * Des:校验mapping信息
  243. * Name: actionCheckMapping
  244. * @return array
  245. * @author 倪宗锋
  246. */
  247. public function actionCheckMapping()
  248. {
  249. $checkMapping = $this->service()->checkMapping();
  250. return json_encode($checkMapping);
  251. }
  252. /**
  253. * Des:推送订单状态
  254. * Name: actionSetOrderStatus
  255. * @return string
  256. * @author 倪宗锋
  257. */
  258. public function actionSetOrderStatus()
  259. {
  260. $params = [
  261. 'OrderID' => \Yii::$app->request->post('OrderID', ''),//订单ID
  262. 'InterfaceConfirmNo' => \Yii::$app->request->post('InterfaceConfirmNo', ''),//酒店确认号
  263. 'OrderStatus' => \Yii::$app->request->post('OrderStatus', ''),//订单状态 3:确认;4:拒绝
  264. 'InterFaceSendID' => \Yii::$app->request->post('InterFaceSendID', ''),//订单接口发送号
  265. 'ResultCode' => \Yii::$app->request->post('ResultCode', ''),
  266. 'Message' => \Yii::$app->request->post('Message', ''),
  267. 'channelId' => \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']),
  268. ];
  269. /*$params = [
  270. 'OrderID' => '4710796222',//订单ID
  271. 'InterfaceConfirmNo' => '3387620972,3389705049,3387086919',//酒店确认号
  272. 'OrderStatus' => '3',//订单状态 3:确认;4:拒绝
  273. 'InterFaceSendID' => 145441316,//订单接口发送号
  274. 'channelId' => '669',//渠道ID
  275. ];*/
  276. $order_id = \Yii::$app->request->post('OrderID', '');
  277. $b = \Yii::$app->request->post('InterfaceConfirmNo', '');
  278. $OrderStatus = \Yii::$app->request->post('OrderStatus', '');
  279. $InterFaceSendID = \Yii::$app->request->post('InterFaceSendID', '');
  280. $channelId = \Yii::$app->request->post('channelId', \Yii::$app->params['ctrip']['relation_supplier_id']);
  281. if ($channelId != 669) {
  282. $arr = array(
  283. "agentid" => 1000002,
  284. "title" => '客服接单',
  285. "msg" => $order_id . '-' . $b . '-' . $OrderStatus . '-' . $InterFaceSendID . '-' . $channelId,
  286. "touser" => 'shifp|wanglg',
  287. );
  288. zOfficeWechat::sendMsg($arr);
  289. }
  290. $setDes = $this->service()->setOrderStatus($params);
  291. if ($setDes['flag'] == false) {
  292. $return = ['code' => 1, 'info' => $setDes['msg']];
  293. } else {
  294. $return = ['code' => 0, 'info' => 'success'];
  295. }
  296. return json_encode($return);
  297. }
  298. /**
  299. * User:Steven
  300. * Desc:
  301. * @param $url
  302. * @param array $param
  303. * @return array|mixed
  304. */
  305. function httpsPostParam($url, $param = array())
  306. {
  307. $ch = curl_init(); // 初始化一个 cURL 对象
  308. curl_setopt($ch, CURLOPT_URL, $url); // 设置需要抓取的URL
  309. curl_setopt($ch, CURLOPT_HEADER, 0); // // 设置header
  310. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
  311. // 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
  312. curl_setopt($ch, CURLOPT_POST, 1);
  313. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param)); // 传递一个作为HTTP “POST”操作的所有数据的字符串。//http_build_query:生成 URL-encode 之后的请求字符串
  314. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  315. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  316. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  317. 'Content-type:application/x-www-form-urlencoded;charset=utf-8'
  318. ));
  319. $rtn = curl_exec($ch); // 运行cURL,请求网页
  320. if ($errno = curl_errno($ch)) {
  321. return array('code' => '1', 'info' => '接口调用失败!');
  322. }
  323. curl_close($ch); // 关闭URL请求
  324. return json_decode($rtn, true); // 返回获取的数据
  325. // return array('code'=> '0','info'=> '对接成功');
  326. }
  327. /**
  328. * User:Steven
  329. * Desc:手动推送订单状态
  330. */
  331. public function actionPushCtripStatus()
  332. {
  333. $a = array(1842200);
  334. foreach ($a as $v) {
  335. $order_id = $v;
  336. $rs = OrderMain::find()->select(['OUTSIDE_ORDER_NO', 'ORDER_CONFIRM_CODE'])->where(['PARENT_ORDER_ID' => 0, 'ORDER_ID' => $order_id])->asArray()->one();
  337. $ctrip_order_id = $rs['OUTSIDE_ORDER_NO'];
  338. $ORDER_CONFIRM_CODE = $rs['ORDER_CONFIRM_CODE'];
  339. $res = OrderChannelInfo::find()->select(['InterFaceSendID'])->where(['ORDER_ID' => $order_id, 'CANCEL_FLAG' => 0])->asArray()->one();
  340. $InterfaceConfirmNo = $res['InterFaceSendID'];
  341. $param = array(
  342. 'OrderID' => $ctrip_order_id,
  343. 'InterfaceConfirmNo' => $ORDER_CONFIRM_CODE,
  344. 'OrderStatus' => CtripOrder::ORDER_STATUS_REFUSED,
  345. 'InterFaceSendID' => $InterfaceConfirmNo,
  346. 'ResultCode' => CtripOrder::RETURN_CODE_STOCK_FAIL,
  347. 'Message' => CtripOrder::RETURN_MSG[CtripOrder::RETURN_CODE_STOCK_FAIL],
  348. 'channelId' => \Yii::$app->params['ctrip']['relation_supplier_id'] //携程
  349. );
  350. $set = new SetService();
  351. $setDes = $set->setOrderStatus($param);
  352. }
  353. }
  354. }