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.

HotelController.php 7.2 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /**
  3. * 酒店下单流程
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zhizhuchuxing.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 倪宗锋
  12. * PhpStorm HotelController.php
  13. * Create By 2018/1/5 9:17 $
  14. */
  15. namespace zzcx\controllers\home;
  16. use common\models\MBaseUnique;
  17. use common\util\OrderUtil;
  18. use common\util\Util;
  19. use yii\web\Controller;
  20. use zzcx\service\home\Hotel;
  21. use common\models\MHotel;
  22. use common\util\CurlInterface;
  23. use zzcx\service\order\Order;
  24. use Yii;
  25. class HotelController extends Controller
  26. {
  27. private $service = null;//逻辑处理类
  28. private function service()
  29. {
  30. if ($this->service == null) {
  31. $this->service = new Hotel();
  32. }
  33. return $this->service;
  34. }
  35. /**
  36. * Des:获取酒店信息
  37. * Name: actionGetInfo
  38. * @return string
  39. * @author 倪宗锋
  40. */
  41. public function actionGetInfo()
  42. {
  43. $params = [
  44. 'hotel_id' => $this->_post('hotel_id', ''),//酒店ID 必传
  45. 'start_date' => $this->_post('start_date', ''),//入住时间 必传
  46. 'end_date' => $this->_post('end_date', ''),//离店时间 必传
  47. ];
  48. $getInfo = $this->service()->getInfo($params);
  49. return json_encode($getInfo);
  50. }
  51. /**
  52. * Des:获取房型列表
  53. * Name: actionGetRoomList
  54. * @return string
  55. * @author 倪宗锋
  56. */
  57. public function actionGetRoomList()
  58. {
  59. $params = [
  60. 'hotel_id' => $this->_post('hotel_id', ''),//酒店ID 必传
  61. 'start_date' => $this->_post('start_date', ''),//入住时间 必传
  62. 'end_date' => $this->_post('end_date', ''),//离店时间 必传
  63. 'room_id' => $this->_post('room_id', '')//房型ID 非必传
  64. ];
  65. $result = $this->service()->getRoomList($params);
  66. return Util::returnJsSu('', $result);
  67. }
  68. /**
  69. * Des:酒店下单接口
  70. * Name: actionMakeOrder
  71. * @return string
  72. * @author 倪宗锋
  73. */
  74. public function actionMakeOrder()
  75. {
  76. $result = $this->service()->makeOrder();
  77. return json_encode($result);
  78. }
  79. /**
  80. * Function Description:获取酒店列表
  81. * Function Name: actionGetHotelList
  82. *
  83. * @return string
  84. *
  85. * @author 娄梦宁
  86. */
  87. public function actionGetHotelList()
  88. {
  89. $params = [
  90. 'area_id' => $this->_post('area_id', '800'),//地区id
  91. 'start_date' => $this->_post('start_date', '2018-01-20'),//入住时间 必传
  92. 'end_date' => $this->_post('end_date', '2018-01-22'),//离店时间 必传
  93. 'search_more' => $this->_post('search_more', ''),//名称,商圈
  94. 'sort' => Yii::$app->request->post('sort', '-1'),//排序规则 -1:综合排序,0价格高到低,1:价格低到高
  95. 'breakfast_include' => $this->_post('breakfast_include', '0'),//早餐标识
  96. 'hotel_label' => $this->_post('hotel_label', ''),//设施服务
  97. 'star_type' => $this->_post('star_type', '0'),//星级及类型
  98. 'price_type' => $this->_post('price_type', '0'),//价格区间
  99. 'bed_type' => $this->_post('bed_type', '0'),//床型
  100. 'brand' => $this->_post('brand', '0'),//品牌
  101. 'current_page' => $this->_post('current_page', 1),
  102. 'page_size' => $this->_post('page_size', 10),
  103. ];
  104. $result = $this->service()->getHotelList($params);
  105. return json_encode($result);
  106. }
  107. /**
  108. * Function Description:获取酒店列表缓存
  109. * Function Name: actionCacheHotel
  110. *
  111. *
  112. * @author 娄梦宁
  113. */
  114. public function actionCacheHotel()
  115. {
  116. $curlInterface = new CurlInterface();
  117. $siteConfig = Util::getSiteConfig();
  118. $url = $siteConfig['adm_host1'] . '/hotel/api/get-hotel-list-cache';
  119. $result = $curlInterface->execute($url);
  120. if ($result['code'] == 0) {
  121. $mHotel = new MHotel();
  122. $mBaseUnique = new MBaseUnique();
  123. $new_time_stamp = $result['data'][0]['time_stamp'];
  124. $collection = $mHotel->getCollection();
  125. foreach ($result['data'] as $val) {
  126. $collection->insert($val);
  127. }
  128. $mBaseUnique::updateAll(['time_stamp' => $new_time_stamp], ['type' => 1]);
  129. $mHotel->deleteAll(['!=', 'time_stamp', $new_time_stamp]);
  130. }
  131. }
  132. /**
  133. * Function Description:获取酒店筛选条件
  134. * Function Name: actionGetHotelType
  135. *
  136. * @return string
  137. *
  138. * @author 李健
  139. */
  140. public function actionGetHotelType()
  141. {
  142. $result = $this->service()->getHotelType();
  143. return json_encode($result);
  144. }
  145. /**
  146. * Des:下单页可定检查
  147. * Name: actionCheckHotel
  148. * @return string
  149. * @author 倪宗锋
  150. */
  151. public function actionCheckHotel()
  152. {
  153. $params = [
  154. 'total_details' => $this->_post('total_details', ''),//每日单价
  155. 'hotel_id' => $this->_post('hotel_id', ''),//酒店ID 必传
  156. 'start_date' => $this->_post('start_date', ''),//入住时间 必传
  157. 'end_date' => $this->_post('end_date', ''),//离店时间 必传
  158. 'room_id' => $this->_post('room_id', ''),//房型ID 必传
  159. 'prod_cnt' => $this->_post('prod_cnt', ''),//房间数量 必传
  160. ];
  161. $result = OrderUtil::checkHotel($params);
  162. return json_encode($result);
  163. }
  164. /**
  165. * Function Description:获取酒店所在城市
  166. * Function Name: actionGetHotelArea
  167. * @return bool|string
  168. * @author 田玲菲
  169. */
  170. public function actionGetHotelArea()
  171. {
  172. $result = $this->service()->getHotelArea();
  173. return json_encode($result);
  174. }
  175. /**
  176. * Des:返回微信官网接口
  177. * Name: actionGetWwwHotelList
  178. * @return string
  179. * @author 倪宗锋
  180. */
  181. public function actionGetWwwHotelList()
  182. {
  183. //先从缓存中获取数据不存在则 从cs接口获取
  184. $cache = Yii::$app->cache;
  185. $key = 'WWW_HOTEL_LIST' . YII_ENV;
  186. $list = $cache->get($key);
  187. if (empty($list)) {
  188. //调用cs接口获取列表
  189. $result = Util::sendCs([], '/hotel/api/get-www-hotel-list', 2);
  190. $list = $result['data'];
  191. if (empty($list[0]['hotel_id'])) {
  192. return json_encode([]);
  193. }
  194. foreach ($list as &$hotel) {
  195. $hotel['category_id'] = '3';
  196. $hotel['pro_cate_id'] = $hotel['hotel_id'];
  197. $hotel['pro_cate_name'] = $hotel['hotel_name'];
  198. $hotel['show_price'] = $hotel['min_price'];
  199. unset($hotel['hotel_id']);
  200. unset($hotel['hotel_name']);
  201. unset($hotel['min_price']);
  202. }
  203. //保存到memcache中
  204. $cache->set($key, $list, 3600);//缓存10分钟
  205. }
  206. return json_encode($list);
  207. }
  208. }