DESKTOP-2STQMTS\Administrator 3 rokov pred
rodič
commit
3ef0cd3227

+ 28 - 10
app/Http/Controllers/AdminApi/ApplyController.php

@@ -43,23 +43,41 @@ class ApplyController extends AdminController
     function getApplyList(){
 
         $search = request()->input('search','');//搜索内容
+        $order_by = request()->input('order_by', '');//排序
 
-        $where = [['status',1]];
-
-        $list = WxUser::where($where)
+        $where = [['u.status',1]];
+        $sql = "x_u.id,x_u.name,x_u.phone,x_u.pv,x_u.uv,x_u.created_at,
+                count(x_s.id) as count";
+        $model = WxUser::from('wx_users as u')
+            ->leftJoin('wx_signups as s', 's.m_id', '=', 'u.id')
+            ->where($where)
             ->where(function ($q) use ($search){
                 if($search){
-                    $q->where('name','like',"%$search%");
-                    $q->orWhere('phone','like',"%$search%");
+                    $q->where('u.name','like',"%$search%");
+                    $q->orWhere('u.phone','like',"%$search%");
                 }
             })
-            ->select(['id','name','phone','pv','uv','created_at'])
-            ->paginate(10);
-
-        foreach ($list as $value){
-            $value['count'] = WxSignup::where('m_id',$value['id'])->count();
+            ->groupBy('u.id')
+            ->selectRaw($sql);
+
+        if ($order_by == 1) {
+            $model->orderBy('pv', 'asc');
+        } elseif ($order_by == 2) {
+            $model->orderBy('pv', 'desc');
+        } elseif ($order_by == 3) {
+            $model->orderBy('uv', 'asc');
+        } elseif ($order_by == 4) {
+            $model->orderBy('uv', 'desc');
+        } elseif ($order_by == 5) {
+            $model->orderBy('count', 'asc');
+        } elseif ($order_by == 6) {
+            $model->orderBy('count', 'desc');
+        } else {
+            $model->orderBy('u.id', 'asc');
         }
 
+        $list = $model->paginate(10);
+
         return $this->apiResponseSuccess('获取信息成功', [
             'list' => $list->items(),
             'total' => $list->total(),