mod_behavior = Model('behavior'); $this->method_dicts = []; $this->init_methods(); } public function analyse($time) { $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', $time) . '_path.log'; $fd = @fopen($path_file, "r"); if($fd == false) return false; while (!feof($fd)) { $line = fgets($fd,1024); if ($line !== false && !empty($line)) { $this->record($line); } } fclose($fd); return true; } 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 = $fparams['act']; $fop = $fparams['op']; $result['from_act'] = $fact; $result['from_op'] = $fop; $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 init_methods() { $this->method_dicts['login'] = function ($op, $params) { if ($op == 'getcodex' || $op == 'getcode') { $val = $params['mobile']; return ['type' => 'mobile', 'data' => $val]; } else { return []; } }; $this->method_dicts['special'] = function ($op, $params) { $val = intval($params['special_id']); return ['type' => 'special','data' => $val]; }; $this->method_dicts['goods_common'] = function ($op, $params) { 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]; } else { return []; } }; $this->method_dicts['search'] = function ($op, $params) { if($op == 'index' || $op == 'search_goods') { $keyword = urldecode($params['keyword']); $brandid = intval($params['brand_id']); $hotid = intval($params['hot_id']); $brand = brand_helper::instance()->name($brandid); $hot = category_helper::instance()->name($hotid); return ['type' => 'keyword','data' => "{$keyword}#{$brand}#{$hot}"]; } elseif($op == 'suggest_words') { $keyword = $params['keyword']; return ['type' => 'keyword','data' => "{$keyword}"]; } else { return []; } }; $this->method_dicts['cart'] = function ($op, $params) { if($op == 'addex') { $bl_id = intval($params['bl_id']); $goods_id = intval($params['goods_id']); if($bl_id > 0) { return ['type' => 'bl','data' => $bl_id]; } else { return ['type' => 'goods','data' => $goods_id]; } } elseif($op == 'edit') { $cart_id = intval($params['cart_id']); return ['type' => 'cart','data' => $cart_id]; } else { return []; } }; $this->method_dicts['member_buy'] = function ($op, $params) { if($op == 'step_first') { $cart_ids = urldecode($_POST['cart_id']); return ['type' => 'cart_ids','data' => $cart_ids]; } elseif($op == 'step_second') { $payment = $params['payment']; return ['type' => 'payment','data' => $payment]; } else { return []; } }; $this->method_dicts['member_bonus'] = function ($op, $params) { return []; }; } private function type_data($act,$op,$params) { if(empty($act) || empty($op)) return []; if(!array_key_exists($act,$this->method_dicts)) return []; return $this->method_dicts[$act]($op,$params); } 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; } }