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); } }