public function run() { //获取精选符合的精选计划 $planInfos = Model_Plan_Jp::getValidChoicePlanByCursor($this->cursor, $this->limit); //无需要处理的数据 if (empty($planInfos)) { $this->setShStopFlag(); $this->setCursor(0); $this->logQuit("无需要处理的数据."); } foreach ($planInfos as $plan) { $cityId = $plan->cityId; $houseType = $plan->houseType; /** 获取房源基本信息 */ $propInfo = Bll_House_JpHouseInfo::getHouseInfoById($plan->houseId); /** 获取价格信息 **/ $arrPrice = Bll_House_JpHouseInfo::getPrice($cityId, $propInfo['base']['houseType'], $propInfo['info']); //获取二手房经纪人id $mainBusiness = Model_Broker_MainBusiness::getMainBusinessByJpBrokerId($plan['memberId'], false); //获取点击单击 $apiParams = array('brokerId' => $mainBusiness['ajkBrokerid'], 'cityId' => $cityId, 'price' => $arrPrice['price'] ?: 0, 'blockId' => $plan->blockId, 'newBlockId' => $plan->newBlockId, 'houseType' => $houseType); $clickPrice = Bll_Service_Choice::jpClickPrice($apiParams); if ($clickPrice['status'] == 'error') { $this->logQuit(sprintf('计划%d获取对应的点击单价失败', $plan->id)); } $spreadPrice = $clickPrice['realTradeAmount']; //更新点击单价 $oldSpreadPrice = $propInfo['info']->spreadPrice; $propInfo['info']->spreadPrice = $spreadPrice; $propInfo['info']->save(); $this->addLogger(sprintf("计划%dspreadPrice修改,%d=>%d", $plan->id, $oldSpreadPrice, $spreadPrice)); //更新游标 $this->setCursor($plan->id); } }
public function handle_request() { $zeroOfferPlanList = Model_Plan_EsfAjkPropSpread::scanPlan0Offer($this->_startId, self::BATCH_LIMIT); if (empty($zeroOfferPlanList)) { $this->logMsg(sprintf('startId: %d 没有获取到计划。', $this->_startId)); file_put_contents($this->_doneFile, 'DONE'); } foreach ($zeroOfferPlanList as $planInfo) { $cityId = $planInfo['cityId']; $houseId = $planInfo['propId']; $planId = $planInfo['id']; $brokerId = $planInfo['brokerId']; $houseInfo = Bll_House_EsfHouse::getHouseBaseInfoEx($houseId, $planInfo['cityId']); if (empty($houseInfo)) { $this->logMsg(sprintf('经纪人[%d] 城市[%d] 房源[%d]没有找到,计划[%d]', $brokerId, $cityId, $houseId, $planId)); continue; } $housePrice = $houseInfo['proPrice'] * 10000; /** * 获取小区价格段出价 */ $clickPrice = Bll_Service_Choice::ajkClickPrice(array('brokerId' => $planInfo['brokerId'], 'cityId' => $cityId, 'price' => $housePrice, 'commId' => $houseInfo['commId'])); if ($clickPrice['status'] == 'error') { $this->logMsg(sprintf('经纪人[%d] 城市[%d] 房源[%d] 计划[%d] 小区[%d] 价格[%d] 获取点击价格失败', $brokerId, $cityId, $houseId, $planId, $houseInfo['commId'], $housePrice)); continue; } if ($clickPrice['realTradeAmount'] != $clickPrice['shouldTradeAmount']) { $offer = $clickPrice['realTradeAmount']; } else { $offer = $clickPrice['realTradeAmount']; } file_put_contents($this->_doneFile, 'DONE'); $this->logMsg(sprintf('经纪人[%d] 城市[%d] 房源[%d] 计划[%d] 小区[%d] 价格[%d] 出价[%d]', $brokerId, $cityId, $houseId, $planId, $houseInfo['commId'], $housePrice, $offer)); continue; if (!Model_Plan_EsfAjkPropSpread::updateOffer($planId, $offer)) { $this->logMsg(sprintf('经纪人[%d] 城市[%d] 房源[%d] 计划[%d] 小区[%d] 价格[%d] 更新出价失败', $brokerId, $cityId, $houseId, $planId, $houseInfo['commId'], $housePrice)); continue; } $this->logMsg(sprintf('经纪人[%d] 城市[%d] 房源[%d] 计划[%d] 小区[%d] 价格[%d] 更新出价成功', $brokerId, $cityId, $houseId, $planId, $houseInfo['commId'], $housePrice)); } if (count($zeroOfferPlanList) < self::BATCH_LIMIT) { file_put_contents($this->_doneFile, 'DONE'); } }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $houseId = $this->_params['propId']; $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$brokerInfo) { throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } $cityId = $brokerInfo->cityId; $isDisplaySummary = 0; if (!Bll_City::isChoiceCity($cityId, Const_Site::HAOZU)) { $data = array('totalClicks' => 0, 'balance' => 0, 'balanceUnit' => '元', 'todayClicks' => 0, 'todayConsume' => 0, 'todayConsumeUnit' => '元', 'clickPrice' => 0, 'clickPriceUnit' => '元', 'maxBucketNum' => 0, 'usedBucketNum' => 0, 'bucketId' => '', 'status' => bll_choice_EsfAPPAPIChoice::PROP_ACTIONTYPE_CHOICE_NOTFIT, 'statusMsg' => '你所在城市未开通精选业务', 'remindStatus' => -1, 'remindStatusMsg' => '不符合精选订阅条件', 'minChoicePrice' => 0, 'minChoicePriceUnit' => '元', 'maxChoicePrice' => 0, 'maxChoicePriceUnit' => '元', 'isDisplaySummary' => $isDisplaySummary); return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data); } $isDisplaySummary = 1; //获取该房子的精选计划 $bllChoice = new Bll_Zufang_Choice(); $planInfo = $bllChoice->get_plan_by_proid($houseId); $amount = 0; $totalConsume = 0; if ($planInfo) { $planId = $planInfo->plan_id; $planBasicInfo = $bllChoice->get_plan($planId); $amount = $planBasicInfo[0]->amount; $totalConsume = $planBasicInfo[0]->total_consume; } //获取 blockId, priceId $propInfo = $bllChoice->get_prop_content($houseId); if (empty($propInfo)) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '房源不存在'); } $content = json_decode($propInfo[0]->contentBasic, true); $price = intval($content['pricenum']); $blockId = $content['blockid']; $priceInfo = Bll_Choice_HzBidBucket::getPriceIntervalInfo($cityId, $price); $priceId = $priceInfo['id']; //获取坑位信息 $bucketInfo = Bll_Choice_HzBidBucket::getBucketInfo($blockId, $priceId); // 获取点击单价 try { $clickPriceInfo = Bll_Service_Choice::hzClickPrice(array('cityId' => $cityId, 'price' => (int) $price, 'blockId' => $blockId, 'brokerId' => $brokerId)); if ($clickPriceInfo['status'] == 'error') { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '系统繁忙(code:-33)'); } } catch (Exception $e) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '系统繁忙(code:-33)'); } $clickPrice = $clickPriceInfo['realTradeAmount'] / 100; $remindStatus = -1; // -1 不符合精选订阅条件 $remindStatusMsg = '不符合精选订阅条件'; if ($planInfo && $planInfo->is_valid == 1) { $date = date('Ymd'); $propChoice = $bllChoice->get_prop_choice_info($houseId, $date, $cityId); $todayClicks = intval($propChoice[0]['bidClicks']); $todayConsume = intval($propChoice[0]['bidConsume']) / 100; $totalClicksInfo = $bllChoice->get_prop_choice_clicks($houseId, $cityId); $totalClicks = intval($totalClicksInfo[0]['bidClicks']); $balance = $amount - $totalConsume; return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('todayClicks' => $todayClicks, 'todayConsume' => round($todayConsume, 2), 'todayConsumeUnit' => '元', 'totalClicks' => $totalClicks, 'balance' => round($balance, 2), 'balanceUnit' => '元', 'clickPrice' => round($clickPrice, 2), 'clickPriceUnit' => '元', 'maxBucketNum' => 20, 'usedBucketNum' => $bucketInfo['usedNum'], 'minChoicePrice' => 20, 'minChoicePriceUnit' => '元', 'maxChoicePrice' => 50, 'maxChoicePriceUnit' => '元', 'status' => '1-1', 'statusMsg' => '推广中', 'remindStatus' => $remindStatus, 'remindStatusMsg' => $remindStatusMsg, 'isDisplaySummary' => $isDisplaySummary)); } else { if ($planInfo && $planInfo->is_valid == 13) { $totalClicksInfo = $bllChoice->get_prop_choice_clicks($houseId, $cityId); $totalClicks = intval($totalClicksInfo[0]['bidClicks']); $rank = Bll_Plan_Bid_HzBid::getChoiceWaitPosition($planInfo->plan_id, $cityId, $blockId, $priceId); return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('clickPrice' => round($clickPrice, 2), 'clickPriceUnit' => '元', 'totalClicks' => $totalClicks, 'balance' => round($amount, 2), 'balanceUnit' => '元', 'maxBucketNum' => 20, 'usedBucketNum' => $bucketInfo['usedNum'], 'minChoicePrice' => 20, 'minChoicePriceUnit' => '元', 'maxChoicePrice' => 50, 'maxChoicePriceUnit' => '元', 'status' => '1-2', 'statusMsg' => "{$rank}", 'remindStatus' => $remindStatus, 'remindStatusMsg' => $remindStatusMsg, 'isDisplaySummary' => $isDisplaySummary)); } else { //判断是否符合精选条件 多图 + 新发15天 if (false == $content['quality'] || date('Ymd', strtotime('-16 days')) > date('Ymd', $content['created'])) { return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('clickPrice' => round($clickPrice, 2), 'clickPriceUnit' => '元', 'maxBucketNum' => 20, 'usedBucketNum' => $bucketInfo['usedNum'], 'minChoicePrice' => 20, 'minChoicePriceUnit' => '元', 'maxChoicePrice' => 50, 'maxChoicePriceUnit' => '元', 'status' => '3-2', 'statusMsg' => '精选推广条件:多图+新发15天', 'remindStatus' => $remindStatus, 'remindStatusMsg' => $remindStatusMsg, 'isDisplaySummary' => $isDisplaySummary)); } } } if ($bucketInfo['usedNum'] >= $bucketInfo['totalNum']) { $status = '2-1'; $statusMsg = '推广位已满'; } else { if ($bucketInfo['usedNum'] >= $bucketInfo['maxOnlineNum']) { $status = '2-2'; $statusMsg = '可立即排队'; } else { $status = '2-3'; $statusMsg = '可立即推广'; } } // 如果推广位已满,判断推广位是否已订阅 if ($status == '2-1') { $subscription = Model_Choice_Subscription::data_access()->filter('site', Model_Choice_Subscription::SITE_RENT)->filter('brokerId', $brokerId)->filter('propId', $houseId)->filter('bucketId', $bucketInfo['id'])->filter('status', Model_Choice_Subscription::SUBSCRIPTION_START)->find_only(); if ($subscription) { $remindStatus = 1; // 1 已订阅 $remindStatusMsg = '取消推广位提醒'; } else { $remindStatus = 0; // 0 未订阅 $remindStatusMsg = '有推广位了提醒我'; } } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('clickPrice' => round($clickPrice, 2), 'clickPriceUnit' => '元', 'bucketId' => $bucketInfo['id'], 'maxBucketNum' => $bucketInfo['totalNum'], 'usedBucketNum' => $bucketInfo['usedNum'], 'minChoicePrice' => 20, 'minChoicePriceUnit' => '元', 'maxChoicePrice' => 50, 'maxChoicePriceUnit' => '元', 'status' => $status, 'statusMsg' => $statusMsg, 'remindStatus' => $remindStatus, 'remindStatusMsg' => $remindStatusMsg, 'isDisplaySummary' => $isDisplaySummary)); }
/** * 金铺-精选房源设置 * * @param $ajkBrokerId * @param $cityId * @param $propId * @param array $params * @return array */ public static function jp_setting_post($ajkBrokerId, $cityId, $propId, $params = array()) { $jpBrokerInfo = Model_Broker_JpBroker::getJpBrokerInfoByAjkBrokerId($ajkBrokerId); //check房源是否已经加入精选推广 $bidObj = Model_Plan_Jp::getBidPlanByHouseIdEx($ajkBrokerId, $propId, true); if (!empty($bidObj)) { if ($bidObj['status'] == Model_Plan_Jp::ENUM_STATUS_ONLINE || $bidObj['status'] == Model_Plan_Jp::ENUM_STATUS_CHOICE_HOLD) { return array('err_no' => self::BID_HOUSE_ALREADY_IN_BID, 'err_msg' => '房源已经加入精选推广'); } elseif ($bidObj['status'] == Model_Plan_Jp::ENUM_STATUS_HOLD) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源正在结算中,请稍后...'); } } $bidChoiceCount = Model_Plan_Jp::getBidChoiceInfoEx($cityId, $ajkBrokerId); //获取精选推广预算 $brokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($ajkBrokerId); $brokerCompanyId = $brokerInfo['BaseInfo']['COMPANYID']; $choiceSet = APF::get_instance()->get_config('choice_set'); if (isset($choiceSet[$brokerCompanyId]) && !empty($choiceSet[$brokerCompanyId])) { $min_budget = $choiceSet[$brokerCompanyId]['jp']['JP_CHOICE_MIN_BUDGET']; $max_budget = $choiceSet[$brokerCompanyId]['jp']['JP_CHOICE_MAX_BUDGET']; } else { $min_budget = $choiceSet['default']['jp']['JP_CHOICE_MIN_BUDGET']; $max_budget = $choiceSet['default']['jp']['JP_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 . '安币'); } $status = isset($bidObj['status']) ? $bidObj['status'] : 0; if (count($bidChoiceCount) >= self::ALL_JP_PLAN_NUM && $status != 4) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '精选推广房源已经超过' . self::ALL_JP_PLAN_NUM . '套'); } if (0 == $jpBrokerInfo) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '您不是金铺经纪人'); } /** 获取房源基本信息 */ $propInfo = Bll_House_JpHouseInfo::getHouseInfoById($propId); if (empty($propInfo)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源不存在'); } if ($propInfo['base']['memberId'] != $jpBrokerInfo['id']) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源不属于该经纪人'); } /** 判断是否是精选开放城市 */ if (!Bll_City::isChoiceIndependentCity($cityId, Const_Site::JINPU)) { /** 判断房源是否在套餐推广 */ $propCombos = Bll_Combo_HouseRelation::getOnlineRelationByHouseId($propId, Bll_Combo_HouseRelation::SITE_TYPE_JP); if (empty($propCombos)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源必须在套餐推广才能参与精选'); } } if (false == $propInfo['info']['isExquisite']) { return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '精品、新发15天房源才能参与精选推广', 'params' => array('site' => 'jp')); } $limitDay = intval(date('Ymd', strtotime('-15 days'))); $postDay = intval(date('Ymd', strtotime($propInfo['base']['createTime']))); if ($limitDay > $postDay) { return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '精品、新发15天房源才能参与精选推广', 'params' => array('site' => 'jp')); } /** 获取板块信息 **/ $blockArr = Bll_House_JpHouseInfo::getBlock($propInfo['base']['houseType'], $propInfo['info']); if (!$blockArr['blockId'] && !$blockArr['newBlockId']) { return array('err_no' => self::BID_HOUSE_ALREADY_IN_BID, 'err_msg' => '房源缺少板块信息'); } /** 获取价格信息 **/ $arrPrice = Bll_House_JpHouseInfo::getPrice($cityId, $propInfo['base']['houseType'], $propInfo['info']); if (empty($arrPrice['price_id'])) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '缺少价格段信息'); } /** 获取点击单价开始 */ try { $apiParams = array('brokerId' => $ajkBrokerId, 'cityId' => $cityId, 'price' => $arrPrice['price'] ?: 0, 'blockId' => $blockArr['blockId'] ?: 0, 'newBlockId' => $blockArr['newBlockId'] ?: 0, 'houseType' => $propInfo['base']['houseType']); /** * @var Bll_Service_Client_HttpResponse $clickPrice */ for ($i = 0; $i < 3; $i++) { $clickPrice = Bll_Service_Choice::jpClickPrice($apiParams); if ($clickPrice->isSucceeded()) { break; } } if (!$clickPrice->isSucceeded() || $clickPrice['status'] == 'error') { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-1000)'); } 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:-2000)'); } /** 防并发 */ if (false === self::rejectSameRequest(Bll_Plan_Bid_Choice::SITE_JP, $ajkBrokerId, $propId)) { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-906)'); } /** 往冻结队列里添加记录,获取request id*/ $bidFreezeOrder = new Bll_Plan_BidFreezeOrderNum(date('Y')); $ajk_user_id = Bll_Broker_MainBusiness::getDataByEsfId($ajkBrokerId)->memberId; $requestId = $bidFreezeOrder->getRequestId(Bll_Plan_BidFreezeOrderNum::JP, $ajk_user_id, date('Y'), 0, $propId); /** 冻结金额 **/ $freezeResult = self::bid_freeze($ajkBrokerId, $params['budget'] * 100, $requestId, sprintf('金铺精选房源冻结,房源ID是: %d', $propId), Const_PaymentApp::JP_CHOICE); /** 判断是否冻结成功 **/ $freezeResponse = $freezeResult->getResponse(); if (!$freezeResult->isSucceeded() || $freezeResponse['status'] == 'error') { return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => isset($freezeResult['info']) ? $freezeResult['info'] . "code:" . $freezeResult['code'] : '冻结金额失败'); } //检查是否有坑位 坑位+1 $bucketStatus = Model_Choice_JPBidBucket::incrementUsedNum($blockArr['blockId'], $blockArr['newBlockId'], $propInfo['base']['houseType'], $arrPrice['price_id']); if (!$bucketStatus) { return array('err_no' => self::BID_WAIT_FAIL, 'err_msg' => '精选推广已满,请稍后再试'); } /** 获取最小竞价单元的精选信息 **/ $bucketInfo = Model_Choice_JPBidBucket::getBucketInfo($blockArr['blockId'], $blockArr['newBlockId'], $propInfo['base']['houseType'], $arrPrice['price_id']); /** 根据最小竞价单位里面的房源数判断当前的房源应该是排队还是推广中 **/ /* if ($bucketInfo['usedNum'] > $bucketInfo['maxOnlineNum']) { $planStatus = Model_Plan_Jp::ENUM_STATUS_CHOICE_HOLD; } else { $planStatus = Model_Plan_Jp::ENUM_STATUS_ONLINE; } */ $planStatus = Model_Plan_Jp::ENUM_STATUS_CHOICE_HOLD; /** 如果计划已经存在删除该计划**/ if (isset($bidObj['status']) && $bidObj['status'] == 4) { Model_Plan_Jp::data_access()->set_field('isDelete', 1)->filter('id', $bidObj['id'])->update(); } /** 构造计划数据 创建计划**/ $planData = self::buildJpPlanData($cityId, $jpBrokerInfo['id'], $params['budget'], $freezeResult['data']['sn'], $propId, $blockArr['blockId'], $blockArr['newBlockId'], $arrPrice['price_id'], $propInfo['base']['houseType'], $planStatus); $planData['ajkBrokerId'] = $ajkBrokerId; $PlanObj = Model_Plan_Jp::create($planData); $PlanObj->save(); if (empty($PlanObj->id)) { /** 坑位-1 **/ Model_Choice_JPBidBucket::decrementUsedNum($blockArr['blockId'], $blockArr['newBlockId'], $propInfo['base']['houseType'], $arrPrice['price_id']); Model_Plan_Jp::data_access()->set_field('isDelete', 0)->filter('id', $bidObj['id'])->update(); return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '创建计划失败'); } /** 更新房源里面的竞价计划id **/ $propInfo['base']->bidSpreadId = $PlanObj->id; $propInfo['base']->save(); /** 更新房源分表信息 **/ //$propInfo['info']->isList = 1; $propInfo['info']->spreadOffer = $clickPrice['realTradeAmount']; $propInfo['info']->spreadOfferTime = time(); $propInfo['info']->save(); /** 构建精选动作处理数据 **/ $choiceData = self::buildJpChoiceData($ajkBrokerId, Model_Choice_ActionQueue::ENUM_BEGIN_BY_HAND, $PlanObj->id, '经纪人手动推广', $propId); /** 插入到精选动作处理队列表 **/ Model_Choice_ActionQueue::create($choiceData, date('m'))->save(); $bidFreezeOrder->updateRequestComplete($requestId, $freezeResult['data']['sn'], $PlanObj->id); if ($bucketInfo['usedNum'] > $bucketInfo['maxOnlineNum']) { $rank = $bucketInfo['usedNum'] - $bucketInfo['maxOnlineNum']; return array('err_no' => self::BID_WAIT_SUCCESS, 'err_msg' => '精选排队成功', 'rank' => $rank); } else { return array('err_no' => self::BID_SHOW_SUCCESS, 'err_msg' => '精选推广成功'); } }
/** * 开启精选计划 * * @param $brokerId int 经纪人id * @param $propId int 房源id * @param $budget int 预算,单位元 */ public function startChoice($brokerId, $propId, $budget) { try { //获取经纪人基本信息 $brokerBaseInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (empty($brokerBaseInfo)) { $this->error(self::EMPTY_BROKER_ERROR, self::EMPTY_BROKER_ERROR_MSG); } $cityId = $brokerBaseInfo->cityId; $userId = $brokerBaseInfo->userId; //判断经纪人城市是否开通精选 if (!$this->checkChoiceOpen($brokerBaseInfo->cityId)) { $this->error(self::CHOICE_CLOSE_ERROR, self::CHOICE_CLOSE_ERROR_MSG); } //判断预算的合法性 if ($budget < Bll_Plan_Bid_Choice::ESF_CHOICE_MIN_BUDGET || $budget > Bll_Plan_Bid_Choice::ESF_CHOICE_MAX_BUDGET) { $this->error(self::BUDGET_INVALID_ERROR, self::BUDGET_INVALID_ERROR_MSG); } //判断余额是否足够 $balanceResponse = Bll_Service_Payment::balance(Bll_Service_Payment::SITE_ANJUKE, array('userId' => $brokerBaseInfo->userId)); if ($balanceResponse['status'] == 'error') { throw new Exception(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } $balance = $balanceResponse['data']['balance']; if ($balance / 100 < $budget) { $this->error(self::BANANCE_LESS_BUDGET, self::BANANCE_LESS_BUDGET_MSG); } //获取房源信息 $houseInfo = Bll_House_EsfHouse::getHouseBaseInfo($propId, $cityId); if (empty($houseInfo)) { $this->error(self::PROP_NOT_EXIST_ERROR, self::PROP_NOT_EXIST_ERROR_MSG); } $houseInfo = $houseInfo[0]; //操作人验证 if ($houseInfo->userId != $userId) { $this->error(self::PROP_OPREATE_ACCESS_INVALID_ERROR, self::PROP_OPREATE_ACCESS_INVALID_ERROR_MSG); } //房源是否可以精选验证 if ($houseInfo->isVisible != 1) { //违规验证 $this->error(self::PROP_CHOICE_NOT_FIT_ISVISIBLE_ERROR, self::PROP_CHOICE_NOT_FIT_ISVISIBLE_ERROR_MSG); } if ($houseInfo->isHighQulity == 0) { //多图验证 $this->error(self::PROP_CHOICE_NOT_FIT_ISHIGHQULITY_ERROR, self::PROP_CHOICE_NOT_FIT_ISHIGHQULITY_ERROR_MSG); } if (date('Ymd', strtotime('-16 days')) > date('Ymd', $houseInfo->postDate)) { //发布时间验证 $this->error(self::PROP_CHOICE_NOT_FIT_POSTDATE_ERROR, self::PROP_CHOICE_NOT_FIT_POSTDATE_ERROR_MSG); } $planInfo = Model_Plan_EsfAjkPropSpread::getChoicePlanInfoByHouseid($propId); if (!empty($planInfo)) { $reBid = 1; } //判断当前经纪人已经精选推广的房源数 if ($reBid) { if (Bll_Plan_Bid_Choice::checkEsfBidChoiceFull($brokerId, $cityId, 1)) { $this->error(self::MAX_CHOICE_NUM_ERROR, sprintf(self::MAX_CHOICE_NUM_ERROR_MSG, Bll_Plan_Bid_Choice::$all_esf_plan_num)); } } else { if (Bll_Plan_Bid_Choice::checkEsfBidChoiceFull($brokerId, $cityId)) { $this->error(self::MAX_CHOICE_NUM_ERROR, sprintf(self::MAX_CHOICE_NUM_ERROR_MSG, Bll_Plan_Bid_Choice::$all_esf_plan_num)); } } //套餐经纪人 还是ppc经纪人 /*$IsComboCity = Bll_Broker_HzBroker::isComboBroker($brokerId); if ($IsComboCity) { //是否套餐推广 $comboHouseRelation = Model_Combo_HouseRelation::getOnlineHousebyHouseId($brokerId, $propId, $cityId, Model_Combo_HouseRelation::SITE_TYPE_AJK); if(empty($comboHouseRelation)) { $this->error(self::PROP_NO_COMBO, self::PROP_NO_COMBO_MSG); } } else { //判断房源的定价计划状态 $fixPlanBll = new Bll_FixedSpread_PropFixedPlanRelation(); $fixPlanRelationStatus = $fixPlanBll->getProSpreadRelationByProId($propId, $cityId); if ($fixPlanRelationStatus['Status'] != 1) { $this->error(self::PROP_CHOICE_NOT_FIT_FIXED_ERROR, self::PROP_CHOICE_NOT_FIT_FIXED_ERROR_MSG); } }*/ /** 判断是否是精选开放城市 */ if (!Bll_City::isChoiceIndependentCity($cityId, Const_Site::ANJUKE)) { /** 判断是在套餐推广中 */ $houseState = Bll_Combo_HouseRelation::getOnlineRelationByHouseId($propId, Bll_Combo_HouseRelation::SITE_TYPE_AJK); if (empty($houseState)) { $this->error(self::PROP_NO_COMBO, self::PROP_NO_COMBO_MSG); } } /** 防并发 */ if (false === Bll_Plan_Bid_Choice::rejectSameRequest(Bll_Plan_Bid_Choice::SITE_AJK, $brokerId, $propId)) { $this->error(self::OPERATION_TIME_ERROR, self::OPERATION_TIME_ERROR_MSG); } //判断是否已在竞价计划中 if ($reBid) { if ($planInfo->status == Model_Plan_EsfAjkPropSpread::ONLINE || $planInfo->status == Model_Plan_EsfAjkPropSpread::ONQUEUE) { $this->error(self::PROP_CHOICE_NOT_FIT_CHOICED_ERROR, self::PROP_CHOICE_NOT_FIT_CHOICED_ERROR_MSG); } } else { if (!empty($planInfo) || $planInfo->status == Model_Plan_EsfAjkPropSpread::ONLINE || $planInfo->status == Model_Plan_EsfAjkPropSpread::ONQUEUE) { $this->error(self::PROP_CHOICE_NOT_FIT_CHOICED_ERROR, self::PROP_CHOICE_NOT_FIT_CHOICED_ERROR_MSG); } } //重新推广,判断结算状态 if ($reBid) { if ($planInfo->tradestatus != Model_Plan_EsfAjkPropSpread::COMPLETETTRADESTATU) { $this->error(self::PROP_CHOICE_NOT_SETTLE_ERROR, self::PROP_CHOICE_NOT_SETTLE_ERROR_MSG); } } $housePrice = intval($houseInfo->proPrice * 10000); $priceIntervalInfo = Model_House_EsfPrice::get_price($cityId, $housePrice); if (empty($priceIntervalInfo)) { $this->error(self::PROP_PRICE_UNKNOW_ERROR, self::PROP_PRICE_UNKNOW_ERROR_MSG); } $priceId = $priceIntervalInfo['id']; $minPrice = $priceIntervalInfo['minPrice']; $maxPrice = $priceIntervalInfo['maxPrice']; //查询坑情况 $bucketInfo = Model_Choice_EsfBidBucket::get_bucket_info($houseInfo->commId, $priceId); if (empty($bucketInfo)) { if (Model_Choice_EsfBidBucket::init_bucket_info($houseInfo->commId, $priceId, $cityId)) { $bucketInfo = array('communityId' => $houseInfo->commId, 'priceId' => $priceId, 'totalNum' => Model_Choice_EsfBidBucket::TOTALNUM, 'usedNum' => 0, 'maxOnlineNum' => Model_Choice_EsfBidBucket::MAXONLINENUM); } else { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } } //预判断坑位 if ($bucketInfo['usedNum'] >= $bucketInfo['totalNum']) { $this->error(self::CHOICE_QUEUE_FULL, self::CHOICE_QUEUE_FULL_MSG); } //按照最大坑位数目更新 if (!Model_Choice_EsfBidBucket::increment_used_num($houseInfo->commId, $priceId, 0)) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } //获取reuqestid $year = date('Y'); $bll = new Bll_Plan_BidFreezeOrderNum($year); $requestId = $bll->getRequestId(Bll_Plan_BidFreezeOrderNum::ESF, $userId, $year, 0, $propId); //冻结金额 $amount = $budget * 100; $note = sprintf("二手房精选房源冻结,propId: %d", $propId); if (($freezeResult = Bll_Plan_Bid_Choice::bid_freeze($brokerId, $amount, $requestId, $note, Const_PaymentApp::AJK_CHOICE)) === false) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } if (!$freezeResult->isSucceeded()) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } if ($freezeResult['status'] == 'error') { $this->error(self::CHOICE_FREEZE_ERROR, self::CHOICE_FREEZE_ERROR_MSG); } $snNum = $freezeResult['data']['sn']; //重新推广,将原来的推广计划置为删除状态 if ($reBid) { $planInfo->status = Model_Plan_EsfAjkPropSpread::DELETE; if (!$planInfo->save()) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } } for ($i = 0; $i < 3; $i++) { //价格 $clickPrice = Bll_Service_Choice::ajkClickPrice(array('brokerId' => $brokerId, 'cityId' => $cityId, 'price' => $housePrice, 'commId' => $houseInfo->commId)); if ($clickPrice->isSucceeded()) { break; } } if (empty($clickPrice) || $clickPrice['status'] != 'ok') { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } $priceUnit = round($clickPrice['realTradeAmount'] / 100, 2); //新建计划 $time = time(); $offer = $priceUnit * 100; $stopTime = $time + Bll_Plan_Bid_Choice::ESF_AUTO_STOP_TIME; $endTime = time() + Model_Plan_EsfAjkPropSpread::CHOICELASTINGTIME; $arrAddInfo['serialnumber'] = $snNum; $arrAddInfo['propId'] = $propId; $arrAddInfo['cityId'] = $cityId; $arrAddInfo['commId'] = $houseInfo->commId; $arrAddInfo['brokerId'] = $brokerId; $arrAddInfo['userId'] = $userId; $arrAddInfo['budget'] = $amount; $arrAddInfo['balance'] = $amount; $arrAddInfo['spreadstartdate'] = $time; $arrAddInfo['spreadenddate'] = $endTime; $arrAddInfo['bigprice'] = $maxPrice; $arrAddInfo['smallprice'] = $minPrice; $arrAddInfo['propriceint'] = $housePrice; $arrAddInfo['status'] = Model_Plan_EsfAjkPropSpread::ONQUEUE; $arrAddInfo['isreserve'] = Model_Plan_EsfAjkPropSpread::RESERVE; $arrAddInfo['bidVersion'] = Model_Plan_EsfAjkPropSpread::CHOICEVERSION; $arrAddInfo['areacode'] = $houseInfo->areaCode; $arrAddInfo['stoptime'] = $stopTime; $arrAddInfo['createtime'] = $time; $arrAddInfo['offer'] = $offer; //排名系数,请直接绕过 +_+ $hpratioABll = new Bll_Plan_Bid_EsfHpratioA(); $arrAddInfo['qulityScore'] = $hpratioABll->getHouseMass($propId, $brokerId, $cityId, $houseInfo->commId, $houseInfo->hasRoomPic, $houseInfo->isHighQulity, $houseInfo->postDate, $houseInfo->unitPrice); $commScore = round($hpratioABll->getCommScore($houseInfo->commId), 5); $arrAddInfo['commScore'] = $commScore; $userActionScore = $hpratioABll->getUserActionScore($propId, $cityId); $arrAddInfo['behaviorScore'] = $userActionScore; $arrAddInfo['hpratioA'] = $hpratioABll->getHpraio($offer, $arrAddInfo['qulityScore'], $userActionScore); $hpratioNorm = $hpratioABll->getPpcNormHpratio($arrAddInfo['hpratioA'], $houseInfo->commId, false, $minPrice, $maxPrice, $houseInfo->areaCode); $arrAddInfo['commsHpratioA'] = round($commScore * $hpratioNorm, 5); if (($planId = Model_Plan_EsfAjkPropSpread::insertLayer($arrAddInfo)) === false) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } //新精选队列插入记录 if (!Bll_Plan_Bid_EsfChoiceQueue::insert($brokerId, $planId, Model_Choice_ActionQueue::ENUM_BEGIN_BY_HAND, date('m'), $brokerId, '经纪人手动开始推广', APF::get_instance()->get_request()->get_client_ip())) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } //插入自动停止队列 $stopType = Model_Plan_EsfAjkPropspreadQueue::AUTOSTOP; Model_Plan_EsfAjkPropspreadQueue::insertOne($planId, $stopTime, $stopType); //记录log表 $remark = sprintf("PROP_ID:null=>%d;CITY_ID:null=>%d;COMM_ID:null=>%d;BROKER_ID:null=>%d;USER_ID:null=>%d;BUDGET:null=>%d;SPREADSTARTDATE:null=>%d;SPREADENDDATE:null=>%d;STATUS:null=>%d;ISRESERVE:null=>%d;SERIALNUMBER:null=>%d;TRADETYPE:0=>1;BALANCE:0=>%d;PROPRICEINT:0=>%d;BIGPRICE:0=>%d;SMALLPRICE:0=>%d", $propId, $cityId, $houseInfo->commId, $brokerId, $userId, $amount, $time, $endTime, Model_Plan_EsfAjkPropSpread::ONQUEUE, Model_Plan_EsfAjkPropSpread::RESERVE, $snNum, $amount, $housePrice, $maxPrice, $minPrice); Model_Plan_LogAjkPropspread::addNewLog($planId, $brokerId, Model_Plan_LogAjkPropspread::ADD, $remark); //更新reuqest id完成 if (!$bll->updateRequestComplete($requestId)) { $this->error(self::SYSTEM_BUSY_ERROR, self::SYSTEM_BUSY_ERROR_MSG); } $rankNum = Bll_Plan_Bid_Choice::getEsfOnlineAndOnQueueNum($planId, $houseInfo->commId, $minPrice, $maxPrice); if ($rankNum <= $bucketInfo['maxOnlineNum']) { return array('status' => self::START_CHOICE_TO_ONLINE, 'statusMsg' => self::START_CHOICE_TO_ONLINE_MSG); } else { return array('status' => self::START_CHOICE_TO_ONQUEUE, 'statusMsg' => self::START_CHOICE_TO_ONQUEUE_MSG); } } catch (Exception $e) { if ($e instanceof Exception_BllErrorException) { $this->errorCode = $e->getCode(); } else { $this->errorCode = self::UNKNOW_ERROR; } $this->errorMsg = $e->getMessage(); return false; } }
public function handle_request_internal() { $brokerId = $this->_params['brokerId']; $houseId = $this->_params['propId']; $budget = $this->_params['budget']; if ($budget < 20 || $budget > 50) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '请输入20~50之间的整数'); } $brokerInfo = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId); if (!$brokerInfo) { throw new Exception_BrokerNotFoundException('经纪人不存在', Const_APIStatus::E_BROKER_NOT_EXISTS); } $cityId = $brokerInfo->cityId; if (!Bll_City::isChoiceCity($cityId, Const_Site::HAOZU)) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => Const_APIStatus::E_NOT_CHOICE_CITY, 'message' => '非精选城市'); } // 获取房源基本信息 $propInfo = Model_House_HzProp::get_prop_info_by_prop_id($houseId); $block_id = $propInfo['contentBasic']['blockid']; // 获取点击单价 try { $clickPriceInfo = Bll_Service_Choice::hzClickPrice(array('cityId' => $cityId, 'price' => (int) $propInfo['contentBasic']['pricenum'], 'blockId' => $block_id, 'brokerId' => $brokerId)); if ($clickPriceInfo['status'] == 'error') { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '系统繁忙(code:-33)'); } } catch (Exception $e) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '系统繁忙(code:-33)'); } $params = array(); $params['price'] = $clickPriceInfo['realTradeAmount'] / 100; // 点击单价单位转换:分 -> 元; $params['show'] = 0; $params['budget'] = $budget; $params['ip'] = $this->_request->get_client_ip(); // 判断是否是重新推广 $bllChoice = new Bll_Zufang_Choice(); $planInfo = $bllChoice->get_plan_by_proid($houseId); //planning表中查找精选计划 if (!empty($planInfo)) { $planId = $planInfo->plan_id; $basicPlanInfo = $bllChoice->get_plan($planId); if (!empty($basicPlanInfo)) { if ($basicPlanInfo[0]->status == 1 || $basicPlanInfo[0]->status == 13) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => '该房源已做精选推广!'); } if ($basicPlanInfo[0]->status != Const_HzPlan::DELETE) { $params['plan_id'] = $planInfo->plan_id; } } } // 开始精选推广 $result = Bll_Plan_Bid_Choice::hz_setting_post($brokerId, $cityId, $houseId, $params); if ($result['err_no'] != Bll_Plan_Bid_Choice::BID_WAIT_SUCCESS) { return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => '', 'message' => $result['err_msg']); } if ($result['rank'] > 10) { $status = 2; $msg = "排在第{$result['rank']}位"; } else { $status = 1; $msg = "精选推广成功"; } return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('status' => $status, 'statusMsg' => $msg)); }