示例#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;
 }
示例#2
0
 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));
 }
示例#3
0
 /**
  * 更新坑位信息,重新计算
  *
  * @param int $blockId
  * @param int $priceId
  * @return bool
  */
 private static function updateBucket($blockId, $priceId)
 {
     $bucketCount = Bll_HzBidPlan::countBucketChoicePlan($blockId, $priceId);
     $bucketInfo = Bll_Choice_HzBidBucket::getBucketInfo($blockId, $priceId);
     if (empty($bucketInfo)) {
         $bucketInfo = Bll_Choice_HzBidBucket::init_bucket_info($blockId, $priceId);
     }
     if ($bucketInfo['usedNum'] == $bucketCount) {
         return true;
     }
     $condition = array('blockId' => $blockId, 'priceId' => $priceId);
     return 1 == Model_Choice_HzBidBucket::updateBucket($condition, array('usedNum' => min($bucketCount, $bucketInfo['totalNum'])));
 }