public function handle_request_internal() { $brokerId = $this->_params['brokerId']; //经纪人信息 $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$brokerInfo) { throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } if (!Bll_Broker_HzBroker::isComboBroker($brokerId)) { throw new Exception_ISNotComboBrokerException('不是套餐经纪人。'); } /** 套餐信息 */ $comboInfoList = Bll_Combo_Broker_BrokerComboInfo::getBrokerComboList($brokerId); $currentDate = time(); foreach ($comboInfoList as $comboInfo) { $startDate = strtotime($comboInfo['startTime']); $endDate = strtotime($comboInfo['endTime']); /** 获取当前使用的套餐 */ if ($currentDate >= $startDate && $currentDate < $endDate && $comboInfo['salePropNum'] > 0) { $currentCombo = $comboInfo; $comboPropNum = $currentCombo['salePropNum']; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $comboPropNum = $currentCombo['rentPropNum'] + $currentCombo['salePropNum']; } break; } } $hasCombo = 0; //没有二手房套餐 if (!isset($currentCombo)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => array(), 'oldList' => array(), 'surplus' => 0, 'hasCombo' => $hasCombo)); } else { $hasCombo = 1; } $cityId = $brokerInfo->cityId; //获取套餐推广信息 $comboSpreadHouseList = Bll_Broker_Combo_ManageAjk::getComboSpreadHouseList($brokerId, $cityId); if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($brokerId, Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK, true); } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK); } //套餐还可以推的房源数量 $surplus = $comboPropNum - $currentSpreadHouseCount; if (empty($comboSpreadHouseList)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => array(), 'oldList' => array(), 'surplus' => $surplus, 'hasCombo' => $hasCombo)); } //获取房源信息 $propIds = array_keys($comboSpreadHouseList); $propsInfo = Bll_House_EsfHouse::getHouseBaseInfo($propIds, $cityId); //批量获取默认图片 $propDefImages = Model_House_AjkPropertyData::getDafImages($propIds); //批量获取房源总点 $houseTodayClickInfo = Bll_House_EsfHouse::getHouseTodayComboClick($propIds); $houseClickInfo = Bll_House_EsfHouse::getComboHouseAccumulateClickByPropIds($brokerId, $propIds, $cityId); //房源竞价&精选计划 $propSpreadInfo = Model_Plan_EsfAjkPropSpread::getPlanByPropIds($propIds); //拼接房源列表中房源数据 $newList = array(); $oldList = array(); foreach ($propsInfo as $prop) { $row = array(); $row['propId'] = $prop->proId; $row['title'] = $prop->proName; $row['commId'] = $prop->commId; $row['commName'] = $prop->commName; $row['roomNum'] = $prop->roomNum; $row['hallNum'] = $prop->hallNum; $row['area'] = round($prop->areaNum); $row['toiletNum'] = $prop->toiletNum; $row['price'] = intval($prop->proPrice); $row['priceUnit'] = '万'; $row['isBid'] = 0; $row['isChoice'] = 0; $row['isMoreImg'] = $prop->isHighQulity; $row['isPhonePub'] = $prop->uriCode == 'mobile.asyn' || $prop->uriCode == 'mobile-ajk-broker.asyn' ? 1 : 0; $row['isVisible'] = isset($houseInfo['isVisible']) ? $houseInfo['isVisible'] : 1; //0-违规房源 1-非违规房源 $row['createTime'] = $prop->postDate; //房源发布时间 $row['imgUrl'] = Model_House_AjkPropertyData::imageUrl($propDefImages[$prop->proId]); if ($prop->commitionType == 2) { $row['isEntrust'] = 1; } else { $row['isEntrust'] = 0; } $row['totalClicks'] = $houseTodayClickInfo[$prop->proId] + $houseClickInfo[$prop->proId]; if (isset($propSpreadInfo[$prop->proId])) { if ($propSpreadInfo[$prop->proId]->bidVersion == 1 && ($propSpreadInfo[$prop->proId]->status == 1 || $propSpreadInfo[$prop->proId]->status == 11)) { $row['isBid'] = 1; } elseif ($propSpreadInfo[$prop->proId]->bidVersion == 2 && ($propSpreadInfo[$prop->proId]->status == 1 || $propSpreadInfo[$prop->proId]->status == 11)) { $row['isChoice'] = 1; } } //计算出房源发布天数 $timeFixStr = strtotime(date("Ymd", $row['createTime'])); $leftDay = floor((time() - $timeFixStr) / 86400); if ($leftDay >= 30) { $oldList[] = $row; } else { $newList[] = $row; } } // 排序 usort($oldList, function ($a, $b) { if ($a['createTime'] == $b['createTime']) { return 0; } return $a['createTime'] > $b['createTime'] ? -1 : 1; }); usort($newList, function ($a, $b) { if ($a['createTime'] == $b['createTime']) { return 0; } return $a['createTime'] > $b['createTime'] ? -1 : 1; }); return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus > 0 ? $surplus : 0, 'hasCombo' => $hasCombo)); }