作者 开飞机的舒克

接口优化

... ... @@ -16,6 +16,8 @@ class Activity extends Api
/**
* @ApiTitle (活动首页)
* @ApiMethod (POST)
* @ApiParams (name="row", type="string", required=false, description="每页显示行数[非必填]")
* @ApiParams (name="page", type="string", required=false, description="当前页[非必填]")
* @ApiReturn ({"code":状态码,
"msg":"提示信息"
"time": "时间戳",
... ... @@ -29,16 +31,21 @@ class Activity extends Api
*/
public function index()
{
$row = $this->request->param('row');
$page = $this->request->param('page');
$row = $row ? $row : 10;
$page = $page ? $page : 1;
$data = db('activity')
->order('createtime DESC')
->select();
->paginate($row,false,['page'=>$page])
->each(function ($item,$key){
$item['images'] = cdnurl($item['images'], true);
$item['createtime'] = date('Y-m-d', $item['createtime']);
return $item;
});
if (!$data) {
$this->error('当前还没有活动', ['status' => 2]);
}
foreach ($data as $k => $v) {
$data[$k]['images'] = cdnurl($v['images'], true);
$data[$k]['createtime'] = date('Y-m-d', $v['createtime']);
}
$this->success('全部项目', $data);
}
... ... @@ -58,18 +65,13 @@ class Activity extends Api
*/
public function getSchoolItem()
{
$id = $this->request->param('id');
if (empty($id)) {
$this->error('参数错误', ['status' => 3]);
}
$data = db('campus c')
->join('activity a','a.id = c.activity_id')
->join('school s','s.id = c.school_id')
->where('c.activity_id', $id)
->field('c.*,a.title as activity_name,s.title as school_name')
->paginate(10,false);
if (empty($data)) {
$this->error('空空', ['status' => 3]);
$this->error('当前还没有校区', ['status' => 2]);
}
$this->success('项目校区', $data);
}
... ...
... ... @@ -1816,7 +1816,30 @@
<div class="panel panel-default">
<div class="panel-heading"><strong>参数</strong></div>
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必选</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>row</td>
<td>string</td>
<td></td>
<td>每页显示行数[非必填]</td>
</tr>
<tr>
<td>page</td>
<td>string</td>
<td></td>
<td>当前页[非必填]</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="panel panel-default">
... ... @@ -1838,7 +1861,12 @@
<div class="panel-body">
<form enctype="application/x-www-form-urlencoded" role="form" action="/api/activity/index" method="POST" name="form0" id="form0">
<div class="form-group">
<label class="control-label" for="row">row</label>
<input type="string" class="form-control input-sm" id="row" placeholder="每页显示行数[非必填]" name="row">
</div>
<div class="form-group">
<label class="control-label" for="page">page</label>
<input type="string" class="form-control input-sm" id="page" placeholder="当前页[非必填]" name="page">
</div>
<div class="form-group form-group-submit">
<button type="submit" class="btn btn-success send" rel="0">提交</button>
... ... @@ -4848,7 +4876,7 @@
</div>
<div class="col-md-6" align="right">
Generated on 2023-03-17 09:48:50 <a href="./" target="_blank">校园活动</a>
Generated on 2023-03-17 10:06:23 <a href="./" target="_blank">校园活动</a>
</div>
</div>
... ...