Esempio n. 1
0
 /**
  * 精选房源设置
  *
  * @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;
 }