Browse Source

2023-5-20-1 访问排行榜2

yingzi 1 year ago
parent
commit
cf2905fa9f
1 changed files with 15 additions and 9 deletions
  1. 15 9
      app/api/controller/Pub.php

+ 15 - 9
app/api/controller/Pub.php

@@ -327,17 +327,23 @@ class Pub extends BaseController
 //        }
 //        $list = $list->order('card_look_count', 'desc')->select();
         //统计访问量
-        $au_id = UserModel::where('status',1)->column('uid');
-        $return = [];
-        foreach ($au_id as $au){
-            $au['number'] = AccessIp::where('add_time','>=',$time['time'])
-                                    ->where('add_time','<=',$time['times'])
-                                    ->sum('status');
-            $return[] = $au;
-        }
+//        $au_id = UserModel::where('status',1)->column('uid');
+//        $return = [];
+//        foreach ($au_id as $au){
+//            $au['number'] = AccessIp::where('add_time','>=',$time['time'])
+//                                    ->where('add_time','<=',$time['times'])
+//                                    ->sum('status');
+//            $return[] = $au;
+//        }
+        $users = AccessIp::where('add_time','>=',$time['time'])
+            ->where('add_time','<=',$time['times'])
+            ->field('uid, count(*) as ip_count')
+            ->group('uid')
+            ->order('ip_count', 'desc')
+            ->select();
 
         $rankList = [];
-        foreach ($return as $key => $value) {
+        foreach ($users as $key => $value) {
             $userInfo = (new UserModel)->where('uid', $value['uid'])->find();
             $auth = (new InfoAudit)->where('uid',$value['uid'])->find();
             $template = $this->getShowTemplateItem($value['uid']);