NoteStar 5 лет назад
Родитель
Сommit
1d7e92bf3d

+ 1 - 0
addons/fecmall/furnilife_theme/app/appfront/theme/furnilife/widgets/head.php

@@ -22,3 +22,4 @@
 
     gtag('config', 'UA-159325062-2');
 </script><?php $parentThis->head() ?>
+<?=  Yii::$service->userfrom->savePageData(); ?>

+ 1 - 1
addons/fecmall/furnilife_theme/app/apphtml5/theme/furnilife/widgets/head.php

@@ -26,4 +26,4 @@
     gtag('config', 'UA-159325062-2');
 </script>
 <?php $parentThis->head() ?>
-
+<?=  Yii::$service->userfrom->savePageData(); ?>

+ 3 - 0
vendor/fancyecommerce/fecshop/app/appadmin/config/modules/Fecadmin.php

@@ -28,6 +28,9 @@ return [
             'logtj' => [
 				'class' => 'fecshop\app\appadmin\modules\Fecadmin\controllers\LogtjController',
 			],
+            'visitortj' => [
+                'class' => 'fecshop\app\appadmin\modules\Fecadmin\controllers\VisitortjController',
+            ],
             'log' => [
 				'class' => 'fecshop\app\appadmin\modules\Fecadmin\controllers\LogController',
 			],

+ 248 - 0
vendor/fancyecommerce/fecshop/app/appadmin/modules/Fecadmin/block/visitortj/Index.php

@@ -0,0 +1,248 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+namespace fecshop\app\appadmin\modules\Fecadmin\block\visitortj;
+
+use fec\helpers\CUrl;
+use fec\helpers\CDate;
+use fec\helpers\CRequest;
+use fecshop\app\appadmin\interfaces\base\AppadminbaseBlockInterface;
+use fecshop\app\appadmin\modules\AppadminbaseBlock;
+use Yii;
+/**
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class Index extends AppadminbaseBlock implements AppadminbaseBlockInterface
+{
+	public function init()
+    {
+        /*
+         * service component, data provider
+         */
+        $this->_service = Yii::$service->userfrom;
+        parent::init();
+        $this->_param['user_from_time_lt'] || $this->_param['user_from_time_lt'] = date('Y-m-d',strtotime(CDate::getCurrentDate().' +1 day '));
+		$this->_param['user_from_time_gte'] || $this->_param['user_from_time_gte'] = date('Y-m-d',strtotime($this->_param['user_from_time_gte'].' -1 month '));
+    }
+	
+	public function getLastData(){
+		# 返回数据的函数
+		# 隐藏部分
+		$pagerForm = $this->getPagerForm();
+
+		# 搜索部分
+		$searchBar = $this->getSearchBar();
+		# 编辑 删除  按钮部分
+		$editBar = $this->getEditBar();
+		# 表头部分
+		$thead = $this->getTableThead();
+		# 表内容部分
+		$tbody = $this->getTableTbody();
+		# 分页部分
+		$toolBar = $this->getToolBar($this->_param['numCount'],$this->_param['pageNum'],$this->_param['numPerPage']); 
+		
+		return [
+			'pagerForm'	 	=> $pagerForm,
+			'searchBar'		=> $searchBar,
+			'editBar'		=> $editBar,
+			'thead'		=> $thead,
+			'tbody'		=> $tbody,
+			'toolBar'	=> $toolBar,
+		];
+	}
+	
+	# 定义搜索部分字段格式
+	public function getSearchArr(){
+		$data = [
+			[	# 字符串类型
+				'type' => 'inputtext',
+				'title' => Yii::$service->page->translate->__('IP'),
+				'name' => 'user_ip' ,
+				'columns_type' => 'string'
+			],
+			[	# 字符串类型
+				'type' => 'inputtext',
+				'title' => Yii::$service->page->translate->__('From_Url'),
+				'name' => 'user_from_url' ,
+				'columns_type' => 'string'
+			],
+			[	# 时间区间类型搜索
+				'type' => 'inputdatefilter',
+				'name' => 'user_from_time',
+				'columns_type' => 'datetime',
+				'value' => [
+					'gte' => Yii::$service->page->translate->__('Created Begin'),
+					'lt' => Yii::$service->page->translate->__('Created End'),
+				]
+			],
+		];
+		return $data;
+	}
+	
+	# 定义表格显示部分的配置
+	public function getTableFieldArr(){
+		$table_th_bar = [
+			[	
+				'orderField'	=> 'user_ip',
+				'label'			=> Yii::$service->page->translate->__('Ip'),
+				'width'			=> '50',
+				'align' 		=> 'center',
+			],
+			[	
+				'orderField'	=> 'user_url',
+				'label'			=> Yii::$service->page->translate->__('Url'),
+				'width'			=> '50',
+				'align' 		=> 'left',
+			],
+            [
+                'orderField'	=> 'user_from_url',
+                'label'			=> Yii::$service->page->translate->__('From_Url'),
+                'width'			=> '100',
+                'align' 		=> 'left',
+            ],
+            [
+                'orderField'	=> 'user_browser',
+                'label'			=> Yii::$service->page->translate->__('Browser'),
+                'width'			=> '30',
+                'align' 		=> 'left',
+            ],
+			//[	
+			//	'orderField'	=> 'menu',
+			//	'label'			=> '操作菜单',
+			//	'width'			=> '70',
+			//	'align' 		=> 'left',
+			//],
+			[	
+				'orderField'	=> 'user_from_time',
+				'label'			=> Yii::$service->page->translate->__('From_Time'),
+				'width'			=> '50',
+				'align' 		=> 'left',
+			],
+		];
+        
+		return $table_th_bar ;
+	}
+	# 得到表格的内容部分 
+	public function getTableTbody(){
+        
+		$obj = Yii::$service->userfrom->getSystemLogModel();
+		$offset = ($this->_param['pageNum'] -1)*$this->_param['numPerPage'] ;
+		$limit 	= $this->_param['numPerPage'];
+		$limit =  " limit  $offset , $limit ";
+		$user_ip 		= CRequest::param('user_ip');
+		$user_from_url 	= CRequest::param('user_from_url');
+		$created_at_lt 	= $this->_param['user_from_time_lt'];
+		$created_at_gte = $this->_param['user_from_time_gte'];
+		$where = [];
+		if($user_ip)
+			$where []= " user_ip = '$user_ip' ";
+		if($user_from_url)
+			$where []= " user_from_url like '%$user_from_url%' ";
+			
+		if($created_at_lt)
+			$where []= " user_from_time < '$created_at_lt' ";
+		if($created_at_gte)
+			$where []= " user_from_time >= '$created_at_gte' ";
+		if(!empty($where)){
+			$where = ' where '.implode(' and ',$where);
+		}else{
+			$where = '';
+		}
+			
+		$table = $obj::tableName();
+		
+		$db = \Yii::$app->db;
+		
+		# 得到 总数。		
+		$sql = "select count(*) as count from (select id  from $table  $where  ) as t ";
+		$data_count = $db->createCommand($sql,[])->queryOne();
+		$this->_param['numCount'] = $data_count['count'];
+		# 得到数据
+		$sql = "select *  from $table  $where  order by id DESC $limit ";
+		$data = $db->createCommand($sql,[])->queryAll();
+
+		return $this->getTableTbodyHtml($data);
+	}
+	
+	# table 内容部分
+	public function getTableTbodyHtml($data){
+		$fileds = $this->getTableFieldArr();
+		$str .= '';
+        $primaryKey = $this->_service->getPrimaryKey();
+		$csrfString = \fec\helpers\CRequest::getCsrfString();
+		foreach ($data as $one) {
+			$str .= '<tr target="sid_user" rel="'.$one[$primaryKey].'">';
+			//$str .= '<td><input name="'.$primaryKey.'s" value="'.$one[$primaryKey].'" type="checkbox"></td>';
+			foreach ($fileds as $field) {
+				$orderField = $field['orderField'];
+				$display	= $field['display'];
+				$val = $one[$orderField];
+				$originVal = $one[$orderField];
+				if ($val) {
+					if (isset($field['display']) && !empty($field['display'])) {
+						$display = $field['display'];
+						$val = $display[$val] ? $display[$val] : $val;
+					}
+					if (isset($field['convert']) && !empty($field['convert'])) {
+						$convert = $field['convert'];
+						foreach ($convert as $origin =>$to) {
+							if (strstr($origin,'date')) {
+								if($to == 'date'){
+									$val = date('Y-m-d',strtotime($val));
+								} else if ($to == 'datetime') {
+									$val = date('Y-m-d H:i:s',strtotime($val));
+								} else if($to == 'int') {
+									$val = strtotime($val);
+								}
+							} else if($origin == 'int') {
+								if ($to == 'date') {
+									$val = date('Y-m-d',$val);
+								} else if ($to == 'datetime') {
+									$val = date('Y-m-d H:i:s',$val);
+								} else if ($to == 'int') {
+									$val = $val;
+								}
+							}
+						}
+					}
+				}
+				$str .= '<td><span title='.$originVal.'>'.$val.'</span></td>';
+			}
+			$str .= '</tr>';
+		}
+        
+		return $str ;
+	}
+	# table 表  标题  1
+	public function getTableTheadHtml($table_th_bar){
+        $primaryKey = $this->_service->getPrimaryKey();
+		$table_th_bar = $this->getTableTheadArrInit($table_th_bar);
+		$this->_param['orderField'] 	= $this->_param['orderField'] 		? $this->_param['orderField'] : $primaryKey;
+		$this->_param['orderDirection'] = $this->_param['orderDirection'] 	? $this->_param['orderDirection'] :  $this->_defaultDirection;
+		foreach ($table_th_bar as $k => $field) {
+			if ($field['orderField'] == $this->_param['orderField']) {
+				$table_th_bar[$k]['class'] = $this->_param['orderDirection'];
+			}	
+		}
+		$str = '<thead><tr>';
+		//$str .= '<th width="22"><input type="checkbox" group="'.$primaryKey.'s" class="checkboxCtrl"></th>';
+		foreach ($table_th_bar as $b) {
+			$width = $b['width'];
+			$label = $b['label'];
+			$orderField = $b['orderField'];
+			$class = isset($b['class']) ? $b['class'] : '';
+			$align = isset($b['align']) ? 'align="'.$b['align'].'"' : '';
+			$str .= '<th width="'.$width.'" '.$align.' orderField="'.$orderField.'" class="'.$class.'">'.$label.'</th>';
+		}
+		$str .= '</tr></thead>';
+        
+		return $str;
+	}
+	
+}

+ 38 - 0
vendor/fancyecommerce/fecshop/app/appadmin/modules/Fecadmin/controllers/VisitortjController.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+namespace fecshop\app\appadmin\modules\Fecadmin\controllers;
+use Yii;
+use fec\helpers\CRequest;
+use fecadmin\FecadminbaseController;
+use fecshop\app\appadmin\modules\AppadminController;
+/**
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class VisitortjController extends AppadminController
+{
+	public $enableCsrfValidation = true;
+    public $blockNamespace = 'fecshop\\app\\appadmin\\modules\\Fecadmin\\block';
+    
+    public function actionIndex()
+    {
+		$data = $this->getBlock()->getLastData();
+		return $this->render($this->action->id,$data);
+	}
+
+	
+}
+
+
+
+
+
+
+
+

+ 37 - 0
vendor/fancyecommerce/fecshop/app/appadmin/theme/base/default/fecadmin/visitortj/index.php

@@ -0,0 +1,37 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+use fec\helpers\CRequest;
+?>
+<form id="pagerForm" method="post" action="<?= \fec\helpers\CUrl::getCurrentUrl();  ?>">
+	<?=  CRequest::getCsrfInputHtml();  ?>
+	<?=  $pagerForm;  ?>
+	
+</form>
+<div class="pageHeader">
+	<form rel="pagerForm" onsubmit="return navTabSearch(this);" action="<?= \fec\helpers\CUrl::getCurrentUrl();  ?>" method="post">
+		<?php echo CRequest::getCsrfInputHtml();  ?>
+		<div class="searchBar">
+			<?php  echo $searchBar; ?>
+		</div>
+	</form>
+</div>
+<div class="pageContent">
+	<div class="panelBar">
+		<?php //echo $editBar;  ?>
+	</div>
+	<div class="panelBar">
+		<?= $toolBar; ?>
+	</div>
+	<table class="table" width="100%" layoutH="138">
+		<?= $thead; ?>
+		<tbody>
+			<?= $tbody; ?>
+		</tbody>
+	</table>
+</div>

+ 5 - 0
vendor/fancyecommerce/fecshop/config/services/Admin.php

@@ -48,6 +48,7 @@ return [
                     'config_apphtml5_manager' 					=> 'Config-Apphtml5',
                     'config_appserver_manager' 				=> 'Config-Appserver',
                     'config_appadmin_manager' 				=> 'Config-Appadmin',
+                    'visitortj' 				=> 'Visitor-Statistics',
 				],
             ],
             'roleUrlKey' => [
@@ -414,6 +415,10 @@ return [
                                 'label' => 'Log Statistics',
                                 'url_key' => '/fecadmin/logtj/index',
                             ],
+                            'visitortj' => [
+                                'label' => 'Visitor Statistics',
+                                'url_key' => '/fecadmin/visitortj/index',
+                            ],
                             'cache' => [
                                 'label' => 'Manager Cache',
                                 'url_key' => '/fecadmin/cache/index',

+ 42 - 0
vendor/fancyecommerce/fecshop/config/services/UserFrom.php

@@ -0,0 +1,42 @@
+<?php
+/**
+ * FecShop file.
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+return [
+    'userfrom' => [
+        'class' => 'fecshop\services\UserFrom',
+        // 子服务
+        //'childService' => [
+        //    'item' => [
+        //        'class' => 'fecshop\services\order\Item',
+        //    ],
+        //],
+        /*
+        //'increment_id' => '',
+        'requiredAddressAttr' => [ # 必填的订单字段。
+            'first_name',
+            'last_name',
+            'email',
+            'telephone',
+            'street1',
+            'country',
+            'city',
+            'state',
+            'zip'
+        ],
+        #处理多少分钟后,支付状态为pending的订单,归还库存。
+        'minuteBeforeThatReturnPendingStock' 	=>  60,
+        # 脚本一次性处理多少个pending订单。
+        'orderCountThatReturnPendingStock' 		=>  30,
+        # 子服务
+        'childService' => [
+            'item' => [
+                'class' => 'fecshop\services\order\Item',
+            ],
+        ],
+        */
+    ],
+];

+ 24 - 0
vendor/fancyecommerce/fecshop/models/mysqldb/UserFrom.php

@@ -0,0 +1,24 @@
+<?php
+/**
+ * FecShop file.
+ *
+ * @link http://www.fecshop.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecshop.com/license/
+ */
+
+namespace fecshop\models\mysqldb;
+
+use yii\db\ActiveRecord;
+
+/**
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class UserFrom extends ActiveRecord
+{
+    public static function tableName()
+    {
+        return '{{%user_from}}';
+    }
+}

+ 162 - 0
vendor/fancyecommerce/fecshop/services/UserFrom.php

@@ -0,0 +1,162 @@
+<?php
+
+/*
+ * FecShop file.
+ *
+ * @link http://www.fecmall.com/
+ * @copyright Copyright (c) 2016 FecShop Software LLC
+ * @license http://www.fecmall.com/license/
+ */
+
+namespace fecshop\services;
+
+use Yii;
+
+/**
+ * Order services.
+ *
+ * @property \fecshop\services\order\Item $item
+ *
+ * @author Terry Zhao <2358269014@qq.com>
+ * @since 1.0
+ */
+class UserFrom extends Service
+{
+    protected $_userFromModelName = '\fecshop\models\mysqldb\UserFrom';
+
+    protected $_userFromModel;
+
+    public function init()
+    {
+        parent::init();
+        list($this->_userFromModelName, $this->_userFromModel) = \Yii::mapGet($this->_userFromModelName);
+
+    }
+
+    public function getSystemLogModel(){
+        return $this->_userFromModel;
+    }
+
+    public function getPrimaryKey()
+    {
+        return 'id';
+    }
+
+    /**
+     * @param $data
+     * @return bool
+     * Save user_from_data
+     */
+    public function saveUserData($data){
+        if(!is_array($data)){
+            Yii::$service->helper->errors->add('UserFromData is not exist', '1');
+            return false;
+        }
+        $user_ip = $data['user_ip'];
+        $user_url = $data['user_url'];
+        $user_from_url = $data['user_from_url'];
+        $user_browser = $data['user_browser'];
+        $user_from_time = date("Y-m-d H:i:s",time());
+
+        $model = new $this->_userFromModelName();
+        $model->user_ip = $user_ip;
+        $model->user_url = $user_url;
+        $model->user_from_url = $user_from_url;
+        $model->user_from_time = $user_from_time;
+        $model->user_browser = $user_browser;
+        $model->save();
+        return true;
+    }
+
+    /**
+     * @param $where
+     * @return bool
+     * get user from data
+     */
+    public function getUserData($where){
+        if(!is_array($where)){
+            Yii::$service->helper->errors->add('UserFromDataWhere is not exist', '1');
+            return false;
+        }
+        $query = $this->_userFromModel->find()->asArray();
+        $query->where($where);
+        $data = $query->all();
+        return $data;
+    }
+
+    public function savePageData(){
+        $data = array();
+        $data['user_ip'] = $this->getIp();
+        $data['user_url'] = $this->getUrl();
+        $data['user_from_url'] = $this->getFromUrl();
+        $data['user_browser'] = $this->getBrowser();
+        $this->saveUserData($data);
+
+    }
+
+    public function getIp(){
+        $ip=false;
+        if(!empty($_SERVER["HTTP_CLIENT_IP"])){
+            $ip = $_SERVER["HTTP_CLIENT_IP"];
+        }
+        if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
+            $ips = explode (", ", $_SERVER['HTTP_X_FORWARDED_FOR']);
+            if ($ip) { array_unshift($ips, $ip); $ip = FALSE; }
+            for ($i = 0; $i < count($ips); $i++) {
+                if (!eregi ("^(10│172.16│192.168).", $ips[$i])) {
+                    $ip = $ips[$i];
+                    break;
+                }
+            }
+        }
+        return ($ip ? $ip : $_SERVER['REMOTE_ADDR']);
+
+    }
+
+     public function getIpContent($url){
+        $headerArray =array("Content-type:application/json;","Accept:application/json");
+        $ch = curl_init();
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch,CURLOPT_HTTPHEADER,$headerArray);
+        $output = curl_exec($ch);
+        curl_close($ch);
+        $output = json_decode($output,true);
+        return $output;
+    }
+
+
+
+    public function getBrowser(){
+
+        $agent=$_SERVER["HTTP_USER_AGENT"];
+        if(strpos($agent,'MSIE')!==false || strpos($agent,'rv:11.0'))
+            return "ie";
+        else if(strpos($agent,'Firefox')!==false)
+            return "firefox";
+        else if(strpos($agent,'Chrome')!==false)
+            return "chrome";
+        else if(strpos($agent,'Opera')!==false)
+            return 'opera';
+        else if((strpos($agent,'Chrome')==false)&&strpos($agent,'Safari')!==false)
+            return 'safari';
+        else
+            return 'unknown';
+    }
+
+    public function getFromUrl(){
+        if(isset($_SERVER['HTTP_REFERER']))
+            return $_SERVER['HTTP_REFERER'];
+        else if(strpos($_SERVER['QUERY_STRING'], '?'))
+            return $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
+        else
+            return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
+    }
+
+    public function getUrl(){
+        return $_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
+    }
+
+}