lip 3 месяцев назад
Родитель
Сommit
7330cb5a3d

+ 34 - 0
app/admin/controller/Kefu.php

@@ -524,5 +524,39 @@ class Kefu extends BaseController
         }
         return $this->success( ['content' => '']);
     }
+    
+    /**
+     * @api {get} 客服网址访问记录
+     */
+    public function website()
+    {
+
+        try {
+            $params = $this->request->param();
+            $page = $params['page'] ?? 1;
+            $limit = $params['limit'] ?? 15;
+            
+            $query = UserView::alias('user_view')
+                        ->join('website', 'user_view.website_id = website.id', 'left');
+
+            if (!empty($params['start_time'])) {
+                $query = $query->where('user_view.created_at', '>=', $params['start_time'].' 00:00:00');
+            }
+            if (!empty($params['end_time'])) {
+                $query = $query->where('user_view.created_at', '<=', $params['end_time'].' 23:59:59');
+            }
+
+            $count = $query->count();
+            $list = $query->field(['user_view.*,website.url'])
+                        ->order('website.num', 'desc')
+                        ->limit($limit)
+                        ->page($page)
+                        ->select();
+        } catch (Exception $e) {
+            return $this->error($e->getMessage());
+        }
+        return $this->success(['count' => $count, 'list' => $list]);
+    }
+
 
 }

+ 18 - 6
app/admin/model/UserView.php

@@ -3,16 +3,28 @@
 namespace app\admin\model;
 
 use app\BaseModel;
-
+use think\facade\Db;
 
 class UserView extends BaseModel
 {
 
-    public static function addData($user_id)
+    public static function addData($url,$user_id)
     {
-        $data=[
-            'user_id'=>$user_id,
-        ];
-        self::create($data);
+        $website_id = Website::where('url', $url)->value('id');
+        if (!$website_id) {
+            Website::create([
+                'url'=>$url,
+                'num' => 1,
+            ]);
+        } else {
+            Website::where('id', $website_id)->update([
+                'num' => Db::raw('num + 1'),
+            ]);
+        }
+        self::create([
+            'website_id' => $website_id,
+            'user_id' => $user_id
+        ]);
+        return true;
     }
 }

+ 11 - 0
app/admin/model/Website.php

@@ -0,0 +1,11 @@
+<?php
+
+namespace app\admin\model;
+
+use app\BaseModel;
+
+
+class Website extends BaseModel
+{
+
+}

+ 2 - 1
app/common/controller/User.php

@@ -121,7 +121,8 @@ class User
             UserModel::where('user_id',$userInfo['user_id'])->update($update);
             
             //记录用户浏览
-            UserView::addData($userInfo['user_id']);
+            if (!empty($_SERVER['HTTP_REFERER']))
+                UserView::addData($_SERVER['HTTP_REFERER'],$userInfo['user_id']);
         
             Db::commit();
         } catch (\Exception $e) {