diff --git a/app/adminapi/controller/action/ActionTypeController.php b/app/adminapi/controller/action/ActionTypeController.php new file mode 100644 index 00000000..65bc2b7d --- /dev/null +++ b/app/adminapi/controller/action/ActionTypeController.php @@ -0,0 +1,62 @@ +request->post(['name']); + //验证参数 + if(empty($params['name'])){ + return $this->fail('参数错误'); + } + //判断操作类型是否存在 + $hasRes = Db::name('farmer_action_type')->field('id')->where('name',$params['name'])->findOrEmpty(); + if(!empty($hasRes)){ + return $this->fail('数据已存在'); + } + //添加数据 + $addRes = Db::name('farmer_action_type')->insert(['name'=>$params['name']]); + //返回数据 + return $addRes ? $this->success('添加成功') : $this->fail('添加失败'); + } + + //修改操作类型 + public function edit(): Json + { + //获取参数 + $params = $this->request->post(['id','name']); + //验证参数 + if(empty($params['id']) || empty($params['name'])){ + return $this->fail('参数错误'); + } + //判断操作类型是否存在 + $hasRes = Db::name('farmer_action_type')->where('id','<>',$params['id'])->where('name',$params['name'])->field('id')->findOrEmpty(); + if(!empty($hasRes)){ + return $this->fail('数据已存在'); + } + //更新数据 + $ediRes = Db::name('farmer_action_type')->where('id',$params['id'])->update(['name'=>$params['name']]); + //返回数据 + return $ediRes ? $this->success('修改成功') : $this->fail('修改失败'); + } + + //操作记录列表 + public function list(): Json + { + //获取参数 + $params = $this->request->get(['name']); + $where = empty($params['name']) ? [] : [['name','like','%'.$params['name'].'%']]; + //获取数据 + $data = Db::name('farmer_action_type')->where($where)->order('id desc')->select(); + //返回数据 + return $this->success('请求成功',$data->toArray()); + } + } \ No newline at end of file