2025-04-01 18:18:52 +08:00

125 lines
2.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\api\controller\backend;
use app\common\controller\Api;
use app\api\model\Admin as AdminModel;
use think\Db;
/**
* 党风教育控制器
*/
class PartyStyle extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 首页
*
*/
public function getPartyStylData()
{
$page = $this->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);
}
}
}