示例#1
0
 public function handle_request_internal()
 {
     $brokerId = $this->_params['brokerId'];
     $bllChoice = new Bll_Zufang_Choice();
     $hzBrokerId = $bllChoice->get_hz_broker_id($brokerId);
     $brokerInfo = $bllChoice->get_broker_info($brokerId);
     $cityId = $brokerInfo[0]->cityId;
     if (!Bll_City::isChoiceCity($cityId, Const_Site::HAOZU)) {
         return array('status' => Const_APIStatus::RETURN_CODE_ERROR, 'errcode' => Const_APIStatus::E_NOT_CHOICE_CITY, 'message' => '非精选城市');
     }
     $result = array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('OnlinePropertyList' => array(), 'QueuedPropertyList' => array(), 'OfflinePropertyList' => array()));
     // 获取所有的计划
     $plans = $bllChoice->get_active_choice_plans($hzBrokerId, array(1, 13, 2, 3, 7, 8));
     if (empty($plans)) {
         return $result;
     }
     $keyedPlans = array();
     foreach ($plans as $plan) {
         $keyedPlans[$plan->id] = $plan;
     }
     // 获取所有的房源和计划的关系
     $choiceRelations = $bllChoice->get_prop(array_keys($keyedPlans));
     $propIds = array();
     $propPlanMap = array();
     $propUpdateTime = array();
     foreach ($choiceRelations as $choiceRelation) {
         $propIds[] = $choiceRelation->proid;
         $propPlanMap[$choiceRelation->proid] = $keyedPlans[$choiceRelation->plan_id];
         $propUpdateTime[$choiceRelation->proid] = $choiceRelation->last_update;
     }
     // 获取所有房源
     if (empty($propIds)) {
         return $result;
     }
     $props = $bllChoice->get_prop_content($propIds);
     // 拼装房源数据
     $propertyList = array();
     foreach ($props as $prop) {
         $row = array();
         $content = json_decode($prop->contentBasic, true);
         $row['propId'] = $prop->propId;
         $row['title'] = $content['title'];
         $row['imgUrl'] = '';
         $row['commId'] = $content['commid'];
         $row['commName'] = $content['commname'];
         $row['roomNum'] = $content['roomnum'];
         $row['hallNum'] = $content['hallnum'];
         $row['toiletNum'] = $content['toilnetnum'];
         $row['price'] = round($content['pricenum']);
         $row['priceUnit'] = '元/月';
         $row['isVisible'] = $prop->isIllegal() ? 0 : 1;
         $row['isBid'] = 0;
         $row['isChoice'] = 1;
         $row['isMoreImg'] = intval($prop->isMultiImages());
         $row['isPhonePub'] = intval($prop->isFromMobile());
         //pmt21181 bug标记 文档上为createTime
         $row['choiceTime'] = $propPlanMap[$prop->propId]->created;
         $row['updateTime'] = $propUpdateTime[$prop->propId];
         $totalClicks = $bllChoice->get_prop_choice_clicks($prop->propId, $cityId);
         // TODO 待定
         $row['totalClicks'] = $totalClicks[0]['bidClicks'];
         //增加委托房源标签
         $isEntrust = Bll_Zufang_Choice::isCommissionHouse($prop->propId, $brokerId, Model_House_Commission::TYPE_RENT);
         if ($isEntrust) {
             $row['isEntrust'] = 1;
         } else {
             $row['isEntrust'] = 0;
         }
         $propertyList[$prop->propId] = $row;
     }
     if ($propIds) {
         // 批量获取房源的默认图片
         $defaultImages = Model_Image_HzImage::getDefaultImagesByHouseIds($propIds);
         foreach ($defaultImages as $defaultImage) {
             $propertyList[$defaultImage['proid']]['imgUrl'] = $defaultImage->imageUrl();
         }
     }
     // 排序
     /*usort($propertyList, function ($a, $b) {
           if ($a['choiceTime'] == $b['choiceTime']) {
               return 0;
           }
           return ($a['choiceTime'] > $b['choiceTime']) ? -1 : 1;
       });
       */
     usort($propertyList, function ($a, $b) {
         if (strtotime($a['updateTime']) == strtotime($b['updateTime'])) {
             return 0;
         }
         return strtotime($a['updateTime']) > strtotime($b['updateTime']) ? -1 : 1;
     });
     // 分组
     $onlinePropertyList = array();
     //推广中列表
     $waitPropertyList = array();
     //排队中列表
     $offlinePropertyList = array();
     //推广结束列表
     foreach ($propertyList as $property) {
         switch ($propPlanMap[$property['propId']]->status) {
             case '1':
                 $property['choiceStatus'] = 1;
                 $property['choiceStatusName'] = '精选中';
                 $onlinePropertyList[] = $property;
                 break;
             case '13':
                 $property['choiceStatus'] = 2;
                 $property['choiceStatusName'] = '排队中';
                 $waitPropertyList[] = $property;
                 break;
             default:
                 $property['isChoice'] = 0;
                 $property['choiceStatus'] = 3;
                 $property['choiceStatusName'] = '已结束';
                 $offlinePropertyList[] = $property;
         }
     }
     return array('status' => Const_APIStatus::RETURN_CODE_OK, 'data' => array('OnlinePropertyList' => $onlinePropertyList, 'QueuedPropertyList' => $waitPropertyList, 'OfflinePropertyList' => $offlinePropertyList));
 }