get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR; $list = scandir($dir); $thisList = array(); $name = 'Pass_log_'.date('Y_m_d',strtotime('-1 day today')); foreach($list as $data){ if(strpos($data, $name) !== false){ $thisList[$data] = $dir.$data; } } $allData = array(); $eventsArr = array(); $tmpEventsIp = array(); $tmpEventsUV = array(); foreach($thisList as $thisDir){ $string = file_get_contents($thisDir); $d = explode("\n", $string); foreach($d as $key=> $s){ if($s){ $arr = unserialize($s); if(isset($eventsArr[$arr['event_id']]['pv'])){ $eventsArr[$arr['event_id']]['pv'] ++; }else{ $eventsArr[$arr['event_id']]['pv'] = 1; } $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip']; $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent']; $allData[] = $arr; } } } # PV # IP foreach($tmpEventsIp as $events_id => $ips){ $eventsArr[$events_id]['ip'] = count($ips); } # UV foreach($tmpEventsUV as $events_id => $vps){ $eventsArr[$events_id]['uv'] = count($vps); } # 用户参与数 $objLotteryLog = new LotteryUserParticipateLog(); foreach($eventsArr as $events_id => $data){ $info = array(); $time = strtotime('-1 day today'); /* $start = $this->maketime(date('Y-m-d 00:00:00', $time)); $end = $time; # 参与人数 $info ['user_num'] = $objLotteryLog->getUserParticipateLogNumGroupByUidDate ($events_id, $start, $end); */ $info ['events_id'] = $events_id ; $info ['pv_num'] = $data['pv'] ; $info ['uv_num'] = $data['uv'] ; $info ['ip_num'] = $data['ip'] ; $info ['date'] = $time; $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE); } } /** * 跑出今天的 IP PV UV * php /export/manager/v2/v2_cas/www/index.php -cIndex -asetuser */ public function doToday() { $objDLotteryPvUvLog = new LotteryPvUvLog (); # 获取今天目录下 $Y = date('Y'); $m = date('m'); $dir =Config::getInstance ()->get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR; $list = scandir($dir); $thisList = array(); $name = 'Pass_log_'.date('Y_m_d'); foreach($list as $data){ if(strpos($data, $name) !== false){ $thisList[$data] = $dir.$data; } } $allData = array(); $eventsArr = array(); $tmpEventsIp = array(); $tmpEventsUV = array(); foreach($thisList as $thisDir){ $string = file_get_contents($thisDir); $d = explode("\n", $string); foreach($d as $key=> $s){ if($s){ $arr = unserialize($s); if(isset($eventsArr[$arr['event_id']]['pv'])){ $eventsArr[$arr['event_id']]['pv'] ++; }else{ $eventsArr[$arr['event_id']]['pv'] = 1; } $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip']; $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent']; $allData[] = $arr; } } } # PV # IP foreach($tmpEventsIp as $events_id => $ips){ $eventsArr[$events_id]['ip'] = count($ips); } # UV foreach($tmpEventsUV as $events_id => $vps){ $eventsArr[$events_id]['uv'] = count($vps); } # 用户参与数 $objLotteryLog = new LotteryUserParticipateLog(); foreach($eventsArr as $events_id => $data){ $info = array(); $time = date(); $start = $this->maketime(date('Y-m-d 00:00:00', $time)); $end = $time; # 参与人数 $info ['user_num'] = $objLotteryLog->getUserParticipateLogNumGroupByUidDate ($events_id, $start, $end); $info ['events_id'] = $events_id ; $info ['pv_num'] = $data['pv'] ; $info ['uv_num'] = $data['uv'] ; $info ['ip_num'] = $data['ip'] ; $info ['date'] = $time; $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE); } } public function maketime($v) { if (!$v) { return ''; } if (is_numeric($v)) { return $v; } if (is_array($v)) { $v = $v[1]; } if (strstr($v, ' ')) { $t = explode(' ', $v); $v = $t[0]; $s = explode(':', $t[1]); } else { $s = array(0, 0, 0); } if (!isset($s[1])) { $s[1] = 0; } if (!isset($s[2])) { $s[2] = 0; } if (strstr($v, '-')) { $t = explode('-', $v); } elseif (strstr($v, '/')) { $u = explode('/', $v); $t[0] = $u[2]; $t[1] = $u[0]; $t[2] = $u[1]; } if (!isset($t)) { $t = array(0, 0, 0); } if (!isset($t[1])) { $t[1] = 0; } if (!isset($t[2])) { $t[2] = 0; } $v = mktime($s[0], $s[1], $s[2], $t[1], $t[2], $t[0]); return $v; } }