-
Notifications
You must be signed in to change notification settings - Fork 1.6k
列表数据接口格式
liaofei edited this page Jan 20, 2021
·
1 revision
status : 接口请求状态 msg : 接口信息 data: 接口数据 data['list'] : 列表数据(默认取15条) data['count'] : 列表数据条数(非list总条数)
{
status: 200,
msg: "ok",
data: {
list:[
0 => {},
1 => {},
1 => {},
1 => {},
...
15 => {},
]
count: 1024
}
}
第一,控制器方法 demo_list
调用services层时,如果调用的是当前控制器对应的services层方法,在调用方式直接$this->services->方法,控制器对应的services对象已经在__construct()中注入进来,赋给属性services了。所以在此控制器中能直接调用。
public function __construct(App $app, DemoServices $service)
{
parent::__construct($app);
$this->services = $service;
}
调用services层时,如果数据是在其他service层,那么就需要在具体的方法内声明调用:
/** @var DemoServices $services */
$services = app()->make(DemoServices::class);
$data = $services->getDemoList($where)
/**
* 获取列表
* @return mixed
*/
public function demo_list()
{
$where = $this->request->getMore([
['status', ''],
['real_name', ''],
['is_del', ''],
['data', '', '', 'time'],
]);
$data = $this->services->getDemoList($where)
return $this->success($data);
}
第二,service层具体数据处理方法 getDemoList
public function getOrderList(array $where)
{
//获取分页数据
[$page, $limit] = $this->getPageValue();
//获取数据
$data = $this->dao->getDemoList($where);
//获取符合条件数据总条数
$count = $this->dao->count($where);
//返回数据
return compact('data', 'count');
}