mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-21 17:44:27 +08:00
丰富基础代码
This commit is contained in:
@@ -41,6 +41,30 @@ class BaseController
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一分页返回结构
|
||||
*
|
||||
* @param mixed $paginator Laravel/Eloquent paginator
|
||||
*/
|
||||
protected function page(mixed $paginator): Response
|
||||
{
|
||||
if (!is_object($paginator) || !method_exists($paginator, 'items')) {
|
||||
return $this->success([
|
||||
'list' => [],
|
||||
'total' => 0,
|
||||
'page' => 1,
|
||||
'size' => 10,
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->success([
|
||||
'list' => $paginator->items(),
|
||||
'total' => $paginator->total(),
|
||||
'page' => $paginator->currentPage(),
|
||||
'size' => $paginator->perPage(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的 token 载荷
|
||||
*
|
||||
|
||||
@@ -62,11 +62,8 @@ abstract class BaseRepository
|
||||
{
|
||||
$query = $this->model->newQuery();
|
||||
|
||||
foreach ($where as $field => $value) {
|
||||
if ($value === null || $value === '') {
|
||||
continue;
|
||||
}
|
||||
$query->where($field, $value);
|
||||
if (!empty($where)) {
|
||||
$query->where($where);
|
||||
}
|
||||
|
||||
return $query->paginate($pageSize, $columns, 'page', $page);
|
||||
|
||||
Reference in New Issue
Block a user