Example #1
0
 /**
  * 重载save方法,为了增加modId
  * @param array $data
  * @return int
  */
 public function save($data = array())
 {
     $temp = array();
     foreach ($this->properties() as $property) {
         if (!is_null($this->{$property})) {
             $temp[$property] = $this->{$property};
         }
     }
     $log = '';
     try {
         if (1 == parent::save($data)) {
             $temp['id'] = $this->id;
             Model_Log_HouseLogIndexNew::doubleWrite(array_merge($temp, $data), $this->splitSuffix);
             return 1;
         }
     } catch (Exception $e) {
         $log = $e->getTraceAsString();
     }
     $logFile = sprintf('/data1/logs/Model_House_HouseLogIndex-%d.log', $this->splitSuffix);
     @file_put_contents($logFile, sprintf('[%s] %s %s' . PHP_EOL, date('Y-m-d H:i:s'), __CLASS__, json_encode($temp)), FILE_APPEND);
     if ($log != '') {
         @file_put_contents($logFile, sprintf('[%s] %s %s' . PHP_EOL, date('Y-m-d H:i:s'), __CLASS__, $log), FILE_APPEND);
     }
     return 0;
 }
Example #2
0
 public function handle_request()
 {
     //分表
     $date = date('Ymd');
     $id = 0;
     //获取游标
     $dateFlag = $this->getFlag();
     if (!empty($dateFlag)) {
         $date = $dateFlag['date'];
         $id = $dateFlag['id'];
     }
     //竞价队列数据获取
     $ProLogList = Model_Log_HouseLogNew::getProLogList($date, $id, $this->limit);
     //判断当前队列是否处理完成
     if (empty($ProLogList)) {
         //判断是否切换表
         if ($date < date('Ymd')) {
             $date = date('Ymd', strtotime($date) + 24 * 3600);
             $id = 0;
             //记录表游标
             $this->setFlag(array('date' => $date, 'id' => $id));
         }
         //休息1秒钟
         $this->setShCommonSleepTime(1);
         $this->setLog(date('Y-m-d H:i:s') . ' 处理完成');
         exit;
     }
     //队列数据处理
     foreach ($ProLogList as $list) {
         $id = $list['id'];
         $time = 0;
         //查询房源的发布时间
         if ($list['siteType'] == 1) {
             //二手房
             $ajkProInfo = Bll_House_EsfHouse::getHouseInfo($list['houseId'], $list['cityId']);
             if ($ajkProInfo->postDate) {
                 $time = $ajkProInfo->postDate;
             }
         } elseif ($list['siteType'] == 2) {
             $hzProInfo = Model_House_HzPropSearch::get_prop_by_prop_id($list['cityId'], $list['houseId']);
             if ($hzProInfo['created']) {
                 $time = $hzProInfo['created'];
             }
         } elseif ($list['siteType'] == 3) {
             $jpProInfo = Model_House_JpHouseIdx::getPropInfoByPk($list['houseId']);
             if ($jpProInfo['createTime']) {
                 $time = strtotime($jpProInfo['createTime']);
             }
         }
         //写索引表
         if (!empty($time)) {
             //查询数据是否存在
             $ProLogIndex = Model_Log_HouseLogIndexNew::getProLogIndexByProId($list['houseId'], date('Ymd', strtotime($list['addDate'])), $list['siteType'], date('Ymd', $time));
             if (!empty($ProLogIndex)) {
                 //记录处理日志
                 $this->setLog(date('Y-m-d H:i:s') . ' id:' . $list['id'] . ' 城市id:' . $list['cityId'] . ' 经纪人:' . $list['brokerId'] . ' 房源:' . $list['houseId'] . ' 网站:' . $list['siteType'] . '  房源创建时间:' . date('Y-m-d H:i:s', $time) . ' remark:索引已存在');
                 continue;
             }
             try {
                 Model_Log_HouseLogIndexNew::create(array('proId' => $list['houseId'], 'datei' => date('Ymd', strtotime($list['addDate'])), 'siteType' => $list['siteType']), date('Ymd', $time))->save();
             } catch (Exception $e) {
                 print_r($e);
             }
             //记录处理日志
             $this->setLog(date('Y-m-d H:i:s') . ' id:' . $list['id'] . ' 城市id:' . $list['cityId'] . ' 经纪人:' . $list['brokerId'] . ' 房源:' . $list['houseId'] . ' 网站:' . $list['siteType'] . '  房源创建时间:' . date('Y-m-d H:i:s', $time) . ' remark:创建索引');
         } else {
             //记录处理日志
             $this->setLog(date('Y-m-d H:i:s') . ' id:' . $list['id'] . ' 城市id:' . $list['cityId'] . ' 经纪人:' . $list['brokerId'] . ' 房源:' . $list['houseId'] . ' 网站:' . $list['siteType'] . '  remark:未找到房源信息');
         }
     }
     $this->setFlag(array('date' => $date, 'id' => $id));
     //休息10毫秒
     $this->setShCommonSleepTime(0.01);
 }