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.
 
 
 
 
 
 

707 lines
28 KiB

  1. <?php
  2. namespace backend\modules\hotel\controllers;
  3. use backend\common\Utils;
  4. use backend\modules\hotel\models\ChannelRoom;
  5. use backend\modules\hotel\models\CtripHotelPrice;
  6. use backend\modules\hotel\models\HotelPriceConversion;
  7. use backend\modules\hotel\models\OperaHotel;
  8. use backend\modules\hotel\models\OperaHotelBaseRoom;
  9. use backend\modules\hotel\models\OperaHotelRoom;
  10. use backend\modules\hotel\models\PriceComparedRoom;
  11. use backend\modules\hotel\models\RoomRelation;
  12. use backend\modules\hotel\models\SyncPriceComparedHotel;
  13. use Yii;
  14. use yii\db\Exception;
  15. use yii\web\Controller;
  16. use common\components\zOfficeWechat;
  17. use common\models\Msg;
  18. use backend\modules\hotel\models\PriceComparedHotel;
  19. class ComparePriceController extends Controller
  20. {
  21. public $layout = "@backend/modules/motorcade/views/layouts/iframe_new";
  22. public $enableCsrfValidation = false;
  23. /**
  24. * User:Steven
  25. * Desc:比价酒店列表
  26. * @return string
  27. */
  28. public function actionIndex()
  29. {
  30. $comparePrice = new HotelPriceConversion();
  31. $ctripHotel = new PriceComparedHotel();
  32. $filter = ['hotel_name' => '', 'cancel_flag' => '', 'channel_id' => '', 'channel' => ''];
  33. // $request = Yii::$app->request;
  34. if (Yii::$app->request->isAjax) {
  35. $filter = Yii::$app->request->get('filter');
  36. }
  37. $dataProvider = $ctripHotel->index($filter);
  38. return $this->render('base', ['view' => 'index', 'data' => ['model' => $ctripHotel, 'comparePrice' => $comparePrice], 'dataProvider' => $dataProvider]);
  39. }
  40. /**
  41. * User:Steven
  42. * Desc:酒店比价
  43. * @return string
  44. */
  45. public function actionComparePrice()
  46. {
  47. $ctripHotelPrice = new CtripHotelPrice();
  48. $hotel_list = $ctripHotelPrice->getDirectHotel();
  49. if (Yii::$app->request->isPost || Yii::$app->request->isGet) {
  50. $HOTEL_ID = is_null(Yii::$app->request->post('HOTEL_ID')) ? Yii::$app->request->get('HOTEL_ID') : Yii::$app->request->post('HOTEL_ID');
  51. }
  52. is_null($HOTEL_ID) ? $HOTEL_ID = $hotel_list[0]['HOTEL_ID'] : $HOTEL_ID;
  53. $ctrip_data = $ctripHotelPrice->getCtripData($HOTEL_ID);
  54. $data = array(
  55. 'ctrip_data' => [],
  56. 'update_time' => ''
  57. );
  58. if (!empty($ctrip_data)) {
  59. $data['hotel_info'] = array(
  60. 'ctrip_hotel_id' => $ctrip_data[0]['ctrip_hotel_id'],
  61. 'hotel_name' => $ctrip_data[0]['hotel_name'],
  62. 'spider_hotel_id' => $HOTEL_ID,
  63. );
  64. $last_up_time = $ctripHotelPrice->getHotelLastUpTime($HOTEL_ID);
  65. // $price_conversion = $ctripHotelPrice->getHotelConversion($HOTEL_ID);
  66. $res = $this->ctripDataService($ctrip_data, $HOTEL_ID);
  67. foreach ($res[$HOTEL_ID] as $key => $item) {
  68. if (empty($item)) {
  69. unset($res[$HOTEL_ID][$key]);
  70. }
  71. }
  72. }
  73. $data['hotel_list'] = $hotel_list;
  74. $data['ctrip_data'] = $res;
  75. $data['update_time'] = $last_up_time['max_create_time'];
  76. // $data['update_time'] = '2017-08-31 00:00:00';
  77. return $this->render('base', ['view' => 'priceCompared', 'data' => $data]);
  78. }
  79. /**
  80. * User:Steven
  81. * Desc:酒店-房型比价列表
  82. * @return string
  83. */
  84. public function actionRoomCompared()
  85. {
  86. $hotel_id = Yii::$app->request->get('hotel_id');
  87. $channel_id = Yii::$app->request->get('channel_id');
  88. if (!isset($hotel_id) || !isset($channel_id)) {
  89. return false;
  90. }
  91. $filter = ['hotel_id' => $hotel_id, 'cancel_flag' => '', 'channel_id' => '', 'channel' => $channel_id];
  92. if (Yii::$app->request->isAjax) {
  93. $filter = Yii::$app->request->get('filter');
  94. $filter['hotel_id'] = $hotel_id;
  95. }
  96. $ctripHotel = new PriceComparedRoom();
  97. $dataProvider = $ctripHotel->getComparedRoom($filter);
  98. // $data['update_time'] = '2017-08-31 00:00:00';
  99. return $this->render('base', ['view' => 'room_compared_list', 'data' => ['model' => $ctripHotel, 'channel_id' => $channel_id, 'hotel_id' => $hotel_id,], 'dataProvider' => $dataProvider]);
  100. }
  101. /**
  102. * User:Steven
  103. * Desc:比价酒店数据总览页面
  104. */
  105. public function actionOverview()
  106. {
  107. $ctripHotel = new PriceComparedHotel();
  108. $param = Yii::$app->request->get();
  109. $channel_id = isset($param['channel_id']) ? $param['channel_id'] : Yii::$app->params['ctrip']['relation_supplier_id'];
  110. $hotel_name = isset($param['hotel_name']) ? $param['hotel_name'] : '';
  111. $hotel_pricipal = isset($param['hotel_pricipal']) ? $param['hotel_pricipal'] : -1;
  112. $dataProvider = $ctripHotel->getHotelOverview($channel_id, $hotel_name, $hotel_pricipal);
  113. $ctrip_hotel_price = new CtripHotelPrice();
  114. $last_up_time = $ctrip_hotel_price->getHotelLastUpTime();
  115. return $this->render('base', ['view' => 'overview', 'data' => ['dataProvider' => $dataProvider, 'last_up_time' => $last_up_time]]);
  116. }
  117. /**
  118. * User:Steven
  119. * Desc:设置比价酒店的价差
  120. * @return \yii\web\Response
  121. */
  122. public function actionSetPriceConversion()
  123. {
  124. if (Yii::$app->request->isPost) {
  125. $post = Yii::$app->request->post();
  126. $comparePrice = empty(HotelPriceConversion::findOne($post['HotelPriceConversion']['hotel_id'])) ? new HotelPriceConversion() : HotelPriceConversion::findOne($post['HotelPriceConversion']['hotel_id']);
  127. if ($comparePrice->load($post) && $comparePrice->validate()) {
  128. if ($comparePrice->save()) {
  129. Yii::$app->session->setFlash('success', "添加成功");
  130. return $this->redirect(array('compare-price/index'));
  131. } else {
  132. Yii::$app->session->setFlash('success', "添加失败");
  133. }
  134. }
  135. }
  136. }
  137. /**
  138. * @author wanglg
  139. * 修改酒店比价状态
  140. */
  141. public function actionModifyStatus()
  142. {
  143. $post = Yii::$app->request->post();
  144. if (!(isset($post['id']) && isset($post['op']))) {
  145. $data['code'] = 2;
  146. }
  147. if ($post['field'] == 'cancel_flag') {
  148. $transform = Yii::$app->db->beginTransaction();
  149. try {
  150. $pch = PriceComparedHotel::findOne($post['id']);
  151. $update['cancel_flag'] = $post['op'] == 'set' ? 0 : 1;
  152. if ($pch->load($update, '') && $pch->validate()) {
  153. if (!$pch->save()) {
  154. throw new \Exception();
  155. }
  156. }
  157. // $hotel_id = $pch -> HotelId;
  158. $ChannelHotelId = $pch->ChannelHotelId;
  159. $sync_hotel = SyncPriceComparedHotel::findOne(['ChannelHotelId' => $ChannelHotelId]);
  160. $new_update = $post['op'] == 'set' ? 0 : 1;
  161. $sync_hotel->CancelFlag = $new_update;
  162. if (!$sync_hotel->update()) {
  163. throw new \Exception();
  164. }
  165. $transform->commit();
  166. $data = 0;
  167. } catch (\Exception $e) {
  168. $transform->rollBack();
  169. $data['code'] = 1;
  170. }
  171. echo json_encode($data);
  172. }
  173. if ($post['field'] == 'send_msg') {
  174. $pch = PriceComparedHotel::findOne($post['id']);
  175. $update['SendMsg'] = $post['op'] == 'set' ? 1 : 0;
  176. $pch->SendMsg = $update['SendMsg'];
  177. if ($pch->update()) {
  178. $data = 0;
  179. } else {
  180. $data = 1;
  181. }
  182. echo json_encode($data);
  183. }
  184. }
  185. /**
  186. * @Author wanglg
  187. * @Desc 修改房型比价状态
  188. */
  189. public function actionRoomStatus()
  190. {
  191. $post = Yii::$app->request->post();
  192. if (!(isset($post['id']) && isset($post['op']))) {
  193. $data['code'] = 2;
  194. }
  195. $pcr = PriceComparedRoom::findOne(['ID' => $post['id']]);
  196. $update['cancel_flag'] = $post['op'] == 'set' ? 0 : 1;
  197. if ($pcr->load($update, '') && $pcr->validate()) {
  198. if (!$pcr->save()) {
  199. $data['code'] = 1;
  200. } else {
  201. $data = 0;
  202. }
  203. }
  204. echo json_encode($data);
  205. }
  206. /**
  207. * 添加比价酒店
  208. */
  209. public function actionAddComparedHotel()
  210. {
  211. $model = new PriceComparedHotel();
  212. $sync_model = new SyncPriceComparedHotel();
  213. $transaction = Yii::$app->db->beginTransaction();
  214. $request = Yii::$app->request->post();
  215. try {
  216. if ($model->load($request) && $model->validate()) {
  217. if (!$model->save()) {
  218. throw new \Exception();
  219. }
  220. } else {
  221. throw new \Exception();
  222. }
  223. $new_request = array('ChannelHotelId' => $request['PriceComparedHotel']['ChannelHotelId'], 'HotelId' => $request['PriceComparedHotel']['HotelId'], 'ChannelId' => $request['PriceComparedHotel']['ChannelId'],);
  224. if ($sync_model->load($new_request, '') && $sync_model->validate()) {
  225. if (!$sync_model->save()) {
  226. throw new \Exception();
  227. }
  228. } else {
  229. throw new \Exception();
  230. }
  231. $transaction->commit();
  232. Yii::$app->session->setFlash('success', "添加比价酒店成功!");
  233. // return '<script>z.pjaxFinish("success", "修改成功", "#float-div");$("#search-btn").trigger(\'click\');</script>';
  234. // echo '<script type="text/javascript">easyAlert("添加比价酒店成功!", "success");</script>';
  235. } catch (\Exception $e) {
  236. $transaction->rollBack();
  237. Yii::$app->session->setFlash('error', "添加比价酒店失败!");
  238. $hotel_list = $model->getHotelList();
  239. return $this->renderPartial('base', ['view' => '_addHotel', 'data' => ['hotel_list' => $hotel_list, 'model' => $model]]);
  240. }
  241. return $this->redirect('/hotel/compare-price/index');
  242. }
  243. /**
  244. * @author wanglg
  245. * 添加比价房型
  246. */
  247. public function actionAddComparedRoom()
  248. {
  249. $model = new PriceComparedRoom();
  250. $request = Yii::$app->request->post();
  251. if ($model->load($request) && $model->validate()) {
  252. if (!$model->save()) {
  253. Yii::$app->session->setFlash('error', "添加比价房型失败!");
  254. } else {
  255. // return '<script>z.pjaxFinish("success", "添加比价房型成功", "#float-div")</script>';
  256. Yii::$app->session->setFlash('success', "添加比价房型成功!");
  257. }
  258. } else {
  259. $room = new OperaHotelRoom();
  260. $base_room = new OperaHotelBaseRoom();
  261. $base_list = $base_room->getHotelBaseRoom($request['PriceComparedRoom']['hotel_id']);
  262. $base_room_id = isset($base_room_id) ? $base_room_id : $base_list[0]->MAIN_ID;
  263. $room_list = $room->getAllRoom($request['PriceComparedRoom']['hotel_id'], $base_room_id);
  264. return $this->renderPartial('_form', ['data' => ['model' => $model, 'room_list' => $room_list, 'base_room' => $base_room, 'hotel_id' => $request['PriceComparedRoom']['hotel_id'], 'base_list' => $base_list]]);
  265. }
  266. return $this->redirect('/hotel/compare-price/room-compared?hotel_id=' . $request['PriceComparedRoom']['hotel_id'] . '&channel_id=' . $request['PriceComparedRoom']['channel_id']);
  267. }
  268. /**
  269. * @author wanglg
  270. * 修改比价房型信息
  271. * @return \yii\web\Response
  272. */
  273. public function actionUpdateComparedRoom()
  274. {
  275. $request = Yii::$app->request->post();
  276. $model = PriceComparedRoom::findOne($request['PriceComparedRoom']['ID']);
  277. if ($model->load($request) && $model->validate()) {
  278. if (!$model->save()) {
  279. Yii::$app->session->setFlash('error', "修改比价房型失败!");
  280. } else {
  281. Yii::$app->session->setFlash('success', "修改比价房型成功!");
  282. }
  283. }
  284. return $this->redirect('/hotel/compare-price/room-compared?hotel_id=' . $request['PriceComparedRoom']['hotel_id'] . '&channel_id=' . $request['PriceComparedRoom']['channel_id']);
  285. }
  286. /**
  287. * @author wanglg
  288. * @return string
  289. */
  290. public function actionAddComparedHotelView()
  291. {
  292. // 不需要参数,直接查询所有未添加的酒店
  293. $model = new PriceComparedHotel();
  294. $hotel_list = $model->getHotelList();
  295. return $this->renderPartial('base', ['view' => '_addHotel', 'data' => ['hotel_list' => $hotel_list, 'model' => $model]]);
  296. }
  297. /**
  298. * @author wanglg
  299. * 添加比价房型弹框显示
  300. */
  301. public function actionAddComparedRoomView()
  302. {
  303. $model = new PriceComparedRoom();
  304. $hotel_id = Yii::$app->request->get('hotel_id');
  305. $base_room = new OperaHotelBaseRoom();
  306. $base_list = $base_room->getHotelBaseRoom($hotel_id);
  307. $room = new OperaHotelRoom();
  308. if (!isset($hotel_id)) {
  309. if (Yii::$app->request->isPjax && Yii::$app->request->post('base_room_id')) {
  310. $base_room_id = Yii::$app->request->post('base_room_id');
  311. $hotel_id = Yii::$app->request->post('hotel_id');
  312. }
  313. }
  314. $base_room_id = isset($base_room_id) ? $base_room_id : $base_list[0]->MAIN_ID;
  315. $room_list = $room->getAllRoom($hotel_id, $base_room_id);
  316. return $this->renderPartial('_form', ['data' => ['action' => 'add', 'model' => $model, 'room_list' => $room_list, 'base_room' => $base_room, 'hotel_id' => $hotel_id, 'base_list' => $base_list]]);
  317. }
  318. /**
  319. * @author wanglg
  320. * @return bool|string
  321. */
  322. public function actionUpdateComparedRoomView()
  323. {
  324. $id = Yii::$app->request->get('id');
  325. $hotel_id = Yii::$app->request->get('hotel_id');
  326. if (empty($hotel_id) || empty($id)) {
  327. return false;
  328. }
  329. $model = PriceComparedRoom::findOne($id);
  330. // 根据子房型查询基础房型id
  331. $parent_room = OperaHotelRoom::findOne($model->room_id);
  332. //根据基础房型id查询该基础房型id
  333. $parent_room_id = OperaHotelBaseRoom::findOne($parent_room->PARENT_ROOM_TYPE);
  334. $base_room = new OperaHotelBaseRoom();
  335. $base_list = $base_room->getHotelBaseRoom($hotel_id);
  336. if (!isset($hotel_id)) {
  337. if (Yii::$app->request->isPjax && Yii::$app->request->post('base_room_id')) {
  338. $base_room_id = Yii::$app->request->post('base_room_id');
  339. $hotel_id = Yii::$app->request->post('hotel_id');
  340. }
  341. }
  342. $room = new OperaHotelRoom();
  343. $base_room_id = isset($base_room_id) ? $base_room_id : $parent_room->PARENT_ROOM_TYPE;
  344. $room_list = $room->getAllRoom($hotel_id, $base_room_id);
  345. return $this->renderPartial('_form', ['data' => ['action' => 'update', 'model' => $model, 'room_list' => $room_list, 'base_room' => $parent_room_id, 'hotel_id' => $hotel_id, 'base_list' => $base_list]]);
  346. }
  347. /**
  348. * User:Steven
  349. * Desc:获取代理IP 快代理
  350. * @return bool
  351. */
  352. public function actionGetProxys()
  353. {
  354. //获取目前可用的IP个数
  355. $max_count = 300; //限制数据库
  356. $model = new CtripHotelPrice();
  357. $count = $model->getAbleProxyCount();
  358. if ($count[0]['count'] >= $max_count) {
  359. return false;
  360. }
  361. $i = 0;
  362. $url = "http://ent.kuaidaili.com/api/getproxy/?orderid=990424805960893&num=300&b_pcchrome=1&b_pcie=1&b_pcff=1&protocol=1&method=1&an_an=1&an_ha=1&sp1=1&quality=2&format=json&sep=1";
  363. $res = Utils::http_get($url);
  364. $res = json_decode($res['content'], true);
  365. if ($res['code'] == 0) {
  366. foreach ($res['data']['proxy_list'] as $item) {
  367. if ($i >= ($max_count - $count[0]['count'])) {
  368. return false;
  369. }
  370. //这里验证代理IP的有效性
  371. $code = $this->GetHttpStatusCode($item);
  372. if ($code == 200) {
  373. $i++;
  374. $model->addProxyIp($item);
  375. }
  376. }
  377. }
  378. }
  379. /**
  380. * User:Steven
  381. * Desc:定时统计房型未展示、价格有劣势的酒店房型统计数据,并通知到酒店运营
  382. */
  383. public function actionCronPriceWarning()
  384. {
  385. $ctripHotelPrice = new CtripHotelPrice();
  386. $res = $ctripHotelPrice->getDirectHotel();
  387. foreach ($res as $item) {
  388. $ctrip_data = $ctripHotelPrice->getCtripData($item['HOTEL_ID']);
  389. if (empty($ctrip_data)) {
  390. continue;
  391. }
  392. // $price_conversion = $ctripHotelPrice->getHotelConversion($item['HOTEL_ID']);
  393. $rs = $this->ctripDataService($ctrip_data, $item['HOTEL_ID']); //这里返回的数据是:1、价格有劣势的 2:价格未显示的
  394. foreach ($rs as $key => $value) {
  395. $room_analysis = '';
  396. $flag = false;
  397. foreach ($value as $k => $v) { // $k
  398. if (empty($v)) {
  399. continue;
  400. }
  401. $inferiority = 0;//劣势房型
  402. $no_show = 0;//未展示房型
  403. foreach ($v as $k1 => $v1) {
  404. if (!is_null($v1['a_price']) && !is_null($v1['b_price'])) { //劣势
  405. $flag = true;
  406. $inferiority++;
  407. } elseif (!is_null($v1['a_price']) && is_null($v1['b_price'])) {
  408. $flag = true;
  409. $no_show++;
  410. }
  411. }
  412. if ($inferiority != 0 || $no_show != 0) {
  413. $str = str_replace(array("\r\n", "\r", " ", "\n"), "", $k);
  414. $room_analysis .= '● ' . preg_replace('/^([^\d]+).*/', '$1', $str) . ': 价格劣势天数:' . $inferiority . '; 未露出天数:' . $no_show . "\n";
  415. }
  416. }
  417. }
  418. if ($flag) {
  419. $url = "http://cs1.zhizhuchuxing.com/hotel/compare-price/compare-price?HOTEL_ID=" . $item['HOTEL_ID'];
  420. $msg = '【' . $item['HOTEL_NAME'] . '】' . '\n' . $room_analysis . '复制在浏览器中打开:' . Msg::sinaShortenUrl($url);
  421. //TODO:给运营发送消息通知
  422. if ($item['SendMsg'] == 1) {
  423. $arr = array("agentid" => 1000002,
  424. "title" => 'Ctrip渠道比价结果预警:',
  425. "msg" => $msg,
  426. "touser" => $item['user_name']);
  427. // "touser" => 'shifp');
  428. zOfficeWechat::sendMsg($arr);
  429. }
  430. }
  431. }
  432. }
  433. /**
  434. * User:Steven
  435. * Desc:提取字符串中的数字
  436. * @param $string
  437. * @return bool|string
  438. */
  439. function findNumber($string)
  440. {
  441. if (!is_string($string) || empty($string)) {
  442. return '';
  443. }
  444. for ($i = 0; $i < strlen($string); $i++) {
  445. $char = substr($string, $i, 1);
  446. if (ctype_digit($char)) {
  447. return substr($string, 0, $i);
  448. }
  449. }
  450. return '';
  451. }
  452. /**
  453. * Author:Steven
  454. * Desc:比价数据处理
  455. * @param $ctrip_data
  456. * @param $price_conversion
  457. * @param $flag 是否折算价差
  458. * @return array
  459. */
  460. public function ctripDataService($ctrip_data, $HOTEL_ID, $flag = true)
  461. {
  462. //查询当前有直连关系的房型ID
  463. $ctripHotelPrice = new CtripHotelPrice();
  464. $room_arr = $ctripHotelPrice->getRelationRoom($ctrip_data[0]['spider_hotel_id']);
  465. $room_list = [];
  466. foreach ($room_arr as $room) {
  467. $room_list[] = $room['channel_room_id'];
  468. }
  469. //a_表示携程 b_表示蜘蛛
  470. $arr = array();
  471. if ($flag) {
  472. $ctripHotelPrice = new CtripHotelPrice();
  473. $price_conversion = $ctripHotelPrice->getHotelConversion($HOTEL_ID);
  474. $price_conversion = $price_conversion[0];
  475. }
  476. foreach ($ctrip_data as $item) {
  477. $spider_price = $item['b_price'];
  478. $ctrip_price = $item['a_price'];
  479. $origin_spider_price = $item['b_price']; //用于记录没有折算价差的时候的价格
  480. $origin_ctrip_price = $item['a_price'];
  481. if ($flag) {//携程价格折算
  482. $remain_room_conversion = isset($price_conversion['remain_room_conversion']) ? $price_conversion['remain_room_conversion'] : 0;
  483. $breakfast_conversion = isset($price_conversion['breakfast_conversion']) ? $price_conversion['breakfast_conversion'] : 0;
  484. $cancel_rules_conversion = isset($price_conversion['cancel_rules_conversion']) ? $price_conversion['cancel_rules_conversion'] : 0;
  485. $pay_type_conversion = isset($price_conversion['pay_type_conversion']) ? $price_conversion['pay_type_conversion'] : 0;
  486. //早餐(非早餐类型的早餐折算) 以我们的价格为基数,加上或者减去早餐数之差*价差
  487. $ctrip_breakfast = $this->calBreakfastLevel($item['a_breakfast']);
  488. $spider_breakfast = $this->calBreakfastLevel($item['b_breakfast']);
  489. $spider_price = $spider_price - ($spider_breakfast - $ctrip_breakfast) * $breakfast_conversion;
  490. //别墅类型的早餐折算
  491. $ctrip_breakfast1 = $this->calbreakfast1($item['a_breakfast']);
  492. $spider_breakfast2 = $this->calbreakfast1($item['b_breakfast']);
  493. $ctrip_person = $this->number($item['a_room_person']);
  494. $spider_person = $this->number($item['b_room_person']);
  495. $spider_price = $spider_price + ($spider_breakfast2 * $spider_person - $ctrip_breakfast1 * $ctrip_person) * $breakfast_conversion;
  496. //现预付 蜘蛛是预付
  497. if ($item['a_payment_txt'] == '到店付' || $item['a_payment_txt'] == '担保') {//现付
  498. $ctrip_price = $ctrip_price - $pay_type_conversion;
  499. }
  500. //保留房
  501. $item['a_confirm_info'] == '立即确认' ? '' : $ctrip_price = $ctrip_price + $remain_room_conversion;
  502. $item['b_confirm_info'] == '立即确认' ? '' : $spider_price = $spider_price + $remain_room_conversion;
  503. //取消规则
  504. $item['a_room_policy'] == '免费取消' ? '' : $ctrip_price = $ctrip_price + $cancel_rules_conversion;
  505. $item['b_room_policy'] == '免费取消' ? '' : $spider_price = $spider_price + $cancel_rules_conversion;
  506. }
  507. if ($spider_price > $ctrip_price || is_null($item['b_price'])) { //蜘蛛价格为null时,即价格未在携程前台显示
  508. $room_type = preg_replace('/^([^\d]+).*/', '$1', str_replace(array("\r\n", "\r", " ", "\n"), "", $item['room_type']));
  509. $arr[$item['spider_hotel_id']][$room_type][$item['start_date']] = array(
  510. 'a_bed_type' => $item['a_bed_type'],
  511. 'b_bed_type' => $item['b_bed_type'],
  512. 'a_breakfast' => $item['a_breakfast'],
  513. 'b_breakfast' => $item['b_breakfast'],
  514. 'a_room_policy' => $item['a_room_policy'],
  515. 'b_room_policy' => $item['b_room_policy'],
  516. 'a_confirm_info' => $item['a_confirm_info'],
  517. 'b_confirm_info' => $item['b_confirm_info'],
  518. 'a_supply_id' => $item['a_supply_id'],
  519. 'a_showdow_id' => $item['a_showdow_id'],
  520. 'a_payment_txt' => $item['a_payment_txt'],
  521. 'b_payment_txt' => $item['b_payment_txt'],
  522. 'a_room_person' => $item['a_room_person'],
  523. 'b_room_person' => $item['b_room_person'],
  524. 'a_price' => $item['a_price'],
  525. 'b_price' => $item['b_price'],
  526. 'b_son_room_id' => $item['son_room_id'],
  527. 'inferiority' => 2,
  528. );
  529. if (($origin_spider_price < $origin_ctrip_price) && !is_null($item['b_price'])) { //这种属于竞争力不足
  530. $arr[$item['spider_hotel_id']][$room_type][$item['start_date']]['inferiority'] = 3;
  531. }
  532. //判断当前房型是不是直连的房型
  533. if (!in_array($item['son_room_id'], $room_list)) {
  534. unset($arr[$item['spider_hotel_id']][$room_type][$item['start_date']]);
  535. }
  536. }
  537. }
  538. //当某个房型下所有的日期,蜘蛛的数据都是空的,表明我们没有合作此房型
  539. foreach ($arr as $itmem_k => $item) {
  540. foreach ($item as $key => $value) {
  541. $i = 0;
  542. foreach ($value as $k => $v) {
  543. if (is_null($v['b_price'])) {
  544. $i++;
  545. if ($i == count($value)) {
  546. unset($arr[$itmem_k][$key]);
  547. }
  548. }
  549. }
  550. }
  551. }
  552. return $arr;
  553. }
  554. /**
  555. * User:Steven
  556. * Desc:计算早餐级别
  557. * @param $breakfast
  558. * @return int
  559. */
  560. public function calBreakfastLevel($breakfast)
  561. {
  562. switch ($breakfast) {
  563. case '无早':
  564. $breakfast_level = 0;
  565. break;
  566. case '每天单早':
  567. $breakfast_level = 1;
  568. break;
  569. case '每天双早':
  570. $breakfast_level = 2;
  571. break;
  572. case '每天三早':
  573. $breakfast_level = 3;
  574. break;
  575. case '每天四早':
  576. $breakfast_level = 4;
  577. break;
  578. case '每天五早':
  579. $breakfast_level = 5;
  580. break;
  581. case '每天六早':
  582. $breakfast_level = 6;
  583. break;
  584. case '每天七早':
  585. $breakfast_level = 7;
  586. break;
  587. case '每天八早':
  588. $breakfast_level = 8;
  589. break;
  590. case '每天九早':
  591. $breakfast_level = 9;
  592. break;
  593. case '每天十早':
  594. $breakfast_level = 10;
  595. break;
  596. default:
  597. $breakfast_level = 0;
  598. break;
  599. }
  600. return $breakfast_level;
  601. }
  602. /**
  603. * User:Steven
  604. * Desc:对于别墅类型的房,计算早餐个数的时候需要考虑到入住人数
  605. * @param $breakfast
  606. * @return int|string
  607. */
  608. public function calbreakfast1($breakfast)
  609. {
  610. $arr = array(1 => '一', 2 => '二', 3 => '三', 4 => '四', 5 => '五', 6 => '六', 7 => '七', 8 => '八', 9 => '九', 10 => '十', 11 => '十一', 12 => '十二');
  611. foreach ($arr as $k => $v) {
  612. if ($breakfast == '每天每人' . $v . '份早') {
  613. return $k;
  614. } else {
  615. return 0;
  616. }
  617. }
  618. }
  619. /**
  620. * User:Steven
  621. * Desc:获取字符串中的数字部分
  622. * @param $str
  623. * @return mixed
  624. */
  625. public function number($str)
  626. {
  627. return preg_replace('/\D/s', '', $str);
  628. }
  629. public function GetHttpStatusCode($proxy)
  630. {
  631. $curl = curl_init();
  632. curl_setopt($curl, CURLOPT_PROXY, $proxy);//使用代理访问
  633. curl_setopt($curl, CURLOPT_URL, "http://www.baidu.com");//获取内容url
  634. curl_setopt($curl, CURLOPT_HEADER, 1);//获取http头信息
  635. curl_setopt($curl, CURLOPT_NOBODY, 1);//不返回html的body信息
  636. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//返回数据流,不直接输出
  637. curl_setopt($curl, CURLOPT_TIMEOUT, 5); //超时时长,单位秒
  638. curl_exec($curl);
  639. $rtn = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  640. curl_close($curl);
  641. return $rtn;
  642. }
  643. }
  644. ?>