request->post('page',1); $size = $this->request->post('size',10); // 从数据库中获取所有数据 $data = Db::name('party_style')->select(); $count = Db::name('party_style')->count(); $res = [ 'data' => $data, 'count' => $count ]; return $this->success('请求成功',$res); } /** *单个科室查询 */ public function getPartyStylFind() { $id = $this->request->post('id'); if(!$id){ return $this->error('缺少参数'); } // 从数据库中获取所有数据 $data = Db::name('party_style')->where('id', $id)->find(); return $this->success('请求成功',$data); } /** *添加数据 */ public function create() { $data = $this->request->post(); $data['createtime'] = date('Y-m-d H:i:s'); $result = Db::name('party_style')->strict(false)->insert($data); if ($result) { return $this->success('添加成功',$result); } else { return $this->error('添加失败',$result); } } /** * 更新记录 * * @param Request $request * @param int $id * @return \think\Response */ public function update() { $id = $this->request->post('id'); if (!$id) { return $this->error('参数错误'); } // 获取原始POST数据(包含所有字段) $data = $_POST; // 移除ID字段(避免更新ID) // unset($data['id']); // return $this->success('更新成功', $data); // 关闭字段严格校验 $result = Db::name('party_style') ->where('id', $id) ->strict(false) // 关闭字段白名单校验 ->update($data); if ($result !== false) { return $this->success('更新成功', $result); } else { return $this->error('更新失败'); } } /** * 删除记录 * * @param int $id * @return \think\Response */ public function delete() { $id = $this->request->post('id'); if(!$id){ return $this->error('缺少参数'); } $result = Db::name('party_style')->delete($id); if ($result) { return $this->success('删除成功',$result); } else { return $this->error('删除失败',$result); } } }