/** * 统计房源在线时长 * * @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); } }
/** * 新增加房源计划 * * @param array $data * @return int */ public static function addPropPlan($data) { try { $oPropPlan = new Model_Plan_HzPlanningDS(); return $oPropPlan->save($data); } catch (Exception $e) { return 0; } }