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)); }
/** * 把经纪人因为套餐到期停止推广的房源(套餐规定的可推广房源数)重新上线,(按房源发布时间 倒序排列) * @return string */ private function reUpExpireHouse() { $currentCombo = Bll_Combo_Broker_BrokerComboInfo::getBrokerCurrentCombo($this->params['ajk_broker_id'], Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ); if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { return $this->allReturn[] = '打通套餐,好租不处理'; } // 当前在线房源数 $onLineSpreadHouseCount = Bll_Combo_HouseRelation::getOnLineSpreadHouseCount($this->params['ajk_broker_id'], Bll_Combo_HouseRelation::SITE_TYPE_HZ); $comboProNum = Bll_Combo_Broker_BrokerComboInfo::getTotalCombosProNum($this->params['ajk_broker_id']); // 套餐可以推广的房源数 $comboProNum = isset($comboProNum['totalRentPropNum']) ? $comboProNum['totalRentPropNum'] : 0; if (!$comboProNum) { return $this->allReturn[] = "套餐可以推广的房源数0"; } if ($onLineSpreadHouseCount >= $comboProNum) { return $this->allReturn[] = "在线推广房源数{$onLineSpreadHouseCount}, 套餐可推广房源数{$comboProNum},不需要上线套餐到期的房子"; } $shouldUpNum = $comboProNum - $onLineSpreadHouseCount; $allExpireRelations = Bll_Combo_HouseRelation::getHouseRelations($this->params['ajk_broker_id'], Bll_Combo_HouseRelation::SITE_TYPE_HZ, Model_Combo_HouseRelation::ENUM_COMBO_EXPIRE); if (empty($allExpireRelations)) { return $this->allReturn[] = "没有需要上线的推广房子"; } // 房子有效性判断 $num = 0; $shouldUpRelations = array(); foreach ($allExpireRelations as $relation) { $proId = $relation['houseId']; if (!($propInfo = Bll_House_HzHouse::getPropInfo($proId, $relation['cityId'], 2))) { continue; } if (!$propInfo['status'] || in_array($propInfo['msg']['status'], array(Const_HzStatus::VERIFY, Const_HzStatus::REMOVE, Const_HzStatus::EXPIRED))) { continue; } if ($num < $shouldUpNum) { $shouldUpRelations[] = $relation; } $num++; } foreach ($shouldUpRelations as $comboRelation) { $this->params['pro_id'] = $comboRelation['houseId']; // 更新关系 Bll_Combo_HouseRelation::updateComboStatusById($comboRelation['id'], Model_Combo_HouseRelation::ENUM_HOUSE_ONLINE, Bll_Combo_HouseRelation::SITE_TYPE_HZ); // 维护房子状态 Bll_HzPropBll::bulidHzProStatu($this->params['pro_id']); // 写入房源取消套餐推广日志 $this->writePropLog(Const_ProLogType::LOG_ADD_INTO_COMBO, '开始套餐推广'); } }
/** * 房源加入套餐推广 * * @param int $brokerId * @param int $cityId * @param array $params * @return array */ private function houseStartComboSpreadAction($brokerId, $cityId, $params) { $houseIds = is_array($params['houseIds']) ? $params['houseIds'] : explode(',', $params['houseIds']); $realHouseIds = $this->removeInvalidateHouseId($brokerId, $houseIds, $cityId); if (empty($realHouseIds)) { return $this->buildResponse('error', $houseIds, '请至少选择一套房源。'); } $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); if (empty($comboList)) { return $this->buildResponse('error', $realHouseIds, '您还没有购买套餐,购买后才能推广房源。<br /><a href="/ajkbroker/combo/buy/select" target="_blank">去购买套餐>></a> '); } $currentComboHouseCount = 0; $currentCombo = array(); $nextCombo = array(); $currentTime = time(); foreach ($comboList as $combo) { /** 打通的套餐 */ if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($combo)) { /** 获取当前使用的套餐 */ if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { if ($combo['salePropNum'] > 0 || $combo['rentPropNum'] > 0) { $currentCombo = $combo; $currentComboHouseCount = $combo['salePropNum'] + $combo['rentPropNum']; } continue; } /** 获取续买套餐 */ if (strtotime($combo['startTime']) > $currentTime) { if ($combo['salePropNum'] > 0 || $combo['rentPropNum'] > 0) { $nextCombo = $combo; } } continue; } /** 未打通的套餐 */ if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime && $combo['salePropNum'] > 0) { $currentComboHouseCount = $combo['salePropNum']; $currentCombo = $combo; break; } /** 获取续买套餐 */ if ($combo['salePropNum'] > 0 && strtotime($combo['startTime']) > $currentTime) { $nextCombo = $combo; } } if (empty($currentCombo) && empty($nextCombo)) { return $this->buildResponse('error', $realHouseIds, '您还没有购买套餐,购买后才能推广房源。<br /><a href="/ajkbroker/combo/buy/select" target="_blank">去购买套餐>></a> '); } if (empty($currentCombo) && !empty($nextCombo)) { return $this->buildResponse('error', $realHouseIds, sprintf('您购买的套餐 %s 需要到 %s 才能生效。', $nextCombo['name'], date('Y.m.d', strtotime($nextCombo['startTime'])))); } if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK, true); } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); } if (count($realHouseIds) + $currentSpreadHouseCount > $currentComboHouseCount) { return $this->buildResponse('error', $realHouseIds, sprintf('最多只能推广 %d 套房源。', $currentComboHouseCount)); } if (Bll_Combo_HouseRelation::houseStartComboSpread($brokerId, $cityId, $realHouseIds, Bll_Combo_HouseRelation::SITE_TYPE_AJK)) { return $this->buildResponse('ok', $realHouseIds, sprintf('成功推广 %d 套房源。', count($realHouseIds))); } return $this->buildResponse('error', $realHouseIds, '套餐推广失败。'); }
public function handle_request_combo() { $ajkBrokerId = $this->brokerId; $cityId = $this->cityId; $siteType = Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ; //首先获取套餐关系房源列表 ---- 那房源到主表去除status 已删除的房源 -----在房源主表获取房源基本信息 $comboList = Bll_Combo_HouseRelation::getHouseRelations($ajkBrokerId, $siteType, 1); $surplus = $hasCombo = 0; //获取套餐信息-首先判断经纪人有无套餐 $comboInfos = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($ajkBrokerId, $siteType); if (count($comboInfos) > 0) { $index = Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType($siteType); $currentTime = time(); foreach ($comboInfos as $combo) { if ($combo[$index] == 0) { continue; } if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { $currentCombo = $combo; } } if (!empty($currentCombo)) { $surplus = $currentCombo['rentPropNum']; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { //商业地产没打通 $surplus = $currentCombo['rentPropNum'] + $currentCombo['salePropNum']; } $hasCombo = 1; } } //获取当前已推广套餐数量 if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($ajkBrokerId, $siteType, true); } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($ajkBrokerId, $cityId, $siteType); } $oldList = $newList = array(); if (empty($comboInfos)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); } $propIds = array(); foreach ($comboList as $row) { $propIds[] = $row['houseId']; } $hzBrokerId = Bll_HzBroker::get_brokerid_by_ajk_brokerid($ajkBrokerId); $comboPropList = Model_House_HzPropSearch::getPropList($propIds, $hzBrokerId, $this->cityId); foreach ($comboPropList as $key => $list) { if (in_array($list['status'], array(Const_HzStatus::VERIFY, Const_HzStatus::REMOVE, Const_HzStatus::EXPIRED))) { unset($comboPropList[$key]); } } //fix bug45133 if (empty($comboPropList)) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); } $propIds = array(); foreach ($comboPropList as $row) { $propIds[] = $row['proid']; } //从主表获取房源信息 $propertyList = Model_House_HzProp::getPropsByPropIds($propIds); //获取是否精选或者竞价 $relations = Model_Plan_HzPlanning::getBidRelationsByHouseIds($propIds, array(Const_HzPlan::SPREAD, Const_HzPlan::WAITING)); if (!empty($relations)) { $planPropMap = array(); foreach ($relations as $relation) { $planIds[] = $relation['plan_id']; $planPropMap[$relation['plan_id']] = $relation['proid']; } if (!empty($planIds)) { $plans = Model_Plan_HzPlanBasic::getPlansByIds($planIds); foreach ($plans as $plan) { if ($plan->flag == 0) { continue; } if ($plan->bid_version == 2) { $propId = $planPropMap[$plan['id']]; $propertyList[$propId]['isChoice'] = 1; } else { $propId = $planPropMap[$plan['id']]; $propertyList[$propId]['isBid'] = 1; } } } } // 批量获取房源的默认图片 $defaultImages = Model_Image_HzImage::getDefaultImagesByHouseIds($propIds); if (!empty($defaultImages)) { foreach ($defaultImages as $defaultImage) { $propertyList[$defaultImage['proid']]['imgUrl'] = $defaultImage->imageUrl(); } } krsort($propertyList); $startDate = $endDate = date('Ymd'); $todayClicks = Bll_Combo_Broker_BrokerComboInfo::getHouseComboClickEx($propIds, $startDate, $endDate, Model_Ppc_NewPackageStatsHouseDay::SITE_TYPE_HZ); $totalClicks = Bll_House_HzHouse::getComboHouseAccumulateClick($ajkBrokerId, $propIds, $cityId); foreach ($propertyList as $list) { $row = array(); $row['id'] = $list['propId']; $row['propId'] = $list['propId']; $row['title'] = $list['title']; $row['imgUrl'] = $list['imgUrl'] ?: ''; $row['commId'] = $list['commid']; $row['commName'] = $list['commname']; $row['roomNum'] = $list['roomnum']; $row['hallNum'] = $list['hallnum']; $row['toiletNum'] = $list['toilnetnum']; $row['area'] = round($list['areanum']); $row['price'] = round($list['pricenum']); $row['priceUnit'] = '元/月'; $row['todayClicks'] = $todayClicks[$list['propId']][$startDate] ?: 0; $row['totalClicks'] = $totalClicks[$list['propId']] ?: 0; $row['totalClicks'] = $row['totalClicks'] + $row['todayClicks']; $row['isBid'] = isset($list['isBid']) ? $list['isBid'] : 0; $row['isChoice'] = isset($list['isChoice']) ? $list['isChoice'] : 0; $row['isVisible'] = (int) ($list['status'] != 6); $row['isMoreImg'] = (int) $list['quality']; $row['isPhonePub'] = (int) (isset($list['from']) && $list['from'] == 'mobile-ajk-broker'); $row['publishDays'] = floor((time() - $list['created']) / 86400); $row['publishDaysMsg'] = $row['publishDays'] > 0 ? "{$row['publishDays']}天前发布" : '今天发布'; $row['createTime'] = date('Y-m-d H:i:s', $list['created']); //$row['updateTime'] = date('Y-m-d H:i:s', $list['updated']); //是否委托 $isEntrust = Bll_Zufang_Choice::isCommissionHouse($list['propId'], $ajkBrokerId, Model_House_Commission::TYPE_RENT); $row['isEntrust'] = $isEntrust ? 1 : 0; $row['publishDays'] > 30 ? $oldList[] = $row : ($newList[] = $row); } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('newList' => $newList, 'oldList' => $oldList, 'surplus' => $surplus - $currentSpreadHouseCount, 'hasCombo' => $hasCombo)); }
/** * 判断新套餐 经纪人是否可以推广房源 * * @param int $cityId * @param int $brokerId * @return bool */ public static function ajkComboBrokerCanSpreadHouse($cityId, $brokerId) { $currentCombo = Bll_Combo_Broker_BrokerComboInfo::getBrokerCurrentCombo($brokerId, Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK); if (empty($currentCombo)) { return false; } if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCount($brokerId, Bll_Combo_HouseRelation::SITE_TYPE_AJK, true); $salePropNum = $currentCombo[Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType(Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK)]; $rentPropNum = $currentCombo[Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType(Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_HZ)]; return $currentSpreadHouseCount < $salePropNum + $rentPropNum; } else { $currentSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); return $currentSpreadHouseCount < $currentCombo[Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType(Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK)]; } }
/** * @param $brokerId * @param $cityId * @param string $siteType * @return array * 房源发布验证是否能够套餐推广 */ public static function housePublishComboCheck($brokerId, $cityId, $siteType = self::SITE_TYPE_AJK) { $comboList = Bll_Combo_Broker_BrokerComboInfo::getComboListBySite($brokerId, $siteType); if (empty($comboList)) { return Util_GlobalFunc::buildReturn(-1, '您还没有购买套餐,只能保存到未推广房源'); } $currentCombo = array(); $nextCombo = array(); $currentTime = time(); $index = Bll_Combo_Broker_BrokerComboInfo::getComboIndexBySiteType($siteType); foreach ($comboList as $combo) { if (strtotime($combo['endTime']) > $currentTime && strtotime($combo['startTime']) < $currentTime) { $currentCombo = $combo; } else { $nextCombo = $combo; } } $currentComboHouseCount = $currentCombo[$index]; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $currentComboHouseCount = $currentCombo['rentPropNum'] + $currentCombo['salePropNum']; } if (empty($currentCombo) && empty($nextCombo)) { return Util_GlobalFunc::buildReturn(-2, '您还没有购买套餐,只能保存到未推广房源'); } if (empty($currentCombo) && !empty($nextCombo)) { return Util_GlobalFunc::buildReturn(-3, '您的套餐未生效,只能保存到未推广房源'); } if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo) && ($siteType == self::SITE_TYPE_HZ || $siteType == self::SITE_TYPE_AJK)) { $currentSpreadHouseCount = static::getHouseCount($brokerId, $siteType, true); } else { $currentSpreadHouseCount = static::getHouseCountEx($brokerId, $cityId, $siteType); } if ($currentSpreadHouseCount >= $currentComboHouseCount) { return Util_GlobalFunc::buildReturn(-4, '推广房源已满,只能保存到未推广房源'); } return Util_GlobalFunc::buildReturn(1, ''); }
/** * * 获取经纪人套餐(已分组) * * @param $userId * @return array * $return['residence'] 住宅(key=0,当前,key=1,续买) * $return['business'] 商业地产(key=0,当前,key=1,续买) * $return['nowCombo'] 当前(排序,二手房、租房、商业地产) * $return['comingCombo'] 续买(排序,二手房、租房、商业地产) * */ public static function getBrokerComboAlreadyGroup($userId) { if (empty($userId)) { return array('error' => '获取套餐API,userId为空'); } //经纪人原始套餐列表 $brokerCombo = self::getBrokerCombo($userId); //住宅、商业地产分组 $return['residence'] = array(); //住宅 $return['business'] = array(); //商业地产 $return['nowCombo'] = array(); //当前使用的套餐 $return['comingCombo'] = array(); //续买的套餐 $sort['group']['residence'] = array(); //住宅排序(根据套餐开始时间) $sort['group']['business'] = array(); //商业地产排序(根据套餐开始时间) $sort['effect']['nowCombo'] = array(); //生效套餐排序(二手房、租房、商业地产) $sort['effect']['comingCombo'] = array(); //续买套餐排序(二手房、租房、商业地产) $sort['effect']['startTime'] = array(); $currentTimestamp = time(); foreach ($brokerCombo as $combo) { $combo['startTimestamp'] = strtotime($combo['startTime']); $combo['endTimestamp'] = strtotime($combo['endTime']); //套餐内容组装 $combo['comboStr'] = ''; if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($combo) && $combo['jpPropNum'] <= 0) { $combo['comboStr'] = sprintf('房源%d套(二手房、住宅租赁)', $combo['salePropNum'] + $combo['rentPropNum']); } else { if ($combo['salePropNum'] > 0) { $combo['comboStr'] .= $combo['comboStr'] ? ',' : ''; $combo['comboStr'] .= sprintf('房源%d套(二手房)', $combo['salePropNum']); } if ($combo['rentPropNum'] > 0) { $combo['comboStr'] .= $combo['comboStr'] ? ',' : ''; $combo['comboStr'] .= sprintf('房源%d套(住宅租赁)', $combo['rentPropNum']); } } if ($combo['jpPropNum'] > 0) { $combo['comboStr'] .= $combo['comboStr'] ? ',' : ''; $combo['comboStr'] .= sprintf('房源%d套(商铺、写字楼)', $combo['jpPropNum']); } //计算天数套餐天数 $combo['day'] = floor((strtotime(date('Y-m-d', $combo['endTimestamp'])) - strtotime(date('Y-m-d', $combo['startTimestamp']))) / 86400) + 1; //计算剩余天数 $combo['remainDay'] = floor((strtotime(date('Y-m-d', $combo['endTimestamp'])) - strtotime(date('Y-m-d'))) / 86400) + 1; //兼容续买的套餐 $combo['remainDay'] = $combo['remainDay'] > $combo['day'] ? $combo['day'] : $combo['remainDay']; //有出售或出租的算做住宅套餐(分组) if ($combo['salePropNum'] || $combo['rentPropNum']) { array_push($return['residence'], $combo); array_push($sort['group']['residence'], $combo['startTimestamp']); } else { //商业地产 array_push($return['business'], $combo); array_push($sort['group']['business'], $combo['startTimestamp']); } //当前 if ($combo['startTimestamp'] <= $currentTimestamp && $combo['endTimestamp'] >= $currentTimestamp) { array_push($return['nowCombo'], $combo); $sort['effect']['nowCombo']['salePropNum'][] = $combo['salePropNum']; $sort['effect']['nowCombo']['rentPropNum'][] = $combo['rentPropNum']; $sort['effect']['nowCombo']['jpPropNum'][] = $combo['jpPropNum']; } else { //续买 array_push($return['comingCombo'], $combo); $sort['effect']['comingCombo']['salePropNum'][] = $combo['salePropNum']; $sort['effect']['comingCombo']['rentPropNum'][] = $combo['rentPropNum']; $sort['effect']['comingCombo']['jpPropNum'][] = $combo['jpPropNum']; $sort['effect']['startTime'][] = $combo['startTimestamp']; } } //根据套餐开始时间排序(住宅、商业地产) if ($return['residence']) { array_multisort($return['residence'], SORT_ASC, $sort['group']['residence']); } if ($return['business']) { array_multisort($return['business'], SORT_ASC, $sort['group']['business']); } //根据套餐开始时间排序(住宅、商业地产) array_multisort($sort['group']['residence'], SORT_ASC, $return['residence']); array_multisort($sort['group']['business'], SORT_ASC, $return['business']); //根据推广套数(二手房、租房、商业地产排序) array_multisort($sort['effect']['nowCombo']['salePropNum'], SORT_DESC, $sort['effect']['nowCombo']['rentPropNum'], SORT_DESC, $sort['effect']['nowCombo']['jpPropNum'], SORT_DESC, $return['nowCombo']); array_multisort($sort['effect']['startTime'], SORT_ASC, $sort['effect']['comingCombo']['salePropNum'], SORT_DESC, $sort['effect']['comingCombo']['rentPropNum'], SORT_DESC, $sort['effect']['comingCombo']['jpPropNum'], SORT_DESC, $return['comingCombo']); return $return; }
/** * 503 套餐到期 * 1. 获取经纪人当前的套餐信息 * 2. 如果经纪人没有套餐 * 1. 下掉经纪人所有的的套餐房源&竞价计划 * 3. 判断经纪人当前在线的房源数和经纪人当前生效的套餐能够推广的房源数 * 1. 如果当前推广的房源数 大于 套餐可以推广的房源数,把多余的房子下掉(按房源发布时间 倒序排列) * * @param $queueInfo * @return array */ public static function comboExpire($queueInfo) { $houseOnlineRelationList = Bll_Combo_HouseRelation::getOnlineHouseList($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_AJK); $currentCombo = Bll_Combo_Broker_BrokerComboInfo::getBrokerCurrentCombo($queueInfo['broker_id'], Bll_Combo_Broker_BrokerComboInfo::SITE_TYPE_AJK); /** 添加打通的套餐的逻辑 */ if (!empty($currentCombo) && Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $dealRemark = array('当前套餐为打通套餐'); $comboSpreadHouseCount = $currentCombo['salePropNum'] + $currentCombo['rentPropNum']; $hzHouseOnlineRelationList = Bll_Combo_HouseRelation::getOnlineHouseList($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_HZ); $spreadHouseCount = count($hzHouseOnlineRelationList) + count($houseOnlineRelationList); if ($spreadHouseCount <= $comboSpreadHouseCount) { $dealRemark[] = sprintf('%d 经纪人当前[%s]套餐,可推广房源数大于当前在线房源数,不处理。', $queueInfo['id'], date('Y-m-d H:i:s')); return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark); } $rangedHouseRelation = Bll_Combo_Updown_AjkDealJob::calculateRangeByCreated($houseOnlineRelationList, $hzHouseOnlineRelationList); $offLineHouseOnlineRelationList = array_slice($rangedHouseRelation, $comboSpreadHouseCount); $fail = array(); $success = array(); foreach ($offLineHouseOnlineRelationList as $offLineHouseOnlineRelation) { $offLineHouseId = $offLineHouseOnlineRelation['houseId']; $siteType = $offLineHouseOnlineRelation['siteType']; $logRemark = static::offLineHouse($queueInfo, array($offLineHouseId), '经纪人套餐到期下架房源', 0); $dealRemark = array_merge($dealRemark, $logRemark); if (1 == Bll_Combo_HouseRelation::updateHouseComboSpreadState($queueInfo['broker_id'], array($offLineHouseId), $siteType, Model_Combo_HouseRelation::ENUM_COMBO_EXPIRE)) { $success[] = $offLineHouseId; } else { $fail[] = $offLineHouseId; } } if (!empty($fail)) { $dealRemark[] = sprintf('下掉经纪人超出房源(%s)失败', implode(', ', $fail)); } if (!empty($success)) { $dealRemark[] = sprintf('下掉经纪人超出房源(%s)成功', implode(', ', $success)); } return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark); } if (empty($houseOnlineRelationList)) { return static::buildReturn(self::PROCESS_STATUS_SUCCESS, '经纪人没有在线房源,不处理。'); } $onlineHouseIds = array(); foreach ($houseOnlineRelationList as $houseOnlineRelation) { $onlineHouseIds[] = $houseOnlineRelation['houseId']; } /** 当前没有生效的套餐,下掉所有的房子 */ if (empty($currentCombo)) { $dealRemark = static::offLineHouse($queueInfo, $onlineHouseIds, '经纪人套餐到期下架房源', 0); if (!Bll_Combo_HouseRelation::expiredBrokerCombo($queueInfo['broker_id'], $queueInfo['city_id'], Bll_Combo_HouseRelation::SITE_TYPE_AJK)) { $dealRemark[] = sprintf('修改经纪人在线房源(%s)套餐关系状态为过期失败', implode(', ', $onlineHouseIds)); } else { $dealRemark[] = sprintf('修改经纪人在线房源(%s)套餐关系状态为过期成功', implode(', ', $onlineHouseIds)); } $dealRemark[] = sprintf('%d 经纪人当前[%s]没有生效的租售套餐,下架房源[ %s ]', $queueInfo['id'], date('Y-m-d H:i:s'), implode(',', $onlineHouseIds)); return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark); } /** * 当前经纪人的套餐可推广房源数,大于当前在线房源,不处理。 */ if ($currentCombo['salePropNum'] >= count($onlineHouseIds)) { return static::buildReturn(self::PROCESS_STATUS_SUCCESS, sprintf('%d 经纪人当前[%s]租售套餐,可推广房源数,大于当前在线房源数,不处理。(%s)', $queueInfo['id'], date('Y-m-d H:i:s'), implode(', ', $onlineHouseIds))); } /** * 当前经纪人套餐可推广房源数小于推广中的房源,下掉多余的房源。 */ $offLineHouseIds = array_slice($onlineHouseIds, $currentCombo['salePropNum']); $dealRemark = static::offLineHouse($queueInfo, $offLineHouseIds, '经纪人套餐到期下架房源', 0); if (count($offLineHouseIds) != Bll_Combo_HouseRelation::updateHouseComboSpreadState($queueInfo['broker_id'], $offLineHouseIds, Bll_Combo_HouseRelation::SITE_TYPE_AJK, Model_Combo_HouseRelation::ENUM_COMBO_EXPIRE)) { $dealRemark[] = sprintf('下掉经纪人超出房源(%s)失败', implode(', ', $offLineHouseIds)); } else { $dealRemark[] = sprintf('下掉经纪人超出房源(%s)成功', implode(', ', $offLineHouseIds)); } $dealRemark[] = sprintf('%d 经纪人当前[%s]租售套餐,可推广房源数小于当前在线房源数,下架房源[ %s ]', $queueInfo['id'], date('Y-m-d H:i:s'), implode(',', $offLineHouseIds)); return static::buildReturn(self::PROCESS_STATUS_SUCCESS, $dealRemark); }
/** * @param Manage_ProplistController $controller * @param AJKRequest $request * @param AJKResponse $response * * @return array */ public static function getComboInfo($controller, $request, $response) { $cityId = $request->getBrokerCityId(); $brokerId = $request->getBrokerId(); $query = $request->get_parameter('q'); $pageParams = array('query' => $query); if (!empty($query)) { $pageParams['searchByCommunity'] = !is_numeric($query); } /** 套餐信息 */ $comboInfoList = Bll_Combo_Broker_BrokerComboInfo::getBrokerComboList($brokerId); //echo "<pre>";print_r($comboInfoList);exit; $currentCombo = array(); $nextCombo = array(); $currentDate = time(); foreach ($comboInfoList as $comboInfo) { $startDate = strtotime($comboInfo['startTime']); $endDate = strtotime($comboInfo['endTime']); /** 获取当前使用的套餐 */ if ($currentDate >= $startDate && $currentDate < $endDate && $comboInfo['salePropNum'] > 0) { $currentCombo = $comboInfo; } /** 获取续买套餐 */ if ($comboInfo['salePropNum'] > 0 && $startDate > $currentDate) { if (!empty($nextCombo)) { $nextComboEffectTime = strtotime($nextCombo['startTime']); if ($nextComboEffectTime > $startDate) { $nextCombo = $comboInfo; } } else { $nextCombo = $comboInfo; } } } $pageParams['currentCombo'] = $currentCombo; $pageParams['nextCombo'] = $nextCombo; $pageParams['comboCanSpreadHouseCount'] = 0; if (!empty($currentCombo)) { if (Bll_Combo_Broker_BrokerComboInfo::isOpenUp($currentCombo)) { $hzSpreadHouseCount = Bll_Combo_HouseRelation::getHouseCountEx($brokerId, $cityId, Bll_Combo_HouseRelation::SITE_TYPE_HZ); $pageParams['comboCanSpreadHouseCount'] = max(0, $currentCombo['salePropNum'] + $currentCombo['rentPropNum'] - $hzSpreadHouseCount); } else { $pageParams['comboCanSpreadHouseCount'] = $currentCombo['salePropNum']; } } $pageParams['comboClick'] = Bll_Ppc_NewPackageStatsBrokerDay::getComboClickInfo($brokerId, date('Ymd'), Model_Ppc_NewPackageStatsBrokerDay::SITE_TYPE_AJK); $isChoiceCity = Bll_City::isChoiceCity($cityId, Const_Site::ANJUKE); $isBlockChoiceCity = Bll_City::isBlockChoice($cityId, Const_Site::ANJUKE); /** 精选城市 */ if ($isChoiceCity) { $pageParams['bidTip'] = '精选'; } $pageParams['isChoiceCity'] = $isChoiceCity; $pageParams['isBlockChoiceCity'] = $isBlockChoiceCity; $pageParams['isBidCity'] = false; $pageParams['isShowCaseCity'] = Bll_City::isShowCaseCity($cityId, Const_Site::ANJUKE); /** 获取竞价计划信息 */ if ($isChoiceCity) { $bidPropIds = array(); $pageParams['bidPlanList'] = static::getBrokerBidPlanList($brokerId, $cityId, $bidPropIds, true); $pageParams['bidPropIds'] = $bidPropIds; $pageParams['bidClickCount'] = Bll_Plan_Bid_AjkPlan::getBrokerBidClick($brokerId, date('Ymd'), $cityId); $pageParams['bidCost'] = Bll_Plan_Bid_AjkPlan::getBrokerBidCost($brokerId, date('Ymd'), $cityId); } /** 获取套餐推广信息 */ $comboSpreadHouseList = static::getComboSpreadHouseList($brokerId, $cityId); $pageParams['comboSpreadHouseList'] = $comboSpreadHouseList; $pageParams['comboHouseIds'] = array_keys($comboSpreadHouseList); /** 速度优化:effectURL 没有在房源管理页使用,所以这个是可以删除的 */ // if (!empty($comboSpreadHouseList)) { // TODO 获取效果时时看链接 // $pageParams['effectURL'] = Bll_Plan_Fix_AjkPlan::GetPlanFixedPriceDetailUri($pageParams['fixPlanPropList'][0]['planInfo']['id'], 0, 1); // } $houseInfoList = static::getBrokerAllPropInfoList($brokerId, $cityId, $pageParams['comboHouseIds'], $bidPropIds, $pageParams['isChoiceCity'], $query); //echo "<pre>";print_r($houseInfoList);exit; /** 房源质量信息 */ //$pageParams['houseSolly'] = static::getHouseSollyResult($houseInfoList['houseIdList']); $pageParams['houseSolly'] = static::getHouseSollyResultEx($houseInfoList); $pageParams['comboHouseIds'] = array_values(array_intersect($pageParams['comboHouseIds'], array_keys($houseInfoList['comboSpreadHouseList']))); if ($isChoiceCity) { $houseBidInfoList = array(); $houseBidStatus = array(); foreach ($pageParams['bidPlanList'] as $bidInfo) { $houseBidInfoList[$bidInfo['propId']] = $bidInfo; $houseBidStatus[$bidInfo['propId']] = $bidInfo['status']; if ($bidInfo['model'] == Model_Plan_EsfAjkPropSpread::BLOCK_CHOICE) { $pageParams['planInfoUrl'][$bidInfo['propId']]['urlChoice'] = "/ajkbroker/user/ajax/blockchoice"; } else { $pageParams['planInfoUrl'][$bidInfo['propId']]['urlChoice'] = "/ajkbroker/user/ajax/choice"; } } $pageParams['houseBidStatus'] = $houseBidStatus; $houseInfoList['comboSpreadHouseList'] = static::extendChoiceInfo($houseInfoList['comboSpreadHouseList'], $houseBidInfoList, $cityId); if (Bll_City::isChoiceIndependentCity($cityId, Const_Site::ANJUKE)) { $houseInfoList['noSpreadHouseList'] = static::extendChoiceInfo($houseInfoList['noSpreadHouseList'], $houseBidInfoList, $cityId); } // print_r($houseInfoList['noSpreadHouseList']); } /** 精选引导优化 (精选城市 && 已经购买了套餐 && 推广房源数>0) */ $choiceFunctionOptimizationGuide = false; /* if ($isChoiceCity && (!empty($currentCombo) || !empty($nextCombo)) && (count($comboSpreadHouseList) > 0)) { if (Bll_Broker_AjkBrokerGuideNew::getGuideStatus($brokerId, 'Choice_Function_Optimization') == 0) { $choiceFunctionOptimizationGuide = true; } } */ $pageParams['choiceFunctionOptimizationGuide'] = $choiceFunctionOptimizationGuide; //echo "<pre>";print_r(array_keys($houseInfoList));exit; return array_merge($pageParams, $houseInfoList); }