public function handle_request() { if ($this->_cityId == 0) { $this->setLog('city Id 为必须传的参数'); return; } if (!isset($this->_solrCityMapping[$this->_cityId])) { $this->setLog(sprintf('cityId[%d] 对应的solr配置不存在', $this->_cityId)); return; } $searchParams = array('__test__' => __CLASS__ . time(), 'fl' => 'id', 'q' => '*:*', 'rows' => 10000, 'wt' => 'json'); $fieldQuery = array('fq=' . urlencode('is_hp:1'), 'fq=' . urlencode(sprintf('city_id:%d', $this->_cityId))); $query = http_build_query($searchParams); $url = $this->getSolrUrl($this->_cityId) . '?' . $query . '&' . implode('&', $fieldQuery); $houseInSolrTemp = $this->httpRequest($url); if (empty($houseInSolrTemp)) { $this->setLog('在solr中的没有房源'); return; } foreach ($houseInSolrTemp as $house) { $houseId = $house['id']; $this->setLog(sprintf('开始处理房源[%d]', $houseId)); $housePlanning = Model_Plan_HzPlanning::getPropBidPlan($houseId, true); if (!empty($housePlanning)) { $ajkBrokerId = $housePlanning['ajkBrokerId']; $choicePlan = Model_Plan_HzPlanBasic::get_plan_by_id($housePlanning['plan_id'], true); $this->setLog(sprintf('房源[%d]的精选计划[%d]信息[bid_version=%d, status=%d]', $houseId, $housePlanning['plan_id'], $choicePlan['bid_version'], $choicePlan['status'])); if (!empty($choicePlan) && $choicePlan['bid_version'] == Const_HzPlan::BID_TYPE && $choicePlan['status'] == Const_HzPlan::SPREAD) { continue; } } else { $this->setLog(sprintf('没有获取到房源[%d]的计划关系信息', $houseId)); $propSearchInfo = Model_House_HzPropSearch::get_prop_by_prop_id($this->_cityId, $houseId); if (empty($propSearchInfo) || $propSearchInfo['ajkBrokerId'] == 0) { $this->setLog(sprintf('没有获取到房源[%d]的经纪人ID', $houseId)); continue; } $ajkBrokerId = $propSearchInfo['ajkBrokerId']; } $this->setLog(sprintf('需要下架房源 [%d - %d - %d]', $houseId, $ajkBrokerId, $this->_cityId)); // $res = Bll_Combo_NoticeSolrUpDown::noticeChoiceSolrZfAPI($this->_cityId, $ajkBrokerId, $houseId, 2, 2, Bll_Combo_NoticeSolrUpDown::HLSFromChoiceUpDown, time()); // $this->setLog('通知solr res: ' . json_encode($res)); } }
/** * 判断房源是否可以参加精选房源推广 * * @param $ajkBrokerId * @param $cityId * @param $propId * @return array */ public static function checkPropCanChoice($ajkBrokerId, $cityId, $propId) { $propSearch = Model_House_HzPropSearch::get_prop_by_prop_id($cityId, $propId); if (empty($propSearch)) { return self::buildReturn(Bll_Plan_Bid_Choice::BID_FAIL_OTHER, '房源不存在'); } /** 判断房源是否是当前经纪人的房源 */ if ($propSearch['ajkBrokerId'] != $ajkBrokerId) { return self::buildReturn(Bll_Plan_Bid_Choice::BID_FAIL_OTHER, '房源不存在(code:-10086)'); } /** 判断是否是精选开放城市 */ if (!Bll_City::isChoiceIndependentCity($cityId, Const_Site::HAOZU)) { /** 判断房源是否在套餐推广中 */ if (!Bll_Combo_HouseRelation::getOnlineRelationByHouseId($propId, Bll_Combo_HouseRelation::SITE_TYPE_HZ)) { return array('err_no' => Bll_Plan_Bid_Choice::BID_FAIL_OTHER, 'err_msg' => '房源必须套餐推广才能参与精选推广'); } } /** 判断房源是否多图 */ if ($propSearch['islabel'] == 0) { return self::buildReturn(Bll_Plan_Bid_Choice::BID_FAIL_QUALITY_OR_NEW, '多图、新发15天房源才能参与精选推广'); } /** 判断房源是否是在15天内发布的 */ if (date('ymd', strtotime('-16 days')) > date('Ymd', $propSearch['created'])) { return self::buildReturn(Bll_Plan_Bid_Choice::BID_FAIL_QUALITY_OR_NEW, '多图、新发15天房源才能参与精选推广'); } /** 判断房源是否已经在竞价计划中了 取master */ $propBidInfo = Model_Plan_HzPlanning::getPropBidPlan($propId, true); if (!empty($propBidInfo)) { $planBasic = Model_Plan_HzPlanBasic::get_plan_by_id($propBidInfo['plan_id'], true); if ($planBasic['bid_version'] == Const_HzPlan::BID_VERSION_CHOICE && in_array($planBasic['status'], array(Const_HzPlan::SPREAD, Const_HzPlan::WAITING))) { return self::buildReturn(Bll_Plan_Bid_Choice::BID_FAIL_OTHER, '该房源已经处于精选状态,请先删除'); } } return array('err_no' => 0, 'err_msg' => ''); }
/** * 查询房源的精选(竞价)信息 * * @param $list * @return array */ private function getProBidInfo($list) { static $_cache = array(); if (isset($_cache[$list['id']])) { return $_cache[$list['id']]; } $bidInfo = array(); //根据房源去查询计划信息 if ($list['siteType'] == 1) { //二手房 $ajkBidInfo = Model_Plan_AjkPropspread::getAjkPropspreadByProId($list['houseId']); if (!empty($ajkBidInfo)) { $bidInfo['bidVersion'] = $ajkBidInfo['bidVersion']; $bidInfo['bidId'] = $ajkBidInfo['id']; } } elseif ($list['siteType'] == 2) { //租房 $hzBidId = Model_Plan_HzPlanning::getPropBidPlan($list['houseId']); if (!empty($hzBidId)) { //查询计划信息 $hzBidInfo = Model_Plan_HzPlanBasic::get_plan_by_id($hzBidId['plan_id']); if (!empty($hzBidInfo) && in_array($hzBidInfo['status'], array(Const_HzPlan::SPREAD, Const_HzPlan::AUTOOVER, Const_HzPlan::MENUOVER, Const_HzPlan::PAUSE, Const_HzPlan::AWAIT, Const_HzPlan::UPPERLIMIT, Const_HzPlan::ENDTIME, Const_HzPlan::WAITING)) || $hzBidInfo['flag'] != 1) { $bidInfo['bidVersion'] = $hzBidInfo['bid_version']; $bidInfo['bidId'] = $hzBidInfo['id']; } } } elseif ($list['siteType'] == 3) { //金铺 $jpBidInfo = Model_Plan_Jp::getBidPlanByHouseIdV2($list['houseId']); if (!empty($jpBidInfo)) { $bidInfo['bidVersion'] = $jpBidInfo->bidVersion; $bidInfo['bidId'] = $jpBidInfo->id; } } $_cache[$list['id']] = $bidInfo; return $bidInfo; }
/** * 精选房源设置页面 * * @param int $ajk_broker_id * @param int $city_id * @param int $prop_id * @param array $params * * @return array */ public static function hz_setting($ajk_broker_id, $city_id, $prop_id, $params = array()) { $pageAttribute = array('broker_id' => $ajk_broker_id, 'prop_id' => $prop_id); //获取精选推广预算 $brokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($ajk_broker_id); $brokerCompanyId = $brokerInfo['BaseInfo']['COMPANYID']; $choiceSet = APF::get_instance()->get_config('choice_set'); if (isset($choiceSet[$brokerCompanyId]) && !empty($choiceSet[$brokerCompanyId])) { $pageAttribute['min_budget'] = $choiceSet[$brokerCompanyId]['hz']['HZ_CHOICE_MIN_BUDGET']; $pageAttribute['max_budget'] = $choiceSet[$brokerCompanyId]['hz']['HZ_CHOICE_MAX_BUDGET']; } else { $pageAttribute['min_budget'] = $choiceSet['default']['hz']['HZ_CHOICE_MIN_BUDGET']; $pageAttribute['max_budget'] = $choiceSet['default']['hz']['HZ_CHOICE_MAX_BUDGET']; } $hz_broker_id = Model_Broker_HzMapping::get_hz_broker_id($ajk_broker_id); if (0 == $hz_broker_id) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '您不是好租经纪人'); } /** 经纪人重新推广房源 */ if (isset($params['act']) && $params['act'] == 'rebid') { $planInfo = Model_Plan_HzPlanBasic::get_plan_by_id($params['plan_id']); if ($planInfo['plan_type'] != 2 || $planInfo['bid_version'] != 2) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源所在的计划不是精选房源计划'); } if ($planInfo['status'] == Const_HzPlan::WAITING || $planInfo['status'] == Const_HzPlan::SPREAD) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源已经精选'); } $pageAttribute['plan_id'] = $params['plan_id']; $pageAttribute['rebid'] = true; } else { $propPlan = Model_Plan_HzPlanning::getPropBidPlan($prop_id); if (!empty($propPlan)) { $planInfo = Model_Plan_HzPlanBasic::get_plan_by_id($propPlan['plan_id']); if ($planInfo['bid_version'] == Const_HzPlan::BID_VERSION_CHOICE && ($planInfo['status'] == Const_HzPlan::WAITING || $planInfo['status'] == Const_HzPlan::SPREAD)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源已经精选'); } if ($planInfo['bid_version'] == Const_HzPlan::BID_VERSION_CHOICE && $propPlan['is_valid'] != 0 && $planInfo['status'] != Const_HzPlan::DELETE && $planInfo['flag'] == 1) { $pageAttribute['plan_id'] = $propPlan['plan_id']; $pageAttribute['rebid'] = true; } else { /** 检查 经纪人是不是 已经满足10套 */ $onlinePlanCount = Model_Plan_HzPlanBasic::count_online_bid_plan_ex($ajk_broker_id); if ($onlinePlanCount >= self::ALL_ZF_PLAN_NUM) { return array('err_no' => Bll_Plan_Bid_Choice::BID_FAIL_OTHER, 'err_msg' => '您最多可以对' . self::ALL_ZF_PLAN_NUM . '套房源做精选推广,请确认数量是否已经达到上限'); } } } } /** 获取房源基本信息 */ $propInfo = Model_House_HzProp::get_prop_info_by_prop_id($prop_id); if (empty($propInfo)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源不存在(code:-3)'); } if (empty($propInfo['contentBasic']) || !isset($propInfo['contentBasic']['userid']) || $propInfo['contentBasic']['userid'] != $hz_broker_id) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源不存在(code:-2)'); } if (false == $propInfo['contentBasic']['quality']) { return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '多图、新发15天房源才能参与精选推广'); } if (date('Ymd', strtotime('-15 days')) > date('Ymd', $propInfo['contentBasic']['created'])) { return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '多图、新发15天房源才能参与精选推广'); } /** 判断是否是精选开放城市 */ if (!Bll_City::isChoiceIndependentCity($city_id, Const_Site::HAOZU)) { /** 判断房源是否在套餐推广 */ $propCombos = Bll_Combo_HouseRelation::getOnlineRelationByHouseId($prop_id, Bll_Combo_HouseRelation::SITE_TYPE_HZ); if (empty($propCombos)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源必须在套餐推广才能参与精选'); } } $balance = self::get_broker_balance_by_broker_id($ajk_broker_id); $pageAttribute['balance'] = $balance; if ($balance > 0) { $balance = sprintf('%.2f', $balance / 100); } $pageAttribute['balance_fmt'] = $balance; /** * renttype: 1整租 2合租 */ if (empty($propInfo['contentBasic'])) { return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '房源不存在(code:-4)'); } /** 出租方式 */ $rent_type = $propInfo['contentBasic']['renttype'] == 1 ? '整租' : '合租'; /** 房屋类型 */ $house_type_config = APF::get_instance()->get_config('housetype', 'house'); $house_type = isset($house_type_config[$city_id]) ? $house_type_config[$city_id] : $house_type_config[0]; $prop_type = isset($house_type[$propInfo['contentBasic']['protype']]) ? $house_type[$propInfo['contentBasic']['protype']] : '其他'; /** 户型 */ $room_amount = $propInfo['contentBasic']['roomnum']; $hall_amount = $propInfo['contentBasic']['hallnum']; $toilet_amount = $propInfo['contentBasic']['toilnetnum']; /** 出租面积 */ $area_amount = $propInfo['contentBasic']['areanum']; /** 租金 */ $price = $propInfo['contentBasic']['pricenum']; $title = $propInfo['contentBasic']['commname']; $blockInfo = Model_City_HzArea::getAreaById($propInfo['contentBasic']['blockid']); if (empty($blockInfo)) { $blockName = $title; } else { $blockName = $blockInfo['typeName']; } $pageAttribute['community_name'] = $blockName; /** 设置标题 */ $pageAttribute['title'] = sprintf('%s,%d室%d厅%d卫,%d平,%s,%s,%d元/月', $title, $room_amount, $hall_amount, $toilet_amount, $area_amount, $rent_type, $prop_type, $price); $bucketInfo = Bll_Choice_HzBidBucket::get_bucket_info($propInfo['contentBasic']['blockid'], $city_id, $propInfo['contentBasic']['pricenum']); $pageAttribute['bucket_total'] = $bucketInfo['totalNum']; $pageAttribute['bucket_used'] = $bucketInfo['usedNum']; // 取出area的areacode 取查询 (由于dw存的blockid是areacode) $area = Model_City_HzArea::getAreaById($propInfo['contentBasic']['blockid']); $averageClickAndBudget = Bll_Choice_HzBidBucket::getBucketAverageClickBudget($area['typeCode'], $city_id, $propInfo['contentBasic']['pricenum']); if (!empty($averageClickAndBudget)) { $pageAttribute['averageClick'] = $averageClickAndBudget['averageClick']; $pageAttribute['averageBudget'] = $averageClickAndBudget['averageBudget'] / 100; } /** 获取点击单价 */ try { $clickPrice = Bll_Service_Choice::hzClickPrice(array('brokerId' => $ajk_broker_id, 'cityId' => $city_id, 'price' => (int) $propInfo['contentBasic']['pricenum'], 'blockId' => $propInfo['contentBasic']['blockid'])); if ($clickPrice['status'] == 'error') { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-1)'); } } catch (Exception $e) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-33)'); } if ($clickPrice['realTradeAmount'] != $clickPrice['shouldTradeAmount']) { $pageAttribute['favorable'] = true; $pageAttribute['price'] = round($clickPrice['realTradeAmount'] / 100, 2); $pageAttribute['origin_price'] = round($clickPrice['shouldTradeAmount'] / 100, 2); $pageAttribute['favorable_end_time'] = isset($clickPrice['rebateEndTime']) ? $clickPrice['rebateEndTime'] : ''; } else { $pageAttribute['favorable'] = false; $pageAttribute['price'] = round($clickPrice['realTradeAmount'] / 100, 2); } $pageAttribute['bucket_used_num'] = $bucketInfo['usedNum']; $pageAttribute['bucket_total_num'] = $bucketInfo['totalNum']; $pageAttribute['bucket_max_online_num'] = $bucketInfo['maxOnlineNum']; $pageAttribute['hidden']['show'] = $bucketInfo['maxOnlineNum'] > $bucketInfo['usedNum'] ? 1 : 0; $priceInfo = Model_House_HzPriceChoice::get_price_by_id($bucketInfo['priceId']); if (($pos = strpos('以', $priceInfo['title'])) !== false) { $priceInfo['title'] = substr($priceInfo['title'], 0, $pos) . '元' . substr($priceInfo['title'], $pos); } else { $priceInfo['title'] = $priceInfo['title'] . '元'; } $pageAttribute['price_title'] = $priceInfo['title']; return $pageAttribute; }
/** * 写房源日志,通知solr下架房源 * * @param array $queue * @return array */ public static function notifySolrUpDown($queue) { $propPlanning = Model_Plan_HzPlanning::getPropBidPlan($queue['proId']); if (empty($propPlanning)) { $queue['cityId'] = Model_Broker_AjkBrokerExtend::getCityIdByBrokerId($queue['brokerId']); return static::notifySolr($queue, Const_ProLogType::LOG_CHOICE_NOFITY_SOLR_DOWN, '没有获取到房源精选关系-下架'); } $planId = $propPlanning['plan_id']; $planInfo = Model_Plan_HzPlanBasic::get_plan_by_id($planId); if (empty($planInfo)) { return static::notifySolr($queue, Const_ProLogType::LOG_CHOICE_NOFITY_SOLR_DOWN, '没有获取到房源精选计划-下架'); } $queue['planId'] = $planId; $queue['cityId'] = $planInfo['cityId']; if ($planInfo['status'] == Const_HzPlan::SPREAD) { return static::notifySolr($queue, Const_ProLogType::LOG_CHOICE_NOFITY_SOLR_UP, '精选推广-上架'); } return static::notifySolr($queue, Const_ProLogType::LOG_CHOICE_NOFITY_SOLR_DOWN, '精选推广-下架'); }
/** * 重新计算坑位数 * 获取精选计划,根据计划的板块id、价格段id重新计算坑位信息。 * 从房源信息里获取到新的板块id、价格段id,更新计划的板块id、价格段id,重新计算坑位信息. * * @param int $houseId * @param int $cityId * @return string */ public static function rebuildBucketHz($houseId, $cityId) { $houseChoicePlan = Model_Plan_HzPlanning::getPropBidPlan($houseId); if (empty($houseChoicePlan)) { return '房源没有做精选'; } $choicePlanInfo = Model_Plan_HzPlanBasic::get_plan_by_id($houseChoicePlan['plan_id']); if (empty($choicePlanInfo)) { return '没有获取到精选计划'; } if ($choicePlanInfo['status'] != Const_HzPlan::SPREAD && $choicePlanInfo['status'] != Const_HzPlan::WAITING) { return '房源精选不在推广或排队中'; } $propInfo = Model_House_HzProp::get_prop_info_by_prop_id($houseId); $blockId = $propInfo['contentBasic']['blockid']; $priceIntervalInfo = Model_House_HzPriceChoice::get_price($cityId, $propInfo['contentBasic']['pricenum']); if (empty($priceIntervalInfo)) { return '没有获取到价格段信息'; } $priceId = $priceIntervalInfo['id']; $data = array('blockId' => $blockId, 'priceId' => $priceId); if (0 == Model_Plan_HzPlanBasic::updatePlan($houseChoicePlan['plan_id'], $data)) { return "更新精选计划[{$houseChoicePlan['plan_id']}]信息失败[{$blockId} - {$priceId}]"; } $result = ''; if (static::updateBucket($blockId, $priceId)) { $result .= "(新)更新坑位[{$blockId} - {$priceId}]成功"; } else { $result .= "(新)更新坑位[{$blockId} - {$priceId}]失败"; } if (static::updateBucket($choicePlanInfo['blockId'], $choicePlanInfo['priceId'])) { $result .= "(旧)更新坑位[{$choicePlanInfo['blockId']} - {$choicePlanInfo['priceId']}]成功"; } else { $result .= "(旧)更新坑位[{$choicePlanInfo['blockId']} - {$choicePlanInfo['priceId']}]失败"; } return $result; }
/** * 获取房源计划信息 * * @param $propId * @return array */ public static function getPropPlanType($propId) { $propFixPlan = Model_Plan_HzPlanning::getPropFixPlan($propId); $propBidPlan = Model_Plan_HzPlanning::getPropBidPlan($propId); $result = array(); if (!empty($propFixPlan)) { $result['fix'] = array('isValid' => $propFixPlan['is_valid'], 'planId' => $propFixPlan['plan_id']); $result['type'] = 1; } if (!empty($propBidPlan)) { $result['bid'] = array('isValid' => $propBidPlan['is_valid'], 'planId' => $propBidPlan['plan_id']); $result['type'] = 2; } if (!empty($propBidPlan) && !empty($propFixPlan)) { $result['type'] = 3; } return $result; }
public function getChoicePlan() { // 获取房源和计划关系 $planRelation = Model_Plan_HzPlanning::getPropBidPlan($this->propId); if (!$planRelation) { return null; } // 获取计划 $plan = Model_Plan_HzPlanBasic::get_plan_by_id($planRelation['plan_id']); if (!$plan) { return null; } // 判断是否精选 if ($plan->bid_version != 2) { return null; } return $plan; }
/** * 添加竞价计划 * 往 `promotion_planning_basic` 里 添加一条记录,往 `promotion_planning_extend` 添加一条记录 * 房源计划关系表`promotion_prop_planning`里一个房源只能有2个记录,一个定价,一个竞价,所以先判断房源在 * 该表里是否已经有竞价计划记录了,有则更新,没有就添加。 * * @param int $brokerId * @param int $propId * @param float $price * @param float $amount * @param int $blockId * @param int $cityId * @param int $sn * @param int $ajk_broker_id * @return array|int|mixed */ public static function insertBidPlan($brokerId, $propId, $price, $amount, $blockId, $cityId, $sn, $ajk_broker_id = 0) { $prop = Model_House_HzProp::get_prop_info_by_prop_id($propId); $priceInterval = Model_House_HzPriceChoice::get_price($cityId, $prop['contentBasic']['pricenum']); $planBasicData = array('plan_title' => '精选', 'blockId' => $blockId, 'priceId' => $priceInterval['id'], 'plan_type' => Const_HzPlan::BID_TYPE, 'user_id' => $brokerId, 'amount' => $amount, 'status' => Const_HzPlan::WAITING, 'created' => time(), 'stop_date' => strtotime('+14 days'), 'order_update' => time(), 'cityId' => $cityId, 'bid_version' => Const_HzPlan::BID_VERSION_CHOICE, 'ajkBrokerId' => $ajk_broker_id); $planId = Model_Plan_HzPlanBasic::addPlan($planBasicData); if ($planId == 0) { return 0; } Bll_Log_EffectPlanLog::addPlanLog(Const_HzPlan::BID_TYPE, $planId, $propId, Const_HaoPanLog::PROPSTARTBID, $brokerId, 0, Const_HzPlan::WAITING, Bll_Log_EffectPlanLog::OPERATION_CHOICE); $extendData = array('plan_id' => $planId, 'start_date' => time(), 'created' => time(), 'end_date' => strtotime('+14 days'), 'sn' => $sn); Model_Plan_HzPlanExtend::addPlanExtend($extendData); $propPlanInfo = Model_Plan_HzPlanning::getPropBidPlan($propId); if (!empty($propPlanInfo)) { $propPlan = array('plan_id' => $planId, 'unit_price' => $price, 'is_valid' => Const_HzPlan::WAITING, 'current_day' => date("Ymd"), 'ajkBrokerId' => $ajk_broker_id, 'last_update' => date("Y-m-d H:i:s")); Model_Plan_HzPlanning::updatePropPlan($propPlanInfo['id'], $propPlan); } else { $propPlan = array('proid' => $propId, 'plan_id' => $planId, 'plan_type' => 2, 'unit_price' => $price, 'is_valid' => Const_HzPlan::WAITING, 'created' => time(), 'city_id' => $cityId, 'current_day' => date("Ymd"), 'user_id' => $brokerId, 'ajkBrokerId' => $ajk_broker_id); Model_Plan_HzPlanning::addPropPlan($propPlan); } return $planId; }