Example #1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $propId = $this->_params['propId'];
     // 判断经纪人是否存在
     $broker = Model_Broker_AjkBrokerExtend::findWithBrokerId($brokerId);
     $hzBrokerId = Model_Broker_MainBusiness::getHzBrokerIdByAjkBrokerId($brokerId);
     if (!$hzBrokerId || !$broker) {
         throw new Exception_Broker_NotFound('BrokerId: ' . $brokerId);
     }
     // 判断城市是否开通竞价业务
     $cityId = $broker['cityId'];
     if (!Bll_City::isBidCity($cityId)) {
         throw new Exception_City_NotBidCity('CityId: ' . $cityId);
     }
     // 获取房源信息
     $prop = Model_House_HzProp::findByPropId($propId);
     /* @var Model_House_HzProp $prop */
     if (!$prop) {
         throw new Exception_Property_NotFound("Zufang propId: {$propId}");
     }
     // TODO 是否需要判断房源是否已删除
     // 判断房源是否属于经纪人
     if ($prop->getContentBasic('userid') != $hzBrokerId) {
         throw new Exception_Property_NotFound("Zufang propId: {$propId} not belog to broker: {$brokerId}");
     }
     // 准备默认返回数据(房源未竞价)
     $data = array('planId' => 0, 'status' => 0, 'rank' => -1, 'rankMsg' => '已暂停', 'todayClicks' => 0, 'totalClicks' => 0, 'clickPrice' => 0, 'clickPriceUnit' => '元', 'minClickPrice' => $prop->getBidMinClickPrice(), 'minClickPriceUnit' => '元', 'budget' => 0, 'budgetUnit' => '元', 'budgetRemain' => 0, 'budgetRemainUnit' => '元');
     // 获取竞价计划
     $bidPlan = $prop->getBidPlan();
     if (!$bidPlan) {
         // 判断房源是否多图房源
         if (!$prop->isMultiImages()) {
             throw new Exception_Property_NotMultiImages("Zufang propId: {$propId}");
         }
         // TODO 判断是否定价推广(也许可以不用,因为只有从定价推广房源列表点进去的房源详情页才会请求该接口)
     } else {
         // 竞价计划ID
         $data['planId'] = $bidPlan['id'];
         // 竞价计划状态
         switch ($bidPlan['status']) {
             case Const_HzPlan::SPREAD:
                 $data['status'] = 1;
                 // 推广中 or 排队中
                 break;
             case Const_HzPlan::MENUOVER:
                 $data['status'] = 2;
                 // 已暂停
                 break;
         }
         // 竞价预算
         $data['budget'] = round($bidPlan['amount'], 2);
         // 竞价预算余额
         $data['budgetRemain'] = round($bidPlan['amount'] - $bidPlan['total_consume'], 2);
         // 竞价排名
         if ($data['status'] == 1) {
             $data['rank'] = Bll_HzBidPlan::get_bid_rank($prop->getContentBasic(), $cityId);
             if ($data['rank'] <= 5) {
                 $data['rankMsg'] = '';
             } else {
                 $data['rankMsg'] = '排队中';
             }
         }
         // 竞价点击单价
         $bidRelation = $prop->getBidRelation();
         $data['clickPrice'] = round($bidRelation['unit_price'], 2);
         // 竞价点击底价
         $data['minClickPrice'] = round($prop->getBidMinClickPrice(), 2);
         // 今日竞价点击量
         $data['todayClicks'] = $prop->getTodayClickSums('bid');
         // 竞价点击总量
         $data['totalClicks'] = $prop->getTotalClickSums('bid');
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => $data);
 }