|
- <?php
- /**
- * API接口类 处理逻辑
- * ============================================================================
- * * 版权所有 蜘蛛出行 * *
- * 网站地址: http://www.zhizhuchuxing.com
- * ----------------------------------------------------------------------------
- * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
- * 使用;不允许对程序代码以任何形式任何目的的再发布。
- * ============================================================================
- * Author By: 倪宗锋
- * PhpStorm ApiService.php
- * Create By 2018/1/4 16:06 $
- */
-
- namespace backend\modules\hotel\models;
-
-
- use common\models\BaseResource;
- use common\models\BaseSupplierSale;
-
- class ApiService
- {
- /**
- * Des:更据日期及酒店ID获取子房型数据
- * Name: getHotelRoomListByDate
- * @param $params
- * @return array
- * @author 倪宗锋
- */
- public function getHotelRoomListByDate($params)
- {
- $runHotelDistrib = new RunHotelDistrib();
- $roomList = $runHotelDistrib->getAllRoomListByHotelDate($params);
- if (!is_array($roomList) || count($roomList) == 0) {
- return ['code' => 2, 'info' => '未获取到符合条件的数据'];
- }
- $day_cnt = round((strtotime($params['end_date']) - strtotime($params['start_date'])) / 3600 / 24);//入住天数
- $base_room_list = [];
- foreach ($roomList as $val) {
- //1、判断 是否可以预定
- $val['can_reserve'] = 1;
- if ($val['sub_room_sale_days'] != $day_cnt) {//子房型上架天数
- $val['can_reserve'] = 0;
- }
- if ($val['room_sale_days'] != $day_cnt) {//房型上架天数
- $val['can_reserve'] = 0;
- }
- if ($val['hotel_sale_days'] != $day_cnt) {//酒店上架天数
- $val['can_reserve'] = 0;
- }
- if ($val['room_open_days'] != $day_cnt) {//房型的房态开房天数
- $val['can_reserve'] = 0;
- }
- if ($val['org_room_open_days'] != $day_cnt) {//渠道房型房态 开房天数
- $val['can_reserve'] = 0;
- }
- if ($val['stock'] == 0) {//库存
- $val['can_reserve'] = 0;
- }
- $val['stock'] = intval($val['stock']);
- if ($val['LASTEST_BOOK_TIME'] != '-1') {//最后预定时间
- $date = explode(',', $val['LASTEST_BOOK_TIME']);
- $lastBookTime = date('Y-m-d', strtotime("+{$date['0']} d", strtotime($params['start_date']))) . ' ' . $date['1'];
- if (strtotime($lastBookTime) <= time()) {
- $val['can_reserve'] = 0;
- }
- }
- unset($val['LASTEST_BOOK_TIME']);
- //2、是否可以取消
- $val['can_cancel'] = 0;
- if ($val['LASTEST_CANCEL_DAY'] != '-1') {//最后取消时间
- $date = explode(',', $val['LASTEST_CANCEL_DAY']);
- $lastBookTime = date('Y-m-d', strtotime("+{$date['0']} d", strtotime($params['start_date']))) . ' ' . $date['1'];
- if (strtotime($lastBookTime) > time()) {
- $val['can_cancel'] = 1;
- }
- }
- unset($val['LASTEST_CANCEL_DAY']);
-
- //3、含早的名称
- $val['breakfast'] = $this->breakfast($val['BREAKFAST_INCLUDE']);
- unset($val['BREAKFAST_INCLUDE']);
- //4、设置房型礼包数据
- $val['gift_list'] = [];
- if (empty($val['gift']) == false) {
- $giftArr = explode('||||', $val['gift']);
- foreach ($giftArr as $giftVal) {
- $gifts = explode('|||', $giftVal);
- $gitDateArr = [];
- $gitDateArr['id'] = $gifts[0];
- $gitDateArr['name'] = $gifts[1];
- $gitDateArr['date'] = $gifts[2];
- $val['gift_list'][] = $gitDateArr;
- }
- uasort($val['gift_list'], 'static::sort_by_date');
- $val['gift_list'] = array_values($val['gift_list']);
- }
- $val['min_price'] = floatval($val['min_price']);
- $val['avg_price'] = floatval($val['avg_price']);
- $val['total_money'] = floatval($val['total_money']);
- unset($val['gift']);
- $val['date_price'] = $this->set_date_price($val['date_price']);
- //5、设置基础房型的数据
- if (empty($base_room_list[$val['base_room_type']])) {
- $bed_name = $this->getBedTypeName($val['BED_TYPE']);//获取床型名称
- $base_room_list[$val['base_room_type']]['base_room_name'] = $val['base_room_name'];//房型名称
- $base_room_list[$val['base_room_type']]['bed_name'] = $bed_name;//床型名称
- $base_room_list[$val['base_room_type']]['area_size'] = $val['area_size'];
- $base_room_list[$val['base_room_type']]['min_price'] = $val['min_price'];
- $base_room_list[$val['base_room_type']]['room_img'] = $val['room_img'];
- } else {
- if ($base_room_list[$val['base_room_type']]['min_price'] > $val['min_price']) {//价格取最小价
- $base_room_list[$val['base_room_type']]['min_price'] = $val['min_price'];
- }
- }
- unset($val['BED_TYPE']);
- $base_room_list[$val['base_room_type']]['room_list'][] = $val;
- }
- $base_room_list = array_values($base_room_list);
- uasort($base_room_list, 'static::sort_by_min_price');
- $base_room_list = array_values($base_room_list);
- return ['code' => 0, 'info' => 'success', 'list' => $base_room_list];
- }
-
- /**
- * Des:更据字段名称排序
- * Name: sort_by_name
- * @param $x
- * @param $y
- * @return int
- * @author 倪宗锋
- */
- static function sort_by_min_price($x, $y)
- {
- if (floatval($x['min_price']) > floatval($y['min_price'])) {
- return 1;
- } else {
- return -1;
- }
- }
-
- /**
- * Des:获取酒店展示信息
- * Name: getHotelInfo
- * @param $params
- * @return array
- * @author 倪宗锋
- */
- public function getHotelInfo($params)
- {
- $runHotel = new OperaHotel();
- $getInfo = $runHotel->getInfo($params['hotel_id']);
- //设置图片
- $getInfo['img_list'] = [];
- if (empty($getInfo['imgs']) == false) {
- $img_arr = explode('||', $getInfo['imgs']);
- foreach ($img_arr as $value) {
- if (empty($value) == '') {
- $getInfo['img_list'][] = $value;
- }
- }
- }
- $getInfo['img_cnt'] = count($getInfo['img_list']);
- unset($getInfo['imgs']);
- $return = ['code' => 0, 'info' => 'success', 'data' => $getInfo];
- return $return;
- }
-
- /**
- * Des:设置日期价格
- * Name: set_date_price
- * @param $date_price
- * @return array
- * @author 倪宗锋
- */
- private function set_date_price($date_price)
- {
- if (empty($date_price)) {
- return [];
- }
- $date_arr = explode("||", $date_price);
- $return = [];
- foreach ($date_arr as $val) {
- $price_s = explode('|', $val);
- if (!empty($price_s[0]) && !empty($price_s['1'])) {
- $return[] = [
- 'date' => $price_s[0],
- 'price' => $price_s[1]
- ];
- }
- }
- uasort($return, 'static::sort_by_date');
- $return = array_values($return);
- return $return;
- }
-
- /**
- * Des:更据字段名称排序
- * Name: sort_by_name
- * @param $x
- * @param $y
- * @return int
- * @author 倪宗锋
- */
- static function sort_by_date($x, $y)
- {
- return strcasecmp($x['date'], $y['date']);
- }
-
-
- /**
- * Des:更据床型ID获取名称
- * Name: getBedTypeName
- * @param $bedType string 床型(1:大床 2:双床 10:多床)组合的情况下用逗号隔开
- * @return string
- * @author 倪宗锋
- */
- public function getBedTypeName($bedType)
- {
- if (empty($bedType)) {
- return '';
- }
- $bedTypeArr = explode(',', $bedType);
- $bed_name = [];
- foreach ($bedTypeArr as $value) {
- if ($value == 1) {
- $bed_name[] = '大床';
- } elseif ($value == 2) {
- $bed_name[] = '双床';
- } elseif ($value == 10) {
- $bed_name[] = '多床';
- }
- }
- return implode('|', $bed_name);
- }
-
- /**
- * Des:获取含早名称
- * Name: breakfast
- * @param $breakfast
- * @return string
- * @author 倪宗锋
- */
- public function breakfast($breakfast)
- {
- switch ($breakfast) {
- case 0:
- $name = '无早';
- break;
- case 1:
- $name = '单早';
- break;
- case 2:
- $name = '双早';
- break;
- case 3:
- $name = '三早';
- break;
- case 4:
- $name = '四早';
- break;
- case 5:
- $name = '五早';
- break;
- case 6:
- $name = '六早';
- break;
- case 7:
- $name = '七早';
- break;
- case 8:
- $name = '八早';
- break;
- case 9:
- $name = '九早';
- break;
- case 10:
- $name = '十早';
- break;
- default:
- $name = '多早';
- }
- return $name;
- }
-
- /**
- * Function Description:微信端获取酒店列表缓存
- * Function Name: getHotelListCache
- *
- * @return array
- *
- * @author 娄梦宁
- */
- public function getHotelListCache()
- {
- #1:获取微信商城酒店销售方式
- $base_supplier_sale = BaseSupplierSale::getSaleType(\Yii::$app->params['wx_supplier_id']);
- if ($base_supplier_sale == '') {
- return [
- 'code' => 1,
- 'info' => '微信商城未被授权酒店销售!'
- ];
- }
-
- #2:获取未来三个月的子房型价格库存
- $start_date = date('Y-m-d');
- $end_date = date('Y-m-d', strtotime('+90 day'));
- $runHotelDistrib = new RunHotelDistrib();
- $room_type_list = $runHotelDistrib->getRoomTypeList($start_date, $end_date, $base_supplier_sale, \Yii::$app->params['wx_supplier_id']);
-
- #3:处理结果集
- if (empty($room_type_list)) {
- return [
- 'code' => 2,
- 'info' => '无可选择房型!',
- ];
- }
- $new_list = [];
- $time_stamp = time();
- foreach ($room_type_list as $val) {
- if (!isset($new_list[$val['hotel_id'] . '-' . $val['run_date']])) {
- #酒店基础信息录入
- $new_list[$val['hotel_id'] . '-' . $val['run_date']] = [
- 'hotel_id' => $val['hotel_id'],
- 'hotel_name' => $val['hotel_name'],
- 'star_level' => $val['star_level'],
- 'area_id' => $val['area_id'],
- 'area_name' => $val['area_name'],
- 'run_date' => $val['run_date'],
- 'is_promotion' => $val['is_promotion'],
- 'recommend_level' => $val['recommend_level'],
- 'sale_label' => $val['sale_label'],
- 'hotel_label' => $val['hotel_label'],
- 'hotel_image' => $val['hotel_image'],
- 'business_area' => $val['business_area'],
- 'brand' => $val['brand'],
- 'hotel_type' => $val['hotel_type'],
- 'time_stamp' => $time_stamp
- ];
- }
- #子房型早餐价格库存床型数据
- $new_list[$val['hotel_id'] . '-' . $val['run_date']]['room_info'][] = [
- 'room_type' => $val['room_type'],
- 'bed_type' => $val['bed_type'],
- 'breakfast_include' => $val['breakfast_include'],
- 'price' => $val['price'],
- 'remaining_count' => $val['stock'] == null ? 0 : $val['stock'],
- ];
- }
- return [
- 'code' => 0,
- 'info' => '酒店列表数据获取成功!',
- 'data' => array_values($new_list)
- ];
- }
-
- /**
- * Function Description:获取酒店列表筛选条件
- * Function Name: getHotelType
- *
- * @return array
- *
- * @author 李健
- */
- public function getHotelType()
- {
- $base_resource = new BaseResource();
- // 获取酒店类型711
- $hotel_type = [
- '0' => '不限',
- '1' => '五星',
- '2' => '四星',
- ];
- $hotel_type_info = $base_resource->getHotelType(711);
- foreach ($hotel_type_info as $v) {
- $hotel_type[] = $v['res_name'];
- }
-
- // 获取酒店品牌
- $hotel_brand = [
- '不限',
- ];
- $hotel_brand_info = $base_resource->getHotelType(712);
- foreach ($hotel_brand_info as $v) {
- $hotel_brand[] = $v['res_name'];
- }
-
- // 设施服务
- $hotel_installation = ['不限'];
- $hotel_installation_info = $base_resource->getHotelType(709);
- foreach ($hotel_installation_info as $v) {
- $hotel_installation[] = $v['res_name'];
- }
-
- // 酒店价格
- $hotel_price = [
- '0' => '不限',
- '1' => '¥200以下',
- '2' => '¥201-500',
- '3' => '¥501-800',
- '4' => '¥801以上',
- ];
-
- // 床型
- $hotel_bed = [
- '0' => '不限',
- '1' => '单床',
- '2' => '双床',
- '3' => '多床',
- ];
-
- // 早餐
- $hotel_breakfast = [
- '0' => '不限',
- '1' => '含早',
- '2' => '单早',
- '3' => '双早',
- ];
-
- $init = [
- [
- 'type_id' => 1,
- 'type_name' => '价格',
- 'list' => $this->initHotelType($hotel_price),
- 'selected' => true,
- 'allowMoreSelected' => false,
- ],
- [
- 'type_id' => 2,
- 'type_name' => '酒店类型',
- 'list' => $this->initHotelType($hotel_type),
- 'selected' => false,
- 'allowMoreSelected' => false,
- ],
- [
- 'type_id' => 3,
- 'type_name' => '品牌',
- 'list' => $this->initHotelType($hotel_brand),
- 'selected' => false,
- 'allowMoreSelected' => true,
- ],
- [
- 'type_id' => 4,
- 'type_name' => '酒店设施',
- 'list' => $this->initHotelType($hotel_installation),
- 'selected' => false,
- 'allowMoreSelected' => true,
- ],
- [
- 'type_id' => 5,
- 'type_name' => '床型',
- 'list' => $this->initHotelType($hotel_bed),
- 'selected' => false,
- 'allowMoreSelected' => false,
- ],
- [
- 'type_id' => 6,
- 'type_name' => '早餐',
- 'list' => $this->initHotelType($hotel_breakfast),
- 'selected' => false,
- 'allowMoreSelected' => false,
- ]
- ];
- return $init;
- }
-
- /**
- * Function Description:初始化酒店类型数据
- * Function Name: initHotelType
- * @param $arr
- *
- * @return array
- *
- * @author 李健
- */
- public function initHotelType($arr)
- {
- $arr2 = [];
- foreach ($arr as $v) {
- $flag = false;
- if ($v == '不限') {
- $flag = true;
- }
- $arr2[] = [
- 'name' => $v,
- 'selected' => $flag,
- ];
- }
- return $arr2;
- }
- }
|