Esempio n. 1
0
 /**
  * 金铺-精选房源设置
  *
  * @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' => '精选推广成功');
     }
 }