要实现的效果如图
增加对应的控制器 index 方法
/**
* 查看
*
* @return string|Json
* @throws \think\Exception
* @throws DbException
*/
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if (false === $this->request->isAjax()) {
$tid = (int)input('tid');
$this->view->assign('tid',$tid);
return $this->view->fetch();
}
//如果发送的来源是 Selectpage,则转发到 Selectpage
if ($this->request->request('keyField')) {
return $this->selectpage();
}
$wheres = [];
if(!empty(input('tid'))){
$wheres['tid'] = input('tid');
}
[$where, $sort, $order, $offset, $limit] = $this->buildparams();
$list = $this->model
->where($where)
->where($wheres)
->order($sort, $order)
->paginate($limit);
//************* 关键代码开始 *************
$rows = $list->items();
if(!empty($rows)){
$firstarr[]=[
'date' => '累计金额',
'amount' => 0
];
$rows = array_merge($rows, $firstarr);
}
$result = ['total' => $list->total(), 'rows' => $rows];
//************* 关键代码结束 *************
return json($result);
}