Kaynağa Gözat

add behavior stat

stanley-king 6 yıl önce
ebeveyn
işleme
c0605f79b2

+ 9 - 10
core/framework/core/base.php

@@ -105,15 +105,15 @@ final class Base
 
 		if(!empty($main))
 		{
-			$function = $_GET['op'].'Op';
-			if (method_exists($main,$function)) {
-				$main->$function();
-			} elseif (method_exists($main,'indexOp')) {
-				$main->indexOp();
-			} else {
-				$error = "Base Error: function {$function} not in $class_name!";
-				throw new Exception($error);
-			}
+            $function = $_GET['op'].'Op';
+            if (method_exists($main,$function)) {
+                $main->$function();
+            } elseif (method_exists($main,'indexOp')) {
+                $main->indexOp();
+            } else {
+                $error = "Base Error: function {$function} not in $class_name!";
+                throw new Exception($error);
+            }
 		}
 		else {
 			$error = "Base Error: class {$class_name} isn't exists!";
@@ -121,7 +121,6 @@ final class Base
 		}
 	}
 
-
 	/**
 	 * run
 	 */

+ 18 - 10
core/framework/libraries/log.php

@@ -55,19 +55,27 @@ class Log
         }
     }
 
-    public static function record_path($message, $lev = self::DEBUG)
-    {
-        self::record($message, $lev);
+    static private $cur_path_file_name = '';
+    static private $cur_path_file;
 
-        $now = @date('Y-m-d H:i:s', time());
-        $pid = posix_getpid();
-        $level = 'USER_PATH';
-        $log_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '-path.log';
-        $content = "[{$pid} {$now}] {$level}: {$message}\r\n";
-        file_put_contents($log_file, $content, FILE_APPEND);
-        return;
+    public static function record_path($content)
+    {
+        $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '_path.log';
+        if(self::$cur_path_file_name != $path_file)
+        {
+            if(self::$cur_path_file != null) {
+                fclose(self::$cur_path_file);
+            }
+            self::$cur_path_file = fopen($path_file,'a');
+        }
 
+        if (@flock(self::$cur_path_file, LOCK_EX)) {
+            fwrite(self::$cur_path_file,$content);
+            fwrite(self::$cur_path_file,"\r\n");
+            @flock(self::$cur_path_file, LOCK_UN);
+        }
     }
+
     public static function record($message, $lev = self::ERR)
     {
         $now = @date('Y-m-d H:i:s', time());

+ 2 - 0
crontab/control/date.php

@@ -127,6 +127,7 @@ class dateControl extends BaseCronControl
             }
         }
     }
+
     public function init_relationOp()
     {
         $i = 0;
@@ -152,6 +153,7 @@ class dateControl extends BaseCronControl
             }
         }
     }
+
     public function skupriceOp()
     {
         $this->add_sku();

+ 21 - 0
data/model/behavior.model.php

@@ -0,0 +1,21 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: stanley-king
+ * Date: 2018/9/1
+ * Time: 下午11:41
+ */
+
+defined('InShopNC') or exit('Access Invalid!');
+
+class behaviorModel extends Model
+{
+    public function __construct()
+    {
+        parent::__construct('stat_behavior');
+    }
+
+    public function addBehavior($data) {
+        $this->insert($data);
+    }
+}

+ 0 - 4
helper/fcgi_server.php

@@ -102,9 +102,6 @@ class fcgi_server
 
                 $file = request_helper::script_file();
                 session::instance()->start();
-
-                $remote_addr = request_helper::remote_addr();
-                Log::record("file={$file} remoteaddr={$remote_addr}",Log::DEBUG);
                 Log::record("member_id=" . session_helper::memberid(),Log::DEBUG);
                 if(file_exists($file))
                 {
@@ -115,7 +112,6 @@ class fcgi_server
                     else
                     {
                         fcgi_header("Content-Type: text/html; charset=UTF-8");
-
                         if(!isset($_GET['act'])) {
                             $_GET['act'] = 'index';
                         }

+ 1 - 1
helper/request_helper.php

@@ -238,7 +238,7 @@ class request_helper
             $_SERVER['original_querystring'] = $squery;
         }
 
-        Log::record_path("content={$squery}",Log::DEBUG);
+        Log::record("content={$squery}",Log::DEBUG);
         $params = preg_split('/&|=/', $squery);
         if ($method == 'get' || $method == 'post')
         {

+ 3 - 4
helper/room/base_room.php

@@ -153,7 +153,7 @@ abstract class base_room
         try
         {
             $minfo = $this->userinfos($user);
-            $str = "{$minfo['nickname']}贡献了{$amount}元助力共享基金,兑换累计步数{$steps}步。<font color='#4A90E2'>一起参与助力吧!</font>";
+            $str = "{$minfo['nickname']}贡献了{$amount}元助力共享基金,兑换步数{$steps}步。<font color='#4A90E2'>一起参与助力吧!</font>";
             return $str;
         }
         catch (Exception $ex) {
@@ -165,7 +165,7 @@ abstract class base_room
         try
         {
             $minfo = $this->userinfos($user);
-            $str = "{$minfo['nickname']}使用了{$amount}元助力共享基金。<font color='#4A90E2'>一起参与助力吧!</font>";
+            $str = "{$minfo['nickname']}使用了{$amount}元共享基金,成功购物。<font color='#4A90E2'>一起参与助力吧!</font>";
             return $str;
         }
         catch (Exception $ex) {
@@ -210,8 +210,7 @@ abstract class base_room
                 $ret = $this->mod_room->invite($this->room_id(),$invitee,$inviter);
                 if($ret == false) {
                     continue;
-                }
-                else {
+                } else {
                     $user = $users[$invitee];
                     $uinfo = new member_info($user);
                     $this->mParticipants[$invitee] = ['nickname' => $uinfo->nickname(),'avatar' => $uinfo->avatar(),'userid' => intval($invitee)];

+ 1 - 1
helper/room_helper.php

@@ -155,7 +155,7 @@ class room_helper
         if($roomid > 0 && intval($amount * 100 + 0.5) > 0 && $userid > 0)
         {
             $mod_room = Model('room');
-            $mod_room->editRoom(['room_id' => $roomid],['shared_bonus' => ['exp',"bonus - {$amount}"]]);
+            $mod_room->editRoom(['room_id' => $roomid],['shared_bonus' => ['exp',"shared_bonus - {$amount}"]]);
             $content = ['user' => session_helper::memberid(),'amount' => $amount];
             room\factory_client::instance()->notice_room($roomid,room\proto_type::msg_stype_spend,$content);
         }

+ 13 - 0
helper/stat_helper.php

@@ -11,6 +11,7 @@ require_once (BASE_ROOT_PATH . '/helper/statistics/stbonus.php');
 require_once (BASE_ROOT_PATH . '/helper/statistics/stmember.php');
 require_once (BASE_ROOT_PATH . '/helper/statistics/statorder.php');
 require_once (BASE_ROOT_PATH . '/helper/statistics/statcall.php');
+require_once (BASE_ROOT_PATH . '/helper/statistics/behavior.php');
 
 class stat_helper
 {
@@ -147,4 +148,16 @@ class stat_helper
             Log::record($ex->getMessage(),Log::ERR);
         }
     }
+    public static function onDaiyBehavior($time)
+    {
+        try
+        {
+            $stat = new statistics\behavior();
+            $stat->analyse($time);
+        }
+        catch(Exception $ex)
+        {
+            Log::record($ex->getMessage(),Log::ERR);
+        }
+    }
 }

+ 156 - 0
helper/statistics/behavior.php

@@ -0,0 +1,156 @@
+<?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;
+    }
+
+}

+ 14 - 24
logmonitor.php

@@ -5,17 +5,11 @@
  * Date: 2018/8/30
  * Time: 下午2:51
  */
-//ini_set('ignore_user_abort', true);
-//set_time_limit(0);
+
 define('BASE_ROOT_PATH',str_replace('\\','/',dirname(__FILE__)));
 
 require_once (BASE_ROOT_PATH . '/fooder.php');
-Base::run_util();
-$monitor = new Monitor();
-
-while (true) {
-    $monitor->run_loop();
-}
+require_once (BASE_ROOT_PATH . '/helper/event_looper.php');
 
 class Monitor
 {
@@ -55,7 +49,6 @@ class Monitor
                     $this->checkStat();
                 }
 
-
                 usleep(1000);
             }
 
@@ -206,21 +199,6 @@ class Monitor
     }
 }
 
-//function monitor_work()
-//{
-//    Base::run_util();
-//    $monitor = new Monitor();
-//
-//    while (true) {
-//        $monitor->run_loop();
-//    }
-//}
-
-//function monitor_work()
-//{
-//    $fd = @fopen(BASE_ROOT_PATH . "/data/log/20180831.log", "r+");
-//
-//}
 
 class Parser
 {
@@ -270,3 +248,15 @@ class Parser
         return false;
     }
 }
+
+function work_proc()
+{
+    Base::run_util();
+    $monitor = new Monitor();
+
+    while (true) {
+        $monitor->run_loop();
+    }
+}
+
+event\util::fork_worker('work_proc',1);

+ 19 - 5
mobile/control/control.php

@@ -30,7 +30,7 @@ class mobileControl
     {
         self::$startime = microtime(true);
 
-        Language::read('mobile');
+        //Language::read('mobile');
         //分页数处理
         if (is_numeric($_GET['page']) && intval(trim($_GET['page'])) > 0) {
             $this->page_size = intval(trim($_GET['page']));
@@ -53,6 +53,24 @@ class mobileControl
         statistics_helper::instance()->add_call($param);
     }
 
+    public function __destruct()
+    {
+        $record = [];
+        $record['user_session'] = session_helper::session_id();
+        $record['member_id'] = session_helper::memberid();
+        $record['relay_id'] = session_helper::relay_id();
+        $record['add_time'] = time();
+        $record['exec_time'] = intval((microtime(true) - self::$startime) * 1000000);
+        $record['content'] = $_SERVER['original_querystring'];
+        $record['client_type'] = session_helper::client_type();
+
+        if(!empty($_GET['from'])) {
+            $from = base64_decode($_GET['from']);
+            Log::record("from={$from}",Log::DEBUG);
+        }
+        Log::record_path(json_encode($record));
+    }
+
     private function set_relay()
     {
         if(isset($_GET['relay_id'])) {
@@ -78,10 +96,6 @@ class mobileControl
         }
     }
 
-    public function __destruct()
-    {
-    }
-
     protected function android()
     {
         return $_SESSION['client_type'] == 'android';

+ 1 - 1
mobile/control/member_talk.php

@@ -1096,7 +1096,7 @@ class member_talkControl extends mbMemberControl
 
         $amount = bcdiv($steps,self::donate_rate,2);
         $mod_room->editRoomParts(['room_id' => $room_id,"member_id" => $user,"state" => 0],["steps" => ['exp',"steps + {$steps}"],"bonus" => ['exp',"bonus + {$amount}"]]);
-        $mod_room->editRoom(['room_id'=>$room_id],['steps_count' => ['exp',"steps_count + {$steps}"], 'shared_bonus' => ['exp',"bonus + {$amount}"]]);
+        $mod_room->editRoom(['room_id'=>$room_id],['steps_count' => ['exp',"steps_count + {$steps}"], 'shared_bonus' => ['exp',"shared_bonus + {$amount}"]]);
 
         $content = ['user' => session_helper::memberid(),'steps' => $steps,'amount' => $amount];
         room\factory_client::instance()->notice_room($room_id,proto_type::msg_stype_donate,$content);

+ 18 - 0
test/TestLog.php

@@ -18,6 +18,7 @@ class TestLog extends PHPUnit_Framework_TestCase
         Base::run_util();
     }
 
+
     public function testPairlog()
     {
         $checker = new scope_trace(__METHOD__);
@@ -1144,6 +1145,23 @@ class TestLog extends PHPUnit_Framework_TestCase
             return false;
         }
     }
+
+    public function testPathlog()
+    {
+        $path_file = BASE_DATA_PATH . '/log/' . date('Ymd', time()) . '_path.log';
+        $fd = @fopen($path_file, "r");
+        $stdout = fopen('php://stdout', 'w');
+
+        while (!feof($fd))
+        {
+            $line = fgets($fd,1024);
+            if ($line !== false && !empty($line)) {
+                fwrite($stdout,"{$line}\n\n");
+            }
+        }
+        fclose($fd);
+    }
+
     public function testMonitor()
     {
         $fd = @fopen(BASE_ROOT_PATH . "/data/log/20180831.log", "c+");

+ 2 - 10
test/TestStat.php

@@ -10,7 +10,6 @@
 define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
 require_once(BASE_ROOT_PATH . '/fooder.php');
 require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
-require_once(BASE_ROOT_PATH . '/helper/stat_helper.php');
 
 class TestStat extends PHPUnit_Framework_TestCase
 {
@@ -75,15 +74,8 @@ class TestStat extends PHPUnit_Framework_TestCase
         $y = base64_decode($x);
     }
 
-    public function testPath()
+    public function testBehavior()
     {
-        $val = 'YWN0PW1lbWJlcl9pbmZvJm9wPWdldA%253D%253D';
-        $x = 'eyJ0ayI6ImdDM2VJVzVZaDRCT3NaUWlYcE5raXo2eVhhamE3R2c1ZWJYK2lnZjZudGhPTFphVFN1RHVmRVVrbEl5TUtCL1hQNnRTcjg2VmRSdE5HUVQwR0NBMUZwS1REbEFwWEFRYTNKckx2OFVtNDU1R1NVYlVJU3lMcWdzNVVwWFBERFFuRGZZQ3lKdytGdEhIcHUzQW5sMkZCWjF2YjFuWGMweDhBZ0xHRjY3REJMQT0iLCJ2IjoxfQ==';
-        $y = base64_decode($x);
-        $data = json_decode($y,true);
-        $tk = base64_decode($data['tk']);
-
-        $path = urldecode($val);
-        $path = base64_decode($path);
+        stat_helper::onDaiyBehavior(time());
     }
 }