Browse Source

数据处理

黄宗昌 2 năm trước cách đây
mục cha
commit
b0d418bff3

+ 12 - 0
app/Http/Controllers/V1/Controller.php

xqd
@@ -91,4 +91,16 @@ class Controller extends BaseController
             'page'=>$list->currentPage(),//当前页
         ];
     }
+
+    // 特殊处理
+    public function pages($list){
+        return [
+            'items' => $list->items()['data'],
+            'total' => $list->total(),   // 总数
+            'pageSize' => $list->perPage(), // 每页数据
+            'totalPage' => $list->lastPage(),// 总页数
+            'page' => $list->currentPage(),//当前页
+        ];
+    }
+
 }

+ 14 - 1
app/Http/Controllers/V1/ProductController.php

xqd
@@ -183,7 +183,20 @@ class ProductController extends Controller
         }
         $list = $query->where('status',1)
             ->paginate($limit);
-        return $this->success($this->page($list));
+        $data = [];
+        foreach ($list as $v){
+            $data[] = [$v->toArray()];
+        }
+
+        $data = [
+            'items' => $data,
+            'total' => $list->total(),   // 总数
+            'pageSize' => $list->perPage(), // 每页数据
+            'totalPage' => $list->lastPage(),// 总页数
+            'page' => $list->currentPage(),//当前页
+        ];
+
+        return $this->success($data);
     }
 
     /**