Ejemplo n.º 1
0
 /**
  * 根据房源ID 获取日志记录
  *
  * @param $propId
  * @param int $split
  * @return array
  */
 public static function getChangeListLogByProId($propId, $split = 0)
 {
     if ($split == 0) {
         $split = date('Ymd');
     }
     try {
         $changeLog = Model_House_HzProChangeLog::data_access($split)->filter('propId', $propId)->sort('id', 'asc')->get_all();
         if (is_null($changeLog)) {
             return array();
         }
         return $changeLog;
     } catch (Exception $e) {
         return array();
     }
 }
 /**
  * 统计房源在线时长
  *
  * @param int $brokerId
  * @param int $propId
  * @param int $propStatus
  */
 public function countHouseOnlineStatistics($brokerId, $propId, $propStatus)
 {
     $this->logMessage(sprintf('开始统计房源在线时长: brokerId=%d, propId=%d, propStatus=%d', $brokerId, $propId, $propStatus));
     $propChangeLogList = Model_House_HzProChangeLog::getChangeListLogByProId($propId, date('Ymd', strtotime('-1 day')));
     /** 如果房源没有操作日志,且房源在线,则去计划表查询,如果计划在线则24小时在线否则不记录 */
     if (empty($propChangeLogList) && $propStatus == Const_HzStatus::ONLINE) {
         $this->logMessage(sprintf('房源(%d)在线,但是昨天没有操作记录', $propId));
         $propPlannings = Model_Plan_HzPlanning::getPlanningByPropId($propId);
         foreach ($propPlannings as $propPlanning) {
             if ($propPlanning['is_valid'] != Const_HzPlan::SPREAD) {
                 continue;
             }
             $propPromotionTime = array('propId' => $propId, 'brokerId' => $brokerId, 'planId' => $propPlanning['plan_id'], 'planType' => $propPlanning['plan_type'], 'onlineDate' => date('Ymd', strtotime('-1 day')), 'onlineHour' => 24.0, 'minOnlineDatetime' => date('Y-m-d H:i:s', $this->yesterdayStartTimeStamp), 'maxOfflineDatetime' => date('Y-m-d H:i:s', $this->yesterdayEndTimeStamp));
             $this->savePropPromotionTime($propPromotionTime);
         }
         return;
     }
     $propChangeInfo = array();
     /** 只使用最后一个记录 */
     foreach ($propChangeLogList as $propChangeLog) {
         $propChangeInfo[$propChangeLog['type']] = $propChangeLog;
     }
     foreach ($propChangeLogList as $spreadType => $lastPropChangeLog) {
         /** 最后一条记录为上架操作 */
         if ($lastPropChangeLog['action'] == Model_House_HzProChangeLog::HOUSE_CHANGE_ACTION_UP) {
             $onlineHour = $lastPropChangeLog['time'] + ($this->yesterdayEndTimeStamp - strtotime($lastPropChangeLog['logTime']));
             $minOnlineDatetime = $lastPropChangeLog['logTime'];
             $maxOfflineDatetime = date('Y-m-d H:i:s', $this->yesterdayEndTimeStamp);
         } else {
             /** 最后一条数据为下架操作 */
             if ($lastPropChangeLog['time'] == 0) {
                 $onlineHour = strtotime($lastPropChangeLog['logTime']) - $this->yesterdayStartTimeStamp;
             } else {
                 $onlineHour = $lastPropChangeLog['time'];
             }
             $minOnlineDatetime = date('Y-m-d H:i:s', $this->yesterdayStartTimeStamp);
             $maxOfflineDatetime = $lastPropChangeLog['logTime'];
         }
         $onlineHour = $onlineHour > 86400 ? 86400 : $onlineHour;
         $propPromotionTime = array('propId' => $propId, 'brokerId' => $brokerId, 'planId' => $lastPropChangeLog['spreadId'], 'planType' => $spreadType, 'onlineDate' => date('Ymd', strtotime('-1 day')), 'onlineHour' => round($onlineHour / 60, 1), 'minOnlineDatetime' => $minOnlineDatetime, 'maxOfflineDatetime' => $maxOfflineDatetime);
         $this->savePropPromotionTime($propPromotionTime);
     }
 }
 /**
  * 统计房源在线时长
  *
  * @param int $brokerId
  * @param int $propId
  * @param int $propStatus
  */
 public function countHouseOnlineStatistics($brokerId, $propId, $propStatus)
 {
     $this->logMessage(sprintf('开始统计房源在线时长: brokerId=%d, propId=%d, propStatus=%d', $brokerId, $propId, $propStatus));
     $propChangeLogList = Model_House_HzProChangeLog::getChangeListLogByProId($propId, date('Ymd', strtotime('-1 day')));
     /** 如果房源没有操作日志,且房源在线,则去计划表查询,如果计划在线则24小时在线否则不记录 */
     if (empty($propChangeLogList)) {
         $this->logMessage(sprintf('房源(%d)在线,但是昨天没有操作记录', $propId));
         $propPlannings = Model_Plan_HzPlanningDS::getPlanningByPropId($propId);
         $this->outTime('Model_Plan_HzPlanningDS::getPlanningByPropId(' . $propId . ');');
         foreach ($propPlannings as $propPlanning) {
             // 计划关系状态 is_valid = 1 继续
             if ($propPlanning['is_valid'] != Const_HzPlan::SPREAD) {
                 continue;
             }
             // 验证计划状态
             $planBasic = Model_Plan_HzPlanBasicDS::get_plan_by_id($propPlanning['plan_id']);
             if ($planBasic['status'] != '1' or $planBasic['flag'] != '1') {
                 continue;
             }
             $propPromotionTime = array('propId' => $propId, 'brokerId' => $brokerId, 'planId' => $propPlanning['plan_id'], 'planType' => $propPlanning['plan_type'], 'onlineDate' => date('Ymd', strtotime('-1 day')), 'onlineHour' => 24.0, 'minOnlineDatetime' => date('Y-m-d H:i:s', $this->yesterdayStartTimeStamp), 'maxOfflineDatetime' => date('Y-m-d H:i:s', $this->yesterdayEndTimeStamp));
             $this->savePropPromotionTime($propPromotionTime);
         }
         return;
     }
     $propChangeInfo = array();
     /** 只使用最后一个记录 */
     foreach ($propChangeLogList as $propChangeLog) {
         //套餐房源,合到定价里面 20140827
         $propChangeLog['type'] = $propChangeLog['type'] == 3 ? 1 : $propChangeLog['type'];
         $propChangeInfo[$propChangeLog['type']] = $propChangeLog;
     }
     foreach ($propChangeInfo as $spreadType => $lastPropChangeLog) {
         /** 最后一条记录为上架操作 */
         if ($lastPropChangeLog['action'] == Model_House_HzProChangeLog::HOUSE_CHANGE_ACTION_UP) {
             $onlineHour = $lastPropChangeLog['time'] + ($this->yesterdayEndTimeStamp - strtotime($lastPropChangeLog['logTime']));
             $minOnlineDatetime = $lastPropChangeLog['logTime'];
             $maxOfflineDatetime = date('Y-m-d H:i:s', $this->yesterdayEndTimeStamp);
         } else {
             /** 最后一条数据为下架操作 */
             if ($lastPropChangeLog['time'] == 0) {
                 $onlineHour = strtotime($lastPropChangeLog['logTime']) - $this->yesterdayStartTimeStamp;
             } else {
                 $onlineHour = $lastPropChangeLog['time'];
             }
             $minOnlineDatetime = date('Y-m-d H:i:s', $this->yesterdayStartTimeStamp);
             $maxOfflineDatetime = $lastPropChangeLog['logTime'];
         }
         $onlineHour = $onlineHour > 86400 ? 86400 : $onlineHour;
         $propPromotionTime = array('propId' => $propId, 'brokerId' => $brokerId, 'planId' => $lastPropChangeLog['spreadId'], 'planType' => $spreadType, 'onlineDate' => date('Ymd', strtotime('-1 day')), 'onlineHour' => round($onlineHour / 3600, 1), 'minOnlineDatetime' => $minOnlineDatetime, 'maxOfflineDatetime' => $maxOfflineDatetime);
         $this->savePropPromotionTime($propPromotionTime);
     }
     // 日志表里当天有竞价没有定价变更记录的情况
     if (count($propChangeInfo) == 1 && isset($propChangeInfo[2])) {
         $propPlanning = Model_Plan_HzPlanningDS::getPropFixPlan($propId);
         $propPromotionTime = array('propId' => $propId, 'brokerId' => $brokerId, 'planId' => $propPlanning['plan_id'], 'planType' => 1, 'onlineDate' => date('Ymd', strtotime('-1 day')), 'onlineHour' => 24, 'minOnlineDatetime' => date('Y-m-d H:i:s', $this->yesterdayStartTimeStamp), 'maxOfflineDatetime' => date('Y-m-d H:i:s', $this->yesterdayEndTimeStamp));
         $this->savePropPromotionTime($propPromotionTime);
     }
 }
Ejemplo n.º 4
0
 /**
  * 房源推广变更日志生成 ppc_db.Hz_Pro_Change_Log_
  *
  * <ol>
  * <li>
  * 当房源日志type为房源推广(5)时,对应推广变更日志action=1
  * </li>
  * <li>
  * 当房源日志type为取消推广(6)时,对应推广变更日志action=2
  * </li>
  * <li>
  * 当房源日志type为取消推广(14)时,对应精选推广变更日志action=1
  * </li>
  * <li>
  * 当房源日志type为取消推广(15)时,对应精选推广变更日志action=2
  * </li>
  * <li>
  * 其他不处理
  * </li>
  * </ol>
  *
  * @param array $records 定价上下架房源日志数据(租房篇)
  */
 public function proSpreadChangeLogCreateHz($record)
 {
     if ($record['siteType'] != 2) {
         //记录处理日志
         $this->setLog('改网站类型的数据暂不处理(定价推广变更日志)');
         return true;
     }
     $type = $record['type'];
     $date = date('Ymd', strtotime($record['addDate']));
     if ($type == 5) {
         $action = 1;
         $type = 1;
     } elseif ($type == 6) {
         $action = 2;
         $type = 1;
     } elseif ($type == 14) {
         $action = 1;
         $type = 2;
     } elseif ($type == 15) {
         $action = 2;
         $type = 2;
     } elseif ($type == 21) {
         $type = 3;
         $action = 2;
     } elseif ($type == 20) {
         $type = 3;
         $action = 1;
     } else {
         //记录处理日志
         $this->setLog('不需要生成推广变更日志');
         return true;
     }
     $dataObject = new Model_House_HzProChangeLog($date);
     //查询最近的日志
     $ChangeLogInfo = $dataObject->getChangeLogByProId($record['houseId'], $date, $type);
     $Time = 0;
     //展示时间
     if (!empty($ChangeLogInfo)) {
         switch ($ChangeLogInfo['action']) {
             case 1:
                 //上一条为推广
                 if ($action == 1) {
                     //本次为推广
                     $Time = $ChangeLogInfo['time'];
                 }
                 if ($action == 2) {
                     //本次为取消推广
                     $Time = $ChangeLogInfo['time'] + time() - strtotime($ChangeLogInfo['logTime']);
                 }
                 break;
             case 2:
                 //上一条为取消推广
                 if ($action == 1) {
                     //本次为推广
                     if (empty($ChangeLogInfo['time'])) {
                         //上一条取消推广时间为0
                         $Time = strtotime($ChangeLogInfo['logTime']) - strtotime(substr($ChangeLogInfo['logTime'], 0, 10));
                     } else {
                         $Time = $ChangeLogInfo['time'];
                     }
                 }
                 if ($action == 2) {
                     //本次为取消推广
                     $Time = $ChangeLogInfo['time'];
                 }
                 break;
             default:
         }
     }
     $dataObject->propId = $record['houseId'];
     $dataObject->brokerId = $record['brokerId'];
     $dataObject->time = $Time;
     $dataObject->action = $action;
     $dataObject->type = $type;
     $dataObject->logTime = date('Y-m-d H:i:s');
     $dataObject->actionId = 0;
     //触发动作id
     $dataObject->spreadId = $record['planId'] ? $record['planId'] : 0;
     //计划id
     if (!$dataObject->save()) {
         //记录处理日志
         $this->setLog('推广变更日志生成失败');
     } else {
         $this->setLog('推广变更日志生成成功');
     }
     return true;
 }