public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $propId = $this->_params['propId']; //好丑陋。。。。。。好无奈。。。。。。 //委托房源自动转发停用,为了app能够展示报错信息。。。 if (empty($propId)) { $this->_params['apiDebug'] = 1; return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '0000', 'message' => '委托房源自动转发功能已停用;若要发布请手动发布'); } $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('不是套餐经纪人。'); } $cityId = $brokerInfo->cityId; /** 套餐信息 */ $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['rentPropNum'] + $comboInfo['salePropNum'] > 0) { $currentCombo = $comboInfo; break; } } //没有二手房套餐 if (!isset($currentCombo)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => 0, 'statusMsg' => '尚未购买套餐,请购买套餐', 'currentComboInfo' => '尚未购买套餐')); } $currentComboName = $currentCombo['name']; $currentComboUsed = 0; $currentComboTotal = $currentCombo['salePropNum'] + $currentCombo['rentPropNum']; //二手房套餐列表 $comboEsfList = Bll_Broker_Combo_ManageAjk::getComboSpreadHouseList($brokerId, $cityId); $comboEsfPropIds = array_keys($comboEsfList); //租房套餐列表 $comboZuFangList = Bll_Combo_HouseRelation::getHouseRelations($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_HZ, 1); $comboZuFangPropIds = array(); foreach ($comboZuFangList as $v) { $comboZuFangPropIds[] = (int) $v['houseId']; } $currentComboUsed = count($comboZuFangPropIds) + count($comboEsfPropIds); $canSpread = $currentComboUsed >= $currentComboTotal ? 0 : (!$currentCombo['openUp'] && !$currentCombo['salePropNum'] ? 0 : 1); if (in_array($propId, array_merge($comboEsfPropIds, $comboZuFangPropIds))) { $status = 2; $statusMsg = '套餐推广中'; } else { $status = 1; $statusMsg = '好房源,不推广就浪费了~'; } //房源今日点击 房源总点击 $houseTodayClickInfo = Bll_House_EsfHouse::getHouseTodayComboClick($propId); $todayClicks = $houseTodayClickInfo[$propId]; //房源总点击 $houseClickInfo = Bll_House_EsfHouse::getComboHouseAccumulateClickByPropIds($brokerId, $propId, $cityId); $totalClicks = $todayClicks + $houseClickInfo[$propId]; $currentComboInfo = isset($currentCombo) ? $currentComboName . " ({$currentComboUsed}/{$currentComboTotal})" : '尚未购买套餐'; return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('todayClicks' => $todayClicks, 'totalClicks' => $totalClicks, 'status' => $status, 'statusMsg' => $statusMsg, 'canSpread' => $canSpread, 'currentComboInfo' => $currentComboInfo)); }
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)); }