Action.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. declare (strict_types = 1);
  3. namespace app\Admin\controller;
  4. use app\BaseController;
  5. use think\facade\Db;
  6. use think\Request;
  7. use think\App;
  8. class Action extends BaseController
  9. {
  10. public function __construct(App $app)
  11. {
  12. parent::__construct($app);
  13. $post =$this->request->post();
  14. $token = isset($post['token']) ? trim($post['token']) : "";
  15. // if($token==""){
  16. // return error_show(101,'token不能为空');
  17. //
  18. // }
  19. // $effetc = VerifyTokens($token);
  20. // if(!empty($effetc) && $effetc['code']!=0){
  21. // return error_show($effetc['code'],$effetc['message']);
  22. //
  23. // }
  24. }
  25. /**
  26. * 显示资源列表
  27. *
  28. * @return \think\Response
  29. */
  30. public function ActionList(){
  31. $post =$this->request->post();
  32. $pageid = isset($post['id']) ? intval($post['id']) : "";
  33. if($pageid==""){
  34. return error_show(1001,'页面id不能为空');
  35. }
  36. $condition = ['menuid'=>$pageid];
  37. $data=Db::name('action')->alias("a")->leftJoin("action_list l","a.action_code=l.action_code")->field
  38. ("a.*,action_name")->where($condition)->select();
  39. return app_show(0,"获取成功",$data);
  40. }
  41. public function ActionSave(){
  42. $post =$this->request->post();
  43. $actid = isset($post['id']) ? intval($post['id']) : "";
  44. if($actid==""){
  45. return error_show(1001,'功能id不能为空');
  46. }
  47. $menuid = isset($post['menuid']) ? intval($post['menuid']) : "";
  48. if($menuid==""){
  49. return error_show(1001,'页面menuid不能为空');
  50. }
  51. $code = isset($post['action_code']) ? trim($post['action_code']) : "";
  52. $status = isset($post['status']) ? intval($post['status']) : 1;
  53. if($code==""){
  54. return error_show(1002,'功能code不能为空');
  55. }
  56. $istrue =Db::name("action")->where(['menuid'=>$menuid,"action_code"=>$code])->find();
  57. if($istrue && $istrue['id']!=$actid){
  58. return error_show(1005,'此功能已存在');
  59. }
  60. try{
  61. $data = ['action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
  62. $result=Db::name("action")->where("id","=",$actid)->save($data);
  63. if($result){
  64. return app_show(0,"更新成功");
  65. }else{
  66. return error_show(1004,"更新失败");
  67. }
  68. }catch (\Exception $e){
  69. return error_show(1003,$e->getMessage());
  70. }
  71. }
  72. public function ActionStatus(){
  73. $post =$this->request->post();
  74. $actid = isset($post['id']) ? intval($post['id']) : "";
  75. if($actid==""){
  76. return error_show(1001,'功能id不能为空');
  77. }
  78. $status = isset($post['status']) ? intval($post['status']) : 1;
  79. try{
  80. $data = ['status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
  81. $result=Db::name("action")->where("id","=",$actid)->save($data);
  82. if($result){
  83. return app_show(0,"更新成功");
  84. }else{
  85. return error_show(1004,"更新失败");
  86. }
  87. }catch (\Exception $e){
  88. return error_show(1003,$e->getMessage());
  89. }
  90. }
  91. /**
  92. * @return \think\response\Json|void
  93. * @throws \think\exception\DbException
  94. */
  95. public function ActionAdd(){
  96. $post =$this->request->post();
  97. $pageid = isset($post['menuid']) ? intval($post['menuid']) : "";
  98. if($pageid==""){
  99. return error_show(1001,'页面id不能为空');
  100. }
  101. $code = isset($post['action_code']) ? trim($post['action_code']) : "";
  102. $status = isset($post['status']) ? intval($post['status']) : 1;
  103. if($code==""){
  104. return error_show(1002,'功能code不能为空');
  105. }
  106. try{
  107. $where = ['menuid'=>$pageid,'action_code'=>$code];
  108. $true =Db::name("action")->where($where)->find();
  109. $data = ['menuid'=>$pageid,'action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s"),"addtime"=>date("Y-m-d H:i:s")];
  110. if($true){
  111. return error_show(1003,'此功能已存在');
  112. }else{
  113. Db::name("action")->insert($data);
  114. return app_show(0,"添加成功");
  115. }
  116. }catch (\Exception $e){
  117. return error_show(1005,$e->getMessage());
  118. }
  119. }
  120. }