|
@@ -0,0 +1,157 @@
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * Created by PhpStorm.
|
|
|
+ * User: stanley-king
|
|
|
+ * Date: 2018/9/1
|
|
|
+ * Time: 下午11:29
|
|
|
+ */
|
|
|
+
|
|
|
+namespace statistics;
|
|
|
+
|
|
|
+
|
|
|
+class behavior
|
|
|
+{
|
|
|
+ private $mod_behavior;
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->mod_behavior = Model('behavior');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function analyse($time)
|
|
|
+ {
|
|
|
+ $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', $time) . '_path.log';
|
|
|
+ $fd = @fopen($path_file, "r");
|
|
|
+
|
|
|
+ while (!feof($fd))
|
|
|
+ {
|
|
|
+ $line = fgets($fd,1024);
|
|
|
+ if ($line !== false && !empty($line)) {
|
|
|
+ $this->record($line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose($fd);
|
|
|
+ }
|
|
|
+ public function analyse_loop($time)
|
|
|
+ {
|
|
|
+ $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', $time) . '_path.log';
|
|
|
+ $fd = @fopen($path_file, "r");
|
|
|
+
|
|
|
+ while (!feof($fd))
|
|
|
+ {
|
|
|
+ $line = fgets($fd,1024);
|
|
|
+ if ($line !== false && !empty($line)) {
|
|
|
+ $this->record($line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fclose($fd);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function record($line)
|
|
|
+ {
|
|
|
+ $input = json_decode($line,true);
|
|
|
+ if($input == false) return;
|
|
|
+
|
|
|
+ $content = $input['content'];
|
|
|
+ unset($input['content']);
|
|
|
+
|
|
|
+ $params = $this->parse_act($content);
|
|
|
+
|
|
|
+ $item = array_merge($input,$params);
|
|
|
+ $this->mod_behavior->addBehavior($item);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function parse_act($content)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $params = $this->parse_content($content);
|
|
|
+ if(empty($params)) return $result;
|
|
|
+
|
|
|
+ $act = $params['act'];
|
|
|
+ $op = $params['op'];
|
|
|
+
|
|
|
+ $result['act'] = $act;
|
|
|
+ $result['op'] = $op;
|
|
|
+
|
|
|
+ $type_data = $this->type_data($act,$op,$params);
|
|
|
+ foreach ($type_data as $key => $val)
|
|
|
+ {
|
|
|
+ if($key == 'type') {
|
|
|
+ $result['ktype'] = $val;
|
|
|
+ }
|
|
|
+ if($key == 'data') {
|
|
|
+ $result['kdata'] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $from = $params['from'];
|
|
|
+ if(!empty($from))
|
|
|
+ {
|
|
|
+ $from = base64_decode($from);
|
|
|
+ $fparams = $this->parse_content($from);
|
|
|
+ $fact = $params['act'];
|
|
|
+ $fop = $params['op'];
|
|
|
+
|
|
|
+ $result['from_act'] = $act;
|
|
|
+ $result['from_op'] = $op;
|
|
|
+
|
|
|
+ $ftype_data = $this->type_data($fact,$fop,$fparams);
|
|
|
+ foreach ($ftype_data as $key => $val)
|
|
|
+ {
|
|
|
+ if($key == 'type') {
|
|
|
+ $result['from_ktype'] = $val;
|
|
|
+ }
|
|
|
+ if($key == 'data') {
|
|
|
+ $result['from_kdata'] = $val;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function type_data($act,$op,$params)
|
|
|
+ {
|
|
|
+ if(empty($act) || empty($op)) return [];
|
|
|
+
|
|
|
+ if($act == 'login')
|
|
|
+ {
|
|
|
+ if($op == 'getcodex' || $op == 'getcode') {
|
|
|
+ $val = $params['mobile'];
|
|
|
+ return ['type' => 'mobile','data' => $val];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ elseif($act == 'special') {
|
|
|
+ $val = intval($params['special_id']);
|
|
|
+ return ['type' => 'special','data' => $val];
|
|
|
+ }
|
|
|
+ elseif($act == 'goods_common')
|
|
|
+ {
|
|
|
+ if($op == 'index' || $op == 'detail' || $op == 'detail_ajax') {
|
|
|
+ $val = intval($params['goods_id']);
|
|
|
+ return ['type' => 'goods','data' => $val];
|
|
|
+ }
|
|
|
+ elseif($op == 'comments') {
|
|
|
+ $val = intval($params['goods_commonid']);
|
|
|
+ return ['type' => 'goods_common','data' => $val];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ private function parse_content($content)
|
|
|
+ {
|
|
|
+ $result = [];
|
|
|
+ $params = preg_split('/&|=/', $content);
|
|
|
+ for ($i = 0; $i < count($params); ++$i)
|
|
|
+ {
|
|
|
+ $key = $params[$i];
|
|
|
+ $val = $params[++$i];
|
|
|
+ $result[$key] = urldecode($val);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $result;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|