/** * 获取价格段信息 * * @param $cityId * @param $price * @return array|mixed|null */ public static function getPriceIntervalInfo($cityId, $price) { $priceIntervalInfo = Model_House_HzPriceChoice::get_price($cityId, $price); if (empty($priceIntervalInfo)) { return array(); } return $priceIntervalInfo; }
/** * 获取优惠价格信息 * * @param int $block_id * @param int $city_id * @param int $price * @return array|bool */ public static function hz_get_favorable_price($block_id, $city_id, $price) { $priceIntervalInfo = Model_House_HzPriceChoice::get_price($city_id, $price); if (empty($priceIntervalInfo)) { return false; } $favorablePrice = Model_Choice_HzFavorablePrice::get_favorable($block_id, $city_id, $priceIntervalInfo['id']); return $favorablePrice; }
/** * 根据ID 获取价格段信息 * * @param $id * @return array */ public static function get_price_by_id($id) { try { $priceInfo = Model_House_HzPriceChoice::data_access('')->filter('id', $id)->get_row(); } catch (Exception $e) { return array(); } if (is_null($priceInfo)) { return array(); } return $priceInfo; }
/** * 精选房源设置 * * @param $ajk_broker_id * @param $city_id * @param $prop_id * @param array $params * * @return array */ public static function hz_setting_post($ajk_broker_id, $city_id, $prop_id, $params = array()) { //获取精选推广预算 $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])) { $min_budget = $choiceSet[$brokerCompanyId]['hz']['HZ_CHOICE_MIN_BUDGET']; $max_budget = $choiceSet[$brokerCompanyId]['hz']['HZ_CHOICE_MAX_BUDGET']; } else { $min_budget = $choiceSet['default']['hz']['HZ_CHOICE_MIN_BUDGET']; $max_budget = $choiceSet['default']['hz']['HZ_CHOICE_MAX_BUDGET']; } if ($params['budget'] < $min_budget || $params['budget'] > $max_budget) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '推广预算,最低' . $min_budget . '安币,最高' . $max_budget . '安币'); } $result = array(); $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' => '您不是好租经纪人'); } /** 判断房源是否可以精选 */ $checkProp = Bll_HzBidPlan::checkPropCanChoice($ajk_broker_id, $city_id, $prop_id); if ($checkProp['err_no'] != 0) { return $checkProp; } /** 防并发 */ if (false === self::rejectSameRequest(Bll_Plan_Bid_Choice::SITE_HAOZU, $ajk_broker_id, $prop_id)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-906)'); } /** 获取房源基本信息 */ $propInfo = Model_House_HzProp::get_prop_info_by_prop_id($prop_id); /** 获取点击单价 */ try { /** * @var Bll_Service_Client_HttpResponse $clickPrice */ for ($i = 0; $i < 3; $i++) { $clickPrice = Bll_Service_Choice::hzClickPrice(array('brokerId' => $ajk_broker_id, 'cityId' => $city_id, 'price' => (int) $propInfo['contentBasic']['pricenum'], 'blockId' => $propInfo['contentBasic']['blockid'])); if ($clickPrice->isSucceeded()) { break; } } if (!$clickPrice->isSucceeded() || $clickPrice['status'] == 'error') { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-' . __LINE__ . ')'); } if ($params['budget'] * 100 < $clickPrice['realTradeAmount']) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '推广预算不能小于点击单价'); } /** 点击单价不能小于当前系统内的单价 防止恶意操作 */ if ($params['price'] < $clickPrice['realTradeAmount'] / 100) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '点击单价错误'); } } catch (Exception $e) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-' . __LINE__ . ')'); } $block_id = $propInfo['contentBasic']['blockid']; $priceIntervalInfo = Model_House_HzPriceChoice::get_price($city_id, $propInfo['contentBasic']['pricenum']); if (empty($priceIntervalInfo)) { $logContent = sprintf('%s ajkBrokerId=%d hzBrokerId=%d cityId=%d propId=%d blockId=%d priceNum=%s %s', date('Y-m-d H:i:s'), $ajk_broker_id, $hz_broker_id, $city_id, $prop_id, $block_id, $propInfo['contentBasic']['pricenum'], '好租城市的价格段获取失败'); APF::get_instance()->get_nlogger()->log('好租城市的价格段', $logContent); return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统烦忙(code:-' . __LINE__ . ')'); } /** 获取坑位信息 提前判断坑位状态 没有的话会自动初始化一个 */ $bucketInfo = Bll_Choice_HzBidBucket::getBucketInfo($block_id, $priceIntervalInfo['id']); if (empty($bucketInfo)) { return array('err_no' => self::BID_WAIT_FAIL, 'err_msg' => '精选房源推广失败'); } /** 精选房源展示推广 */ if (isset($params['show']) && $params['show'] == 1) { $result = array('err_no' => self::BID_SHOW_SUCCESS, 'err_msg' => '精选房源推广成功'); if ($bucketInfo['usedNum'] >= $bucketInfo['maxOnlineNum']) { return array('err_no' => self::BID_SHOW_FAIL, 'err_msg' => '精选房源推广失败'); } /** 展示位 坑位自增 */ $lockBucket = Model_Choice_HzBidBucket::increment_used_num_online($block_id, $priceIntervalInfo['id']); if (!$lockBucket) { return array('err_no' => self::BID_SHOW_FAIL, 'err_msg' => '精选房源推广失败'); } } else { $result = array('err_no' => self::BID_WAIT_SUCCESS, 'err_msg' => '精选房源推广成功'); if ($bucketInfo['usedNum'] >= $bucketInfo['totalNum']) { return array('err_no' => self::BID_WAIT_FAIL, 'err_msg' => '推广位已满!'); } /** 排队位置 坑位自增 */ $lockBucket = Model_Choice_HzBidBucket::increment_used_num($block_id, $priceIntervalInfo['id']); if (!$lockBucket) { return array('err_no' => self::BID_WAIT_FAIL, 'err_msg' => '精选房源推广失败'); } } /** 往冻结队列里添加记录,获取request id*/ $bidFreezeOrder = new Bll_Plan_BidFreezeOrderNum(date('Y')); $ajk_user_id = Bll_Broker_MainBusiness::getDataByEsfId($ajk_broker_id)->memberId; $requestId = $bidFreezeOrder->getRequestId(Bll_Plan_BidFreezeOrderNum::HZ, $ajk_user_id, date('Y'), 0, $prop_id); /** 冻结金额 */ $freezeResult = self::hz_bid_freeze($ajk_broker_id, $params['budget'] * 100, $requestId, sprintf('好租精选房源冻结,propId: %d', $prop_id)); if (!$freezeResult->isSucceeded() || $freezeResult['status'] == 'error') { Model_Choice_HzBidBucket::decrement_used_num($block_id, $priceIntervalInfo['id']); return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => isset($freezeResult['info']) ? $freezeResult['info'] : '冻结金额失败'); } $sn = $freezeResult['data']['sn']; if (!isset($params['plan_id']) || empty($params['plan_id'])) { $createdRemark = sprintf('经纪人开始精选房源推广 SN:%s', $sn); $resultPlan = Bll_Plan_Bid_HzBid::add_plan($hz_broker_id, $prop_id, $params['price'], $params['budget'], $block_id, $city_id, $sn, $ajk_broker_id); /** 添加计划失败 */ if ($resultPlan['error_code'] != 0) { Model_Choice_HzBidBucket::decrement_used_num($block_id, $priceIntervalInfo['id']); return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => $resultPlan['error_message']); } $planId = $resultPlan['planId']; } else { $createdRemark = sprintf('经纪人重新推广精选房源 SN:%s', $sn); /** 更新精选房源计划预算 */ $planId = $params['plan_id']; $resultPlan = Bll_Plan_Bid_HzBid::update_bid($hz_broker_id, $planId, $prop_id, $params['price'], $params['budget'], $city_id, $sn, $ajk_broker_id); if ($resultPlan['error_code'] != 0) { Model_Choice_HzBidBucket::decrement_used_num($block_id, $priceIntervalInfo['id']); return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => $resultPlan['error_message']); } $planId = $resultPlan['planId']; } $result['rank'] = Bll_Plan_Bid_HzBid::getChoiceWaitPosition($planId, $city_id, $block_id, $priceIntervalInfo['id']); /** 精选房源成功 */ $actionQueueData = array('siteType' => Model_Choice_ActionQueue::ENUM_HAOZU, 'brokerId' => $ajk_broker_id, 'planId' => $planId, 'proId' => $prop_id, 'actionId' => Model_Choice_ActionQueue::ENUM_BEGIN_BY_HAND, 'createTime' => time(), 'createRemark' => $createdRemark, 'operationId' => $ajk_broker_id, 'ip' => $params['ip']); Model_Choice_ActionQueue::addBidQueen($actionQueueData); $bidFreezeOrder->updateRequestComplete($requestId, $sn, $planId); return $result; }
/** * 精选房源板块变更,修正计划的板块ID * * @param array $queue * @return array */ public static function houseAreaChange($queue) { if ($queue['siteType'] != 2) { return Bll_HzPropBll::build_return(0, '非好租精选队列'); } if ($queue['planId'] == 0 || $queue['proId'] == 0) { return Bll_HzPropBll::build_return(0, '房源Id、计划Id不能为空'); } /** 获取精选计划信息 */ $planInfo = Model_Plan_HzPlanBasic::get_plan_by_id($queue['planId'], true); if (empty($planInfo)) { return Bll_HzPropBll::build_return(1, sprintf('获取计划[%d]信息失败', $queue['planId'])); } if ($planInfo['status'] != Const_HzPlan::SPREAD && $planInfo['status'] != Const_HzPlan::WAITING) { return Bll_HzPropBll::build_return(1, sprintf('计划[%d]不在推广或者排队中', $queue['planId'])); } /** 获取房源基本信息 */ $houseInfo = Model_House_HzProp::get_prop_info_by_prop_id($queue['proId'], true); if (empty($houseInfo)) { return Bll_HzPropBll::build_return(1, '获取房源[%d - %d]信息失败', $planInfo['cityId'], $queue['proId']); } if ($houseInfo['contentBasic']['status'] == 99 || $houseInfo['contentBasic']['status'] == 100) { return Bll_HzPropBll::build_return(1, sprintf('房源已经被删除[%d - %d]', $queue['proId'], $houseInfo['contentBasic']['status'])); } $blockId = $houseInfo['contentBasic']['blockid']; /** 获取价格段Id */ $priceIntervalInfo = Model_House_HzPriceChoice::get_price($planInfo['cityId'], $houseInfo['contentBasic']['pricenum']); if (empty($priceIntervalInfo)) { return Bll_HzPropBll::build_return(1, sprintf('没有获取到价格段信息[%d - %d]', $planInfo['cityId'], $houseInfo['contentBasic']['pricenum'])); } $priceId = $priceIntervalInfo['id']; $data = array('blockId' => $blockId, 'priceId' => $priceId); if (0 == Model_Plan_HzPlanBasic::updatePlan($queue['planId'], $data)) { return Bll_HzPropBll::build_return(1, sprintf('更新精选计划[%d][%s]失败', $queue['planId'], json_encode($data))); } $result = sprintf('更新精选计划[%d][%s]成功', $queue['planId'], json_encode($data)); if (static::updateBucket($blockId, $priceId)) { $result .= ",(新)更新坑位[{$blockId} - {$priceId}]成功"; } else { $result .= ",(新)更新坑位[{$blockId} - {$priceId}]失败"; } if (static::updateBucket($planInfo['blockId'], $planInfo['priceId'])) { $result .= ",(旧)更新坑位[{$planInfo['blockId']} - {$planInfo['priceId']}]成功"; } else { $result .= ",(旧)更新坑位[{$planInfo['blockId']} - {$planInfo['priceId']}]失败"; } return Bll_HzPropBll::build_return(1, $result); }
/** * 108 房源价格变更 * 查选房源信息是否存在 * 如果不存在 返回结束 * 如果存在 记录房源编辑日志 type=2 * 查询该房源的计划关系 * 如果不存在 返回结束 * 如果存在,重新计算定价的底价并更新计划关系表中的底价 * 查询计划 * 如果计划不在推广 返回结束 * 如果计划正在推广或者第二天推广, 记录房源更新日志 type=4 * 处理竞价 */ private function change_prop_price() { $data = self::build_prop_log($this->params, 2, "房源修改价格", $this->params['broker_id']); $houseStatus = json_decode($this->params['remark'], true); $data['remark'] = json_encode(array('oldPrice' => $houseStatus['oldPrice'], 'newPrice' => $houseStatus['price'], 'msg' => $data['remark'])); if (!Model_Log_HouseLogNew::create($data, date('Ymd'))->save()) { throw new Exception_BllErrorException("房源{$this->params['broker_id']}修改价格日志写入失败"); } else { $this->allReturn[] = "房源{$this->params['broker_id']}修改价格日志写入"; } if ($this->params['isComboCity']) { if (!($comboRelation = Bll_Combo_HouseRelation::getOnlineRelationByHouseId($this->params['pro_id']))) { return $this->allReturn[] = "房源{$this->params['pro_id']}套餐关系为空"; } //$this->writePropLog(4, '更新'); } else { // 查询定价关系 if (!($fixPlanning = Model_Plan_HzPlanning::getPropFixPlan($this->params['pro_id']))) { return $this->allReturn[] = "房源{$this->params['pro_id']}定价关系为空"; } // 重新计算低价并更新 $prop = Bll_HzProp::get_prop($this->params['pro_id']); $priceNum = $prop['pricenum']; $cityId = $prop['cityid']; $priceLevel = Model_House_HzPriceChoice::get_price($cityId, $priceNum); $bottomPrice = $priceLevel['price']; Model_Plan_HzPlanning::updatePropPlan($fixPlanning['id'], array('unit_price' => $bottomPrice)); if (in_array($fixPlanning['is_valid'], array(Const_HzPlan::SPREAD, Const_HzPlan::AUTOOVER))) { //$this->writePropLog(4, '更新'); } } $this->tempDoBid(); }
/** * 重新计算坑位数 * 获取精选计划,根据计划的板块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 $out * @return array * @throws Exception */ private static function prepareSimilarPropCompare(&$out) { $compare = array(); // 我的房源 (从昨日往前推一周,此房源的累计有效点击。如遇今日新发房源,则不显示) if ($out['propInfo']['leftDays'] != Const_HzStatus::PROP_EXPIRED) { $propRank = Model_Stats_HzPropRankLastSevenDays::getRankByProId($out['proId']); $compare['myClicks'] = $propRank ? $propRank['totalVPPVLastSevenDays'] : 0; } // 平均点击:从昨日往前推一周,推广过的同类房源的累计有效点击/推广过的房源数 $priceInfo = Model_House_HzPriceChoice::get_price($out['cityId'], $out['propInfo']['pricenum']); $subregionPrice = Model_Stats_HzSubregionPriceLastSevenDaysSummary::getSubregionPrice($out['propInfo']['typeCode'], $priceInfo ? $priceInfo['id'] : 0); $compare['averageClicks'] = $subregionPrice && $subregionPrice['totalPmPropLastWeek'] ? (int) ($subregionPrice['totalVPPVLastWeek'] / $subregionPrice['totalPmPropLastWeek']) : 0; // 最受欢迎房子 最受欢迎房源:从昨日往前推一周,在线过的同类房源的累计有效点击最高的那套房源的点击量 $compare['welcomePropClicks'] = $subregionPrice ? $subregionPrice['maxVPPV'] : 0; // 您领先了 领先了XX%的同类房源:=(1 - A/B)*100% (比值取小数点后两位,四舍五入)如遇今日新发房源,则不显示。 // A=从昨日往前推一周,此房源的累计有效点击在所有推广过同类房源中的排名。 // B=从昨日往前推一个星期,同类房源中所有推广过的房源数 if (!isset($propRank) || !$propRank || !isset($subregionPrice) || !$subregionPrice) { $compare['lead'] = false; } else { $a = $propRank ? $propRank['rank'] : 0; $b = $subregionPrice ? $subregionPrice['totalPmPropLastWeek'] : 0; $compare['lead'] = $b ? number_format(1 - $a / $b, 2) * 100 . '%' : 100 . '%'; } return $compare; }
/** * 根据租金价格,返回点击单价 * @param $cityId * @param $price * @return array */ public static function getUnitPrice($cityId, $price) { $result = Model_House_HzPriceChoice::get_price($cityId, $price); return $result ? $result : 0; }
/** * 组装未推广列表 取出所有-有效定价房源 * @param $out * @return array */ private static function prepareOutList(&$out) { $outList = array(); $outPropIds = array(); $fixProIds = array_keys($out['props']); // 取出经纪人所有非删除房源 (分表) $allSearchProps = Model_House_HzPropSearch::getPropLists($out['cityId'], array(array('ajkBrokerId', '=', $out['ajkBrokerId']), array('status', '<>', Const_HzStatus::DELETE), array('status', '<>', Const_HzStatus::OFFLINE), array('status', '<>', Const_HzStatus::OUTPORT), array('status', '<>', Const_HzStatus::HIBERNATE), array('status', '<>', Const_HzStatus::REMOVE), array('status', '<>', Const_HzStatus::EXPIRED)), 1000, array('created', 'desc')); if (empty($allSearchProps)) { return array(); } // 获取城市价格段 $allPrices = Model_House_HzPriceChoice::getAllPriceByCityId($out['cityId']); $out['getQualityProIds'] = array(); foreach ($allSearchProps as $allSearchProp) { $proId = $allSearchProp['proid']; $out['getQualityProIds'][] = $proId; // 过滤非删除状态定价 if (in_array($proId, $fixProIds)) { continue; } $outList[$proId] = $allSearchProp; // 获取剩余时间 $outList[$proId]['leftDays'] = Bll_House_HzHouse::getLeftDays($allSearchProp['created']); $outPropIds[] = $proId; } // 获取改经纪人所有房源质量 $out['propsQuality'] = Model_Stats_HzPropQuality::getPropsquality($out['getQualityProIds']); // 获取如是违规房源 拼接违规原因 $outList = Bll_HzProp::checkAndGetPropsIllegalInfos($outList); // 批量获取主表信息 if (empty($outPropIds)) { return array(); } $props = Model_House_HzProp::getPropsByPropIds($outPropIds); if (!$props) { return array(); } // 房源主分表信息合并 foreach ($outList as $proId => $outProp) { $outList[$proId] = array_merge($outList[$proId], $props[$proId]); // 计算点击价格 if (!empty($allPrices)) { foreach ($allPrices as $priceInfo) { if ($priceInfo['lower'] < $outList[$proId]['pricenum'] && $priceInfo['upper'] >= $outList[$proId]['pricenum']) { $outList[$proId]['unitPrice'] = $priceInfo['price']; break; } } } } return $outList; }
/** * 精选房子计算:默认(0)/可推广(1)/可排队(2)/已排满(3) * @param $proInfos * @param $cityId * @return array */ public static function getPropChoiceStatus($proInfos, $cityId) { if (empty($proInfos)) { return array(); } $priceIds = Model_House_HzPriceChoice::getAllPriceByCityId($cityId); if (empty($priceIds)) { return array(); } $result = array(); $choiceStatus = array(); foreach ($proInfos as $propInfo) { // 取价格段id $priceNum = isset($propInfo['priceNum']) ? $propInfo['priceNum'] : $propInfo['pricenum']; $propInfo['priceId'] = 0; foreach ($priceIds as $priceInfo) { if ($priceInfo['lower'] < $priceNum && $priceInfo['upper'] >= $priceNum) { $propInfo['priceId'] = $priceInfo['id']; break; } } $propInfo['blockId'] = isset($propInfo['blockId']) ? $propInfo['blockId'] : $propInfo['blockid']; // 获取精选状态 if ($bidBucket = Model_Choice_HzBidBucket::get_bucket_info($propInfo['blockId'], $propInfo['priceId'])) { if ($bidBucket['usedNum'] < $bidBucket['maxOnlineNum']) { $choiceStatus['choiceStatus'] = 1; $choiceStatus['choiceMsg'] = '可推广'; } elseif ($bidBucket['usedNum'] < $bidBucket['totalNum']) { $choiceStatus['choiceStatus'] = 2; $choiceStatus['choiceMsg'] = '可排队'; } else { $choiceStatus['choiceStatus'] = 3; $choiceStatus['choiceMsg'] = '已排满'; } } else { $choiceStatus['choiceStatus'] = 1; $choiceStatus['choiceMsg'] = '可推广'; } $result[$propInfo['proId']] = $choiceStatus; } return $result; }