public function handle_request()
 {
     /** 房源删除 */
     if ($this->_dealType == 0) {
         $condition = array(array('id', '>', $this->_startId), array('updatedTime', '>=', $this->_startTime), array('updatedTime', '<=', $this->_endTime));
         $houseList = Model_House_JpHouseIdx::getPropLists($condition, self::BATCH_LIMIT);
         foreach ($houseList as $house) {
             $this->setFlag(array('id' => $house['id'], 'time' => date('Y-m-d H:i:s')), $this->_cursorFile);
             /** 房源被删除 */
             if ($house['isDelete'] == Model_House_JpHouseIdx::ENUM_IS_DELETE_YES) {
                 $this->logMsg(sprintf('房源[%d]: 被删除[%s]', $house['id'], json_encode($house)));
                 $this->repairComboSpreadRelation($house['memberId'], $house['id'], self::HOUSE_STATE_DELETE, $house['houseType']);
                 continue;
             }
             $this->logMsg(sprintf('房源[%d] 无需处理[%s]', $house['id'], json_encode($house)));
         }
         $this->done(count($houseList));
     } else {
         $houseList = $this->getHouseList();
         foreach ($houseList as $house) {
             $this->setFlag(array('id' => $house['id'], 'time' => date('Y-m-d H:i:s')), $this->_cursorFile);
             /** 房源违规 */
             if ($house['isIllegal'] == 1) {
                 $this->logMsg(sprintf('房源[%d]: 被违规[%s]', $house['id'], json_encode($house)));
                 $this->repairComboSpreadRelation($house['memberId'], $house['id'], self::HOUSE_STATE_ILLEGAL, $house['houseType']);
                 continue;
             }
             /** 房源过期 */
             if ($house['isExpired'] == 1) {
                 $this->logMsg(sprintf('房源[%d]: 被过期[%s]', $house['id'], json_encode($house)));
                 $this->repairComboSpreadRelation($house['memberId'], $house['id'], self::HOUSE_STATE_EXPIRED, $house['houseType']);
                 continue;
             }
             $this->logMsg(sprintf('房源[%d] 无需处理[%s]', $house['id'], json_encode($house)));
         }
         $this->done(count($houseList));
     }
 }
 private function modifyHouse($task)
 {
     //取数据
     $params = array(array('id', '>', 0), array('propertyId', '=', $task['propertyId']), array('houseType', 'in', array(1, 2, 3, 4)));
     $sort = array('id', 'asc');
     $tasks = Model_House_JpHouseIdx::getPropLists($params, $this->houseLimit, $sort);
     if (empty($tasks)) {
         return array('status' => 'none', 'msg' => 'house list is empty');
     }
     while ($tasks) {
         //处理数据
         foreach ($tasks as $key => $val) {
             $this->cursor = $val['id'];
             if ($val['isDelete'] == 1) {
                 continue;
             }
             //判断房源信息是否需要修改
             $houseModelClass = Model_House_JpHouseIdx::getHouseTypeModelClass($val['houseType']);
             $dataAccess = $houseModelClass::data_access('');
             $dataAccess->filter('id', $val['id']);
             //                $dataAccess->filter('districtId', $task['areaId']);
             //                $dataAccess->filter('blockId', $task['blockId']);
             $result = $dataAccess->get_row();
             if (empty($result)) {
                 continue;
             }
             //非自选
             if ($val['houseType'] == 1 || $val['houseType'] == 2) {
                 if ($result['buildingId'] == $task['propertyId']) {
                     try {
                         // call api update house
                         $data = array('officeId' => $val['id']);
                         $result = $this->updateBuildingHouse($data);
                         $info = $result['info'];
                         if ($result['status'] == 'ok') {
                             $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 成功 】data:' . $info);
                         } else {
                             $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 失败 】data:' . $info);
                         }
                     } catch (Exception $e) {
                         $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 异常 】');
                         $this->setLog($e->getMessage());
                     }
                 }
             } elseif ($val['houseType'] == 3 || $val['houseType'] == 4) {
                 if ($result['propertyId'] == $task['propertyId']) {
                     try {
                         // call api update house
                         $data = array('shopId' => $val['id'], 'districtId' => $this->newDistrictId, 'blockId' => $this->newBlockId);
                         $result = $this->updateShopHouse($data);
                         $info = $result['info'];
                         if ($result['status'] == 'ok') {
                             $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 成功 】data:' . $info);
                         } else {
                             $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 失败 】data:' . $info);
                         }
                     } catch (Exception $e) {
                         $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源[ ' . $val['id'] . ' ]分表[ ' . $val['houseType'] . ' ]的districtId=' . $this->newDistrictId . ',blockId=' . $this->newBlockId . ' 【 异常 】');
                         $this->setLog($e->getMessage());
                     }
                 }
             }
         }
         $this->setLog('[' . date('Y-m-d H:i:s') . '] updateHouse: 更新房源 current cursor: ' . $this->cursor);
         //取数据
         $params = array(array('id', '>', $this->cursor), array('propertyId', '=', $task['propertyId']), array('houseType', 'in', array(1, 2, 3, 4)));
         $sort = array('id', 'asc');
         $tasks = Model_House_JpHouseIdx::getPropLists($params, $this->houseLimit, $sort);
     }
     return array('status' => 'over', 'msg' => 'house list is empty');
 }
Esempio n. 3
0
 /**
  * Job执行逻辑
  */
 public function handle_request()
 {
     printf('[%s] lastLogId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $this->lastLogId);
     $this->setLog(sprintf('[%s] lastLogId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $this->lastLogId));
     // 获取非删除的房子
     $params = array(array('isDelete', '=', 0), array('id', '>', $this->lastLogId));
     if ($this->cityIds) {
         $params = array(array('isDelete', '=', 0), array('cityId', 'in', $this->cityIds), array('id', '>', $this->lastLogId));
     }
     $tasks = Model_House_JpHouseIdx::getPropLists($params, $this->limit);
     if ($tasks === false) {
         $this->setLog(sprintf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '获取数据失败'));
         exit;
     }
     if (empty($tasks)) {
         // 任务完成
         printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '任务执行完成');
         $this->setStop();
         $this->setShStopFlag();
         $this->setFlag(array('lastLogId' => 0));
         exit;
     }
     $doProps = array();
     /** 本次处理的房子 */
     $doTmpProIds = array();
     $solrProIdsTmp = array();
     $solrProIds = array();
     foreach ($tasks as $task) {
         $this->lastLogId = $task['id'];
         $doProps[$task['id']] = $task;
         $doTmpProIds[$task['houseType']][] = $task['id'];
     }
     foreach ($doTmpProIds as $type => $proIds) {
         printf('[%s] 获取solr, type: %s, proId: %s' . PHP_EOL, date('Y-m-d H:i:s'), $type, json_encode($proIds));
         // 获取solr
         $solrs = Util_SearchUtil::getJpPropsFromSolr($this->getTypeByHouseType($type), $proIds, $this->limit);
         if (!empty($solrs)) {
             $solrProIdsTmp[$type] = $solrs;
         }
     }
     // 扁平处理
     if (!empty($solrProIdsTmp)) {
         foreach ($solrProIdsTmp as $items) {
             foreach ($items as $item) {
                 $solrProIds[] = $item['id'];
             }
         }
     }
     // 拿出不在线的进行处理
     $willDealProIds = array_diff(array_keys($doProps), $solrProIds);
     if (empty($willDealProIds)) {
         printf('[%s] remark: %s' . PHP_EOL, date('Y-m-d H:i:s'), '本轮取的房子都在线,不需要处理');
         //记录游标
         $this->setFlag(array('lastLogId' => $this->lastLogId));
         die;
     }
     // 循环处理任务
     foreach ($willDealProIds as $willDealProId) {
         $this->dealTask($doProps[$willDealProId]);
     }
     //记录游标
     $this->setFlag(array('lastLogId' => $this->lastLogId));
 }