RunLog.class.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace Cas\Controller\CmdLine;
  3. use Cas\Dao\LotteryPvUvLog;
  4. use KIF\Core\Config;
  5. /**
  6. * 分析前一天 /log/Pass_log 访问日志
  7. *
  8. * php index.php -cCmdLine_RunLog -aRun
  9. */
  10. class RunLog extends Controller {
  11. public function doDefault() {
  12. }
  13. /**
  14. * 跑出前一天的活动的 IP PV UV
  15. * php /export/manager/v2/v2_cas/www/index.php -cCmdLine_RunLog -aRun
  16. */
  17. public function doRun() {
  18. $objDLotteryPvUvLog = new LotteryPvUvLog ();
  19. # 获取昨天目录下 所有的
  20. $Y = date('Y',strtotime('-1 day today'));
  21. $m = date('m',strtotime('-1 day today'));
  22. $dir =Config::getInstance ()->get ( 'Log_Path' ).DIRECTORY_SEPARATOR.$Y.DIRECTORY_SEPARATOR.$m.DIRECTORY_SEPARATOR;
  23. $list = scandir($dir);
  24. $thisList = array();
  25. $name = 'Pass_log_'.date('Y_m_d',strtotime('-1 day today'));
  26. foreach($list as $data){
  27. if(strpos($data, $name) !== false){
  28. $thisList[$data] = $dir.$data;
  29. }
  30. }
  31. $allData = array();
  32. $eventsArr = array();
  33. $tmpEventsIp = array();
  34. $tmpEventsUV = array();
  35. foreach($thisList as $thisDir){
  36. $string = file_get_contents($thisDir);
  37. $d = explode("\n", $string);
  38. foreach($d as $key=> $s){
  39. if($s){
  40. $arr = unserialize($s);
  41. if(isset($eventsArr[$arr['event_id']]['pv'])){
  42. $eventsArr[$arr['event_id']]['pv'] ++;
  43. }else{
  44. $eventsArr[$arr['event_id']]['pv'] = 1;
  45. }
  46. $tmpEventsIp[$arr['event_id']][$arr['ip']] = $arr['ip'];
  47. $tmpEventsUV[$arr['event_id']][$arr['ip'].$arr['user_agent']] = $arr['ip'].$arr['user_agent'];
  48. $allData[] = $arr;
  49. }
  50. }
  51. }
  52. # PV
  53. # IP
  54. foreach($tmpEventsIp as $events_id => $ips){
  55. $eventsArr[$events_id]['ip'] = count($ips);
  56. }
  57. # UV
  58. foreach($tmpEventsUV as $events_id => $vps){
  59. $eventsArr[$events_id]['uv'] = count($vps);
  60. }
  61. foreach($eventsArr as $events_id => $data){
  62. $info = array();
  63. $info ['events_id'] = $events_id ;
  64. $info ['pv_num'] = $data['pv'] ;
  65. $info ['uv_num'] = $data['uv'] ;
  66. $info ['ip_num'] = $data['ip'] ;
  67. $info ['date'] = strtotime('-1 day today');
  68. $objDLotteryPvUvLog->add ( $info ,LotteryPvUvLog::PARAM_CREATE_ACTION_ONDUPLICATE);
  69. }
  70. }
  71. }