コード例 #1
0
ファイル: Choice.php プロジェクト: emilymwang8/ajk-broker
 /**
  * 二手房精选推广设置页面
  *
  * @param $brokerId
  * @param $cityId
  * @param $houseId
  * @param $userId
  * @param array $params
  * @return array
  */
 public static function esf_setting_post($brokerId, $cityId, $houseId, $userId, $params = array())
 {
     $result = array();
     //获取精选推广预算
     $brokerInfo = Bll_BrokerBaseBll::get_instance()->get_broker_info($brokerId);
     $brokerCompanyId = $brokerInfo['BaseInfo']['COMPANYID'];
     $choiceSet = APF::get_instance()->get_config('choice_set');
     if (isset($choiceSet[$brokerCompanyId]) && !empty($choiceSet[$brokerCompanyId])) {
         $min_budget = $choiceSet[$brokerCompanyId]['ajk']['ESF_CHOICE_MIN_BUDGET'];
         $max_budget = $choiceSet[$brokerCompanyId]['ajk']['ESF_CHOICE_MAX_BUDGET'];
     } else {
         $min_budget = $choiceSet['default']['ajk']['ESF_CHOICE_MIN_BUDGET'];
         $max_budget = $choiceSet['default']['ajk']['ESF_CHOICE_MAX_BUDGET'];
     }
     //判断预算的合法性
     if ($params['budget'] < $min_budget || $params['budget'] > $max_budget) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '预算价格范围非法');
     }
     //获取房源信息
     $pageAttribute['housesInfo'] = Bll_House_EsfHouse::getHouseBaseInfo($houseId, $cityId);
     if (empty($pageAttribute['housesInfo'])) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源不存在');
     }
     $houseInfo = $pageAttribute['housesInfo'][0];
     if ($houseInfo->userId != $userId) {
         return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '房源不属于当前操作人');
     }
     if ($houseInfo->isVisible != 1) {
         return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '房源是违规房源,不可以参加精选房源推广');
     }
     if ($houseInfo->isHighQulity == 0) {
         return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '多图、新发15天房源才能参与精选推广');
     }
     if (date('Ymd', strtotime('-15 days')) > date('Ymd', $houseInfo->postDate)) {
         return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '只能精选推广15天内发布的房源');
     }
     self::setChoiceNum($cityId);
     //判断当前经纪人已经精选推广的房源数
     if (isset($params['act']) && isset($params['rebid'])) {
         if (self::checkEsfBidChoiceFull($brokerId, $cityId, 1)) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '最多精选推广' . self::$all_esf_plan_num . '套房源');
         }
     } else {
         if (self::checkEsfBidChoiceFull($brokerId, $cityId)) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '最多精选推广' . self::$all_esf_plan_num . '套房源');
         }
     }
     /** 判断是否是精选开放城市 */
     if (!Bll_City::isChoiceIndependentCity($cityId, Const_Site::ANJUKE)) {
         /** 判断是在套餐推广中 */
         $houseState = Bll_Combo_HouseRelation::getOnlineRelationByHouseId($houseId, Bll_Combo_HouseRelation::SITE_TYPE_AJK);
         if (empty($houseState)) {
             return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '该房源不在推广中');
         }
     }
     //判断是否已在竞价计划中
     $planInfo = Model_Plan_EsfAjkPropSpread::getChoicePlanInfoByHouseid($houseId);
     if (!empty($planInfo) && !isset($params['rebid'])) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源已经精选');
     }
     /** 防并发 */
     if (false === self::rejectSameRequest(Bll_Plan_Bid_Choice::SITE_AJK, $brokerId, $houseId)) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '系统繁忙(code:-906)');
     }
     //重新推广,判断结算状态
     if (isset($params['act']) && isset($params['rebid'])) {
         //获取计划信息
         if (!isset($planInfo)) {
             $planInfo = Model_Plan_EsfAjkPropSpread::getChoicePlanInfoByHouseid($houseId);
         }
         if ($planInfo->status == Model_Plan_EsfAjkPropSpread::ONLINE || $planInfo->status == Model_Plan_EsfAjkPropSpread::ONQUEUE) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源已经精选');
         }
         if ($planInfo->tradestatus != Model_Plan_EsfAjkPropSpread::COMPLETETTRADESTATU) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '房源还未结算完成');
         }
     }
     $housePrice = intval($houseInfo->proPrice * 10000);
     $priceIntervalInfo = Model_House_EsfPrice::get_price($cityId, $housePrice);
     if (empty($priceIntervalInfo)) {
         return array('err_no' => self::BID_FAIL_QUALITY_OR_NEW, 'err_msg' => '房源价格未知');
     }
     $priceId = $priceIntervalInfo['id'];
     $minPrice = $priceIntervalInfo['minPrice'];
     $maxPrice = $priceIntervalInfo['maxPrice'];
     /** 获取点击单价 最低预算不能小于点击单价 */
     try {
         /**
          * @var Bll_Service_Client_HttpResponse $clickPrice
          */
         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 (!$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 (isset($params['fromApi']) && $params['fromApi']) {
             /** 来自API 的精选创建计划 */
             $params['price'] = $clickPrice['realTradeAmount'] / 100;
         } else {
             /** 点击单价不能小于当前系统内的单价 防止恶意操作 */
             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__ . ')');
     }
     //查询坑情况
     $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 {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
         }
     }
     //坑位表维护
     if ($params['show'] == 1) {
         //预判断坑位
         if ($bucketInfo['usedNum'] >= $bucketInfo['maxOnlineNum']) {
             return array('err_no' => self::BID_SHOW_FAIL, 'err_msg' => '推广位置已满,请重新推广!');
         }
         //按照最大在线数目更新坑位表
         if (!Model_Choice_EsfBidBucket::increment_used_num($houseInfo->commId, $priceId, 1)) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
         }
     } else {
         //预判断坑位
         if ($bucketInfo['usedNum'] >= $bucketInfo['totalNum']) {
             return array('err_no' => self::BID_WAIT_FAIL, 'err_msg' => '排队位置已满,请重新推广!');
         }
         //按照最大坑位数目更新
         if (!Model_Choice_EsfBidBucket::increment_used_num($houseInfo->commId, $priceId, 0)) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
         }
     }
     //获取reuqestid
     $year = date('Y');
     $bll = new Bll_Plan_BidFreezeOrderNum($year);
     $requestId = $bll->getRequestId(Bll_Plan_BidFreezeOrderNum::ESF, $userId, $year, 0, $houseId);
     //冻结金额
     $amount = $params['budget'] * 100;
     $note = sprintf("二手房精选房源冻结,propId: %d", $houseId);
     if (($freezeResult = self::bid_freeze($brokerId, $amount, $requestId, $note, Const_PaymentApp::AJK_CHOICE)) === false) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
     }
     if (!$freezeResult->isSucceeded()) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
     }
     if ($freezeResult['status'] == 'error') {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '冻结失败!');
     }
     $snNum = $freezeResult['data']['sn'];
     //重新推广,将原来的推广计划置为删除状态
     if (isset($params['act']) && $params['rebid']) {
         $planInfo->status = Model_Plan_EsfAjkPropSpread::DELETE;
         if (!$planInfo->save()) {
             return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
         }
     }
     //新建计划
     $time = time();
     $offer = $params['price'] * 100;
     $stopTime = $time + self::ESF_AUTO_STOP_TIME;
     $endTime = time() + Model_Plan_EsfAjkPropSpread::CHOICELASTINGTIME;
     $arrAddInfo['serialnumber'] = $snNum;
     $arrAddInfo['propId'] = $houseId;
     $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;
     $arrAddInfo['model'] = Model_Plan_EsfAjkPropSpread::COMM_CHOICE;
     //排名系数,请直接绕过 +_+
     $hpratioABll = new Bll_Plan_Bid_EsfHpratioA();
     $arrAddInfo['qulityScore'] = $hpratioABll->getHouseMass($houseId, $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($houseId, $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) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
     }
     //新精选队列插入记录
     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(), $houseId)) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
     }
     //插入自动停止队列
     $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", $houseId, $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, $snNum, $planId)) {
         return array('err_no' => self::BID_FAIL_OTHER, 'err_msg' => '服务器繁忙,请重试(code: -' . __LINE__ . ')');
     }
     if ($params['show'] == 1) {
         return array('err_no' => self::BID_SHOW_SUCCESS);
     } else {
         $rank = Bll_Plan_Bid_Choice::getEsfOnQueueNum($planId, $houseInfo->commId, $minPrice, $maxPrice);
         return array('err_no' => self::BID_WAIT_SUCCESS, 'rank' => $rank);
     }
 }
コード例 #2
0
 /**
  * 开启精选计划
  *
  * @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;
     }
 }