shish 4 gadi atpakaļ
vecāks
revīzija
71ddfbbdc8

+ 15 - 0
app-hd/controllers/GhsController.php

@@ -7,6 +7,7 @@ use biz\recharge\classes\RechargeHbClass;
 use biz\shop\classes\ShopClass;
 use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\classes\CustomLevelClass;
+use bizHd\stat\classes\StatVisitClass;
 use common\components\util;
 use Yii;
 
@@ -110,4 +111,18 @@ class GhsController extends BaseController
         util::success(['list' => $map]);
     }
 
+    //访问供货商的商城 shish 20211022
+    public function actionVisitMall()
+    {
+        $id = Yii::$app->request->get('id');
+        $info = GhsClass::getById($id, true);
+        GhsClass::valid($info, $this->shopId);
+        $customId = $info->customId ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        StatVisitClass::addGhsCustomVisit($info, $custom);
+    }
+
 }

+ 29 - 14
biz-hd/stat/classes/StatVisitClass.php

@@ -2,24 +2,39 @@
 
 namespace bizHd\stat\classes;
 
+use bizGhs\custom\classes\CustomClass;
 use common\components\util;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
 class StatVisitClass extends BaseClass
 {
-	
-	public static $baseFile = '\bizHd\stat\models\StatVisit';
-	
-	//$time 日期
-	public static function getKeyName($sjId, $class, $time = null)
-	{
-		//全站每天的访问量 //全站每天的访问ip量
-		if (in_array($class, ['whole_site_view', 'whole_site_visit',]) == false) {
-			util::fail('无效键名');
-		}
-		$time = isset($time) == false ? date("Ymd") : $time;
-		return $class . '_' . $sjId . '_' . $time;
-	}
-	
+
+    public static $baseFile = '\bizHd\stat\models\StatVisit';
+
+    //$time 日期
+    public static function getKeyName($sjId, $class, $time = null)
+    {
+        //全站每天的访问量 //全站每天的访问ip量
+        if (in_array($class, ['whole_site_view', 'whole_site_visit',]) == false) {
+            util::fail('无效键名');
+        }
+        $time = isset($time) == false ? date("Ymd") : $time;
+        return $class . '_' . $sjId . '_' . $time;
+    }
+
+    //增加供货商的访客
+    public static function addGhsCustomVisit($ghs, $custom)
+    {
+        $customId = $custom->id ?? 0;
+        $ghsShopId = $ghs->shopId ?? 0;
+        $cacheKey = 'ghs_mall_visit_' . $ghsShopId;
+        $exists = Yii::$app->redis->executeCommand('SISMEMBER', [$cacheKey, $customId]);
+        if (empty($exists)) {
+            Yii::$app->redis->executeCommand('SADD', [$cacheKey, $customId]);
+            $custom->visitTime = date("Y-m-d H:i:s");
+            $custom->save();
+        }
+    }
+
 }

+ 7 - 18
biz-hd/stat/services/StatVisitService.php

@@ -15,14 +15,13 @@ class StatVisitService extends BaseService
 
     public static $baseFile = '\bizHd\stat\classes\StatVisitClass';
 
-    /**
-     * 收集访问次数和访问IP
-     */
+    //收集访问次数和访问IP
     public static function gatherVisit($shopId)
     {
         //收集访问次数
         $wholeSiteView = StatVisitClass::getKeyName($shopId, 'whole_site_view');
         Yii::$app->redis->executeCommand('INCRBY', [$wholeSiteView, 1]);//记录当天访问人数
+
         //收集访问客数
         $ip = Yii::$app->request->userIP;
         $wholeSiteVisit = StatVisitClass::getKeyName($shopId, 'whole_site_visit');
@@ -33,9 +32,7 @@ class StatVisitService extends BaseService
         }
     }
 
-    /**
-     * 将昨天的保存入库
-     */
+    //将昨天的保存入库
     public static function saveYesterdayNum($shopId)
     {
         $yesTime = date("Ymd", strtotime("-1 day"));
@@ -77,9 +74,7 @@ class StatVisitService extends BaseService
         self::clearYesNum($shopId);
     }
 
-    /**
-     * 清空昨天的缓存
-     */
+    //清空昨天的缓存
     public static function clearYesNum($shopId)
     {
         $yesTime = date("Ymd", strtotime("-1 day"));
@@ -108,9 +103,7 @@ class StatVisitService extends BaseService
         return !empty($num) ? $num : 0;
     }
 
-    /**
-     * 获取总访客数
-     */
+    //获取总访客数
     public static function getTotalVisit($shopId)
     {
         $todayNum = self::getTodayVisitNum($shopId);
@@ -120,9 +113,7 @@ class StatVisitService extends BaseService
         return $newTotalVisit;
     }
 
-    /**
-     * 模拟创建昨天的访问IP与数据
-     */
+    //模拟创建昨天的访问IP与数据
     public static function randYesNum($shopId)
     {
         $count = rand(10, 30);
@@ -144,9 +135,7 @@ class StatVisitService extends BaseService
         self::getYesNum($shopId);
     }
 
-    /**
-     * 获取昨天的访问IP和数据
-     */
+    //获取昨天的访问IP和数据
     public static function getYesNum($shopId)
     {
         $yesTime = date("Ymd", strtotime("-1 day"));