public static function &getInstance()
 {
     if (self::$_instance === null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemple #2
0
 public function handle_request_internal()
 {
     $fPropId = $this->_params['fPropId'];
     $userId = $this->_params['userId'];
     //获取房源库房源数据
     $fpropObj = Model_Fyk_PropLibrary::getDataById($fPropId);
     $fPropInfo = $fpropObj[0];
     $fPropInfoExtend = Bll_Fyk_Prop_Extend::getInstance()->getPropExtendInfo($fPropId);
     //查询用户是否购买这套房源
     $isBuy = $this->isBuyProp($userId, $fPropId);
     //组装数据
     $data = $this->dataCheck($fPropInfo, $fPropInfoExtend[$fPropId], $isBuy);
     $result = array('status' => 'ok', 'data' => $data);
     return $result;
 }
 /**
  * 判断是否为重复房源
  * @param $commId
  * @param $buildNum
  * @param $roomNum
  * @return bool
  */
 private function isSameProp($commId, $buildNum, $roomNum)
 {
     $isSameProp = false;
     $propInfo = Model_Fyk_PropLibrary::getSamePropInfo($commId, $buildNum, $roomNum);
     if (!empty($propInfo)) {
         $isSameProp = true;
     }
     return $isSameProp;
 }
 /**
  * @return Model_Fyk_PropLibrary|null
  * @throws Exception
  */
 public function prop()
 {
     return Model_Fyk_PropLibrary::data_access()->filter('id', $this->propId)->find_only();
 }
Exemple #5
0
 public function handle_request()
 {
     /**取任务记录*/
     $props = $this->getProps();
     $recommendProps = $this->getRecommendProps($props);
     //房源id 为key
     //没有推荐房源
     if (empty($recommendProps)) {
         // 更新游标
         $id = array_pop($props);
         if (!empty($id)) {
             $this->cursor['id'] = $id->id;
             $this->setFlag($this->cursor);
         }
         return;
     }
     $propIds = array_keys($recommendProps);
     $propInfos = Model_Fyk_PropLibrary::getDataById($propIds);
     //没有找到房源信息
     if (empty($propInfos)) {
         // 更新游标
         $id = array_pop($props);
         $this->cursor['id'] = $id->id;
         $this->setFlag($this->cursor);
         return;
     }
     //房源userId  fyk_user_props表中查找;
     $userProps = $this->getUserProps($propIds);
     $keyPropInfos = array();
     $commIds = array();
     foreach ($propInfos as $propInfo) {
         $commIds[] = $propInfo['commId'];
         $keyPropInfos[$propInfo['id']] = $propInfo;
         // 房源id 为key 房源信息
     }
     //批量小区位置
     $commLations = $this->getCommLation($commIds);
     //小区id 为key  小区坐标
     /**逐条处理任务*/
     foreach ($props as $prop) {
         if (!isset($recommendProps[$prop->propId])) {
             // todo update cursor
         } else {
             //取房源坐标和经纪人坐标->找到相应经纪人;
             $commId = $keyPropInfos[$prop->propId]['commId'];
             $sosolat = $commLations[$commId]['sosolat'];
             $sosolng = $commLations[$commId]['sosolng'];
             $km = 2000;
             //该房源无效
             if (empty($sosolat) || empty($sosolng)) {
                 //log
                 $this->cursor['id'] = $prop['id'];
                 $this->setFlag($this->cursor);
                 continue;
             }
             if (!empty($_SERVER['PG_TEST'])) {
                 //PG
                 $testBrokerIds = APF::get_instance()->get_config('fyk_pg_test_brokerIds');
                 $testCommIds = APF::get_instance()->get_config('fyk_pg_test_commIds');
                 $testUserIds = APF::get_instance()->get_config('fyk_pg_test_userIds');
             } else {
                 //GA
                 $testBrokerIds = APF::get_instance()->get_config('fyk_ga_test_brokerIds');
                 $testCommIds = APF::get_instance()->get_config('fyk_ga_test_commIds');
                 $testUserIds = APF::get_instance()->get_config('fyk_ga_test_userIds');
             }
             if (in_array($commId, $testCommIds)) {
                 //如果是测试小区的房子,则推给测试经纪人
                 foreach ($testBrokerIds as $testBrokerId) {
                     $test = new Model_Broker_BrokerActionCenter();
                     $test->brokerId = $testBrokerId;
                     $allBrokers[$testBrokerId] = $test;
                 }
                 $brokerUserIds = $testUserIds;
             } else {
                 list($allBrokers, $brokerUserIds) = $this->getBrokersWithinScope($sosolat, $sosolng, $km, '');
                 //2 限制人数
             }
             /** pg 测试经纪人 broerkIds */
             if (empty($allBrokers)) {
                 $this->cursor['id'] = $prop['id'];
                 $this->setFlag($this->cursor);
                 continue;
             }
             //插入fyk_push_props表
             foreach ($allBrokers as $broker) {
                 $params = array();
                 $params['userId'] = $brokerUserIds[$broker->brokerId];
                 $params['propId'] = $prop->propId;
                 $params['createTime'] = date('Y-m-d H:i:s', time());
                 $params['updateTime'] = date('Y-m-d H:i:s', time());
                 if (empty($params['userId'])) {
                     continue;
                 }
                 if (in_array($params['userId'], $userProps[$prop->propId])) {
                     continue;
                 }
                 $res = Model_Broker_FykPushProps::insertFykPushProps($params);
                 if ($res) {
                     //经纪人新推房源数加1
                     $brokerPropCountInfo = Model_Fyk_PushPropsLatestCount::getBrokerPropCount($brokerUserIds[$broker->brokerId]);
                     if ($brokerPropCountInfo) {
                         $brokerPropCountInfo->count += 1;
                         $brokerPropCountInfo->save();
                     } else {
                         $data = new Model_Fyk_PushPropsLatestCount();
                         $data->count = 1;
                         $data->userId = $brokerUserIds[$broker->brokerId];
                         $data->updateTime = date('Y-m-d H:i:s', time());
                         $data->save();
                     }
                 }
             }
         }
         // 更新游标
         $this->cursor['id'] = $prop['id'];
         $this->setFlag($this->cursor);
     }
 }
Exemple #6
0
 /**
  * 根据房源id查询小区id
  * @param $propIds
  * @return array
  */
 public function getCommIdsByPropIds($propIds)
 {
     return Model_Fyk_PropLibrary::getCommIdsByPropIds($propIds);
 }
 public function handle_request_internal()
 {
     $propLists = array();
     $hasNextPage = 0;
     $userId = $this->_params['userId'];
     $sinceId = isset($this->_params['sinceId']) ? intval($this->_params['sinceId']) : 0;
     $per = isset($this->_params['per']) ? $this->_params['per'] : 20;
     $propIds = Model_Broker_FykPushProps::data_access()->load_field('propId')->filter('userId', $userId)->sort('id', 'desc')->limit($per + 1)->offset($sinceId)->get_all();
     if (!empty($propIds)) {
         $hasNextPage = count($propIds) > $per ? 1 : 0;
         if ($hasNextPage) {
             array_pop($propIds);
             $sinceId = $sinceId + $per;
         } else {
             $sinceId = 0;
         }
         $propIds = self::getArrayColumn($propIds, 'propId');
         $props = Model_Fyk_PropLibrary::data_access()->filter('id', array_unique($propIds))->get_all();
         //获取小区、板块名称 start
         $commNames = $typeNames = array();
         $commIds = self::getArrayColumn($props, 'commId');
         /*$commInfos = Model_Community_AjkCommunity::data_access()
           ->filter('commId', $commIds)
           ->get_all();*/
         $commInfos = Bll_Community_APIComm::getInstance()->getInfoById($commIds);
         foreach ($commInfos as $info) {
             $commNames[$info['comm_id']] = $info['name'];
         }
         //————————————————————————————————————————————————
         $districtIds = self::getArrayColumn($props, 'areaId');
         $blockIds = self::getArrayColumn($props, 'blockId');
         $typeIds = array_merge($districtIds, $blockIds);
         $typeInfos = Model_City_TypeCode::data_access()->load_field('typeId')->load_field('typeName')->filter('typeId', $typeIds)->get_all();
         foreach ($typeInfos as $info) {
             $typeNames[$info['typeId']] = $info['typeName'];
         }
         //获取小区、板块名称 end
         foreach ($props as $prop) {
             //计算发布时间
             $publishDate = strtotime(date('Y-m-d', $prop['createTime']));
             $nowDate = strtotime(date('Y-m-d', time()));
             $publishDays = intval(($nowDate - $publishDate) / 86400);
             $propId = $prop['id'];
             $propList['fPropId'] = $propId;
             $propList['isOnly'] = $prop['isOnly'];
             $propList['isReal'] = $prop['isReal'];
             $propList['certificate'] = $prop['certificate'];
             $propList['commId'] = $prop['commId'];
             $propList['commName'] = $commNames[$prop['commId']];
             $propList['districtId'] = $prop['areaId'];
             $propList['districtName'] = $typeNames[$prop['areaId']];
             $propList['blockId'] = $prop['blockId'];
             $propList['blockName'] = $typeNames[$prop['blockId']];
             $propList['roomNum'] = $prop['cell'];
             $propList['hallNum'] = $prop['hall'];
             $propList['toiletNum'] = $prop['toilet'];
             $propList['area'] = $prop['acreage'];
             $propList['areaUnit'] = '平';
             $propList['price'] = intval($prop['totalPrices']);
             $propList['priceUnit'] = '万';
             $propList['publishDays'] = $publishDays;
             $propList['publishDaysMsg'] = $propList['publishDays'] > 0 ? "{$propList['publishDays']}天前发布" : '今天发布';
             $propLists[$propId] = $propList;
         }
     }
     $propListFormat = array();
     foreach ($propIds as $id) {
         $propListFormat[] = $propLists[$id];
     }
     unset($propLists);
     //更新为0
     Model_Fyk_PushPropsLatestCount::data_access()->set_field('count', 0)->filter('userId', $userId)->update();
     $data['props'] = $propListFormat;
     $data['sinceId'] = $sinceId;
     $data['hasNextPage'] = $hasNextPage;
     return API_Result::create()->ok()->data($data)->toArray();
 }
 public function handle_request()
 {
     //监控fyk_push_props表 如果有新增记录 生成推送信息推送
     $props = $this->getPushedRecommendProps();
     if (empty($props)) {
         // 更新游标
         $id = array_pop($props);
         if (!empty($id)) {
             $this->cursor['id'] = $id->id;
             $this->setFlag($this->cursor);
         }
         return;
     }
     $propIds = array();
     foreach ($props as $prop) {
         $propIds[] = $prop->propId;
     }
     //房源库房源信息
     $commIds = array();
     $keyPropInfos = array();
     $propInfos = Model_Fyk_PropLibrary::getDataById($propIds);
     if (empty($propInfos)) {
         // 更新游标
         $id = array_pop($props);
         $this->cursor['id'] = $id->id;
         $this->setFlag($this->cursor);
         return;
     }
     foreach ($propInfos as $propInfo) {
         $commIds[] = $propInfo['commId'];
         $keyPropInfos[$propInfo['id']] = $propInfo;
         // 房源id 为key 房源信息
     }
     //批量小区信息
     $commInfos = $this->getCommInfo($commIds);
     //小区id 为key  小区坐标
     foreach ($props as $prop) {
         $userId = $prop->userId;
         $brokerInfo = Model_Broker_AjkBrokerExtend::getBrokerInfoByUserId($userId);
         if (empty($brokerInfo)) {
             //更新游标
             $this->cursor['id'] = $prop->id;
             $this->setFlag($this->cursor);
             continue;
         }
         $brokerId = $brokerInfo->brokerId;
         //获取房源小区
         $commId = $keyPropInfos[$prop->propId]['commId'];
         if (empty($commId)) {
             //更新游标
             $this->cursor['id'] = $prop->id;
             $this->setFlag($this->cursor);
             continue;
         }
         $msg = $commInfos[$commId]['commName'] . '出现新房源';
         /** 消息推送 */
         $result = $this->push($brokerId, $msg);
         //更新游标
         $this->cursor['id'] = $prop->id;
         $this->setFlag($this->cursor);
     }
 }