Action.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\bug\controller;
  4. use app\bug\model\ActionList;
  5. use think\App;
  6. use think\facade\Validate;
  7. class Action extends Base
  8. {
  9. protected $noLogin=[];
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. $this->model = new \app\bug\model\Action();
  14. }
  15. /** 获取页面id下功能按钮
  16. */
  17. public function ActionList(){
  18. $pageid =$this->request->post("id/d");
  19. if($pageid=="")return error('页面id不能为空');
  20. $condition = ['menuid'=>$pageid];
  21. $data=$this->model->with(["actionInfo"])->where($condition)->select();
  22. return success("获取成功",$data);
  23. }
  24. /** 新建功能按钮
  25. * @return \think\Response|\think\response\Json|void
  26. */
  27. public function ActionSave(){
  28. $post =$this->request->param(["id"=>0,"action_name"=>"","action_desc"=>"","status"=>1,"action_code"=>""],
  29. "post","trim");
  30. $valid = Validate::rule([
  31. "id|主键Id"=>"number|egt:0",
  32. "action_name|功能名称"=>"require|max:255|unique:app\bug\model\ActionList,action_name",
  33. "status|功能状态"=>"number|in:0,1",
  34. "action_code|功能编号"=>"require|max:255",
  35. "action_desc|功能描述"=>"max:255",
  36. ]);
  37. if($valid->check($post)==false)return error($valid->getError());
  38. $isf= ActionList::where('id','=',$post['id'])->findOrEmpty();
  39. if($post['id']>0 && $isf->isEmpty())return error('未找到数据');
  40. $message = $post['id']>0?"修改":"添加";
  41. try{
  42. $isf->save($post);
  43. return success("功能{$message}成功");
  44. }catch (\Exception $e){
  45. return error($e->getMessage());
  46. }
  47. }
  48. /**
  49. * 页面功能启禁用
  50. * @return \think\Response|\think\response\Json|void
  51. */
  52. public function ActionStatus(){
  53. $post =$this->request->param(['id'=>0,'status'=>0],'post','trim');
  54. $valid = Validate::rule([
  55. 'id|主键Id'=>'require|number|gt:0',
  56. 'status|功能状态'=>'number|in:0,1'
  57. ]);
  58. if($valid->check($post)==false)return error($valid->getError());
  59. $isf= $this->model->where('id','=',$post['id'])->findOrEmpty();
  60. if($isf->isEmpty())return error('未找到数据');
  61. try{
  62. $isf->status=$post['status'];
  63. $result=$isf->save();
  64. if($result==false) return error("{$this->model->status_cn[$isf->status]}失败");
  65. return success("{$this->model->status_cn[$isf->status]}成功");
  66. }catch (\Exception $e){
  67. return error($e->getMessage());
  68. }
  69. }
  70. /**页面功能添加
  71. * @return \think\response\Json|void
  72. * @throws \think\exception\DbException
  73. */
  74. public function ActionAdd(){
  75. $post =$this->request->param(['menuid'=>0,'status'=>1,"action_code"=>""],'post','trim');
  76. $valid = Validate::rule([
  77. 'menuid|菜单Id'=>'require|number|gt:0',
  78. 'action_code|功能编号'=>'require|number|gt:0',
  79. 'status|功能状态'=>'number|in:0,1'
  80. ]);
  81. if($valid->check($post)==false)return error($valid->getError());
  82. $isf = $this->model->where( ['menuid'=>$post['menuid'],'action_code'=>$post['action_code']])->findOrEmpty();
  83. if($isf->isEmpty()==false) return error('此功能已存在');
  84. try{
  85. $result=$isf->save($post);
  86. if($result==false)return error("创建失败");
  87. return success("创建成功");
  88. }catch (\Exception $e){
  89. return error($e->getMessage());
  90. }
  91. }
  92. }