Commit 129d59c5 by 杨树贤

分页问题

parent fd9b3a97
......@@ -15,7 +15,7 @@ class CaseController extends Controller
$pageSize = $request->get('page_size');
$list = $service->getCaseList($page, $pageSize);
return $this->Export(0, 'ok', ['data' => $list]);
return $this->Export(0, 'ok', $list);
}
public function show(Request $request, CaseService $service)
......
......@@ -47,7 +47,7 @@ class ArticleModel extends BaseModel
'banner_img',
'publish_time',
];
$data = $this->select($field)
$query = $this->select($field)
->with([
'article_tag' => function ($query) {
$query->select(['id', 'art_id', 'tag', 'url']);
......@@ -59,11 +59,13 @@ class ArticleModel extends BaseModel
$query->select(['type_id', 'type_name']);
},
])
->where($map)->page($page, $pageSize)
->where($map);
$data = $query->page($page, $pageSize)
->orderBy('art_id', 'desc')
->get()->toArray();
$total = $query->count();
return $data;
return compact('data','total');
}
public function getCase($id)
......
......@@ -22,14 +22,16 @@ class CaseService extends BaseService
private function transform($data)
{
foreach ($data as $key => &$item) {
$item['type'] = array_get($item['type'], 'type_name', '');
$item['top_type'] = array_get($item['top_type'], 'type_name', '');
$item['publish_time'] = $item['publish_time'] ? date('Y-m-d H:i:s', $item['publish_time']) : 0;
$item['brand'] = $item['writer'];
unset($item['writer']);
$item['tags'] = array_column($item['article_tag'], 'tag');
unset($item['article_tag']);
if (!empty($data['data'])) {
foreach ($data['data'] as $key => &$item) {
$item['type'] = array_get($item['type'], 'type_name', '');
$item['top_type'] = array_get($item['top_type'], 'type_name', '');
$item['publish_time'] = $item['publish_time'] ? date('Y-m-d H:i:s', $item['publish_time']) : 0;
$item['brand'] = $item['writer'];
unset($item['writer']);
$item['tags'] = array_column($item['article_tag'], 'tag');
unset($item['article_tag']);
}
}
unset($item);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment