Action.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. namespace app\Admin\controller;
  3. use app\BaseController;
  4. use think\facade\Db;
  5. class Action extends BaseController
  6. {
  7. /**
  8. * @return \think\response\Json
  9. * @throws \think\db\exception\DataNotFoundException
  10. * @throws \think\db\exception\DbException
  11. * @throws \think\db\exception\ModelNotFoundException
  12. * @throws \think\exception\DbException
  13. */
  14. public function index(){
  15. $post =$this->request->post();
  16. $token = isset($post['token']) ? trim($post['token']) : "";
  17. if($token==""){
  18. return error_show(101,'token不能为空');
  19. }
  20. $effetc = VerifyTokens($token);
  21. if(!empty($effetc) && $effetc['code']!=0){
  22. return error_show($effetc['code'],$effetc['message']);
  23. }
  24. $data = Db::name("admin_menu")->where(["pid"=>0,"status"=>1])->select();
  25. $result = [];
  26. if(empty($data)){
  27. return app_show(0,"获取成功",$result);
  28. }
  29. foreach ($data as $key=>$val){
  30. $val["child"]=[];
  31. $result[$val['id']] =$val;
  32. }
  33. $child =Db::name("admin_menu")->where("pid","<>",0)->where('status',"=",1)->select();
  34. foreach ($child as $k=>$value){
  35. // $act = PasAction::all(['menuid'=>$value['id'],"status"=>1]);
  36. $act =Db::name("action")->alias("a")->leftJoin("cfp_action_list l","a.action_code=l.action_code")->field
  37. ("a.*,action_name")->where(['a.menuid'=>$value['id'],"a.status"=>1])->select();
  38. $act_data = Db::name("action_field")->where(['menuid'=>$value['id'],"status"=>1])->select();
  39. $value['action'] = $act;
  40. $value['action_data'] = $act_data;
  41. if(array_key_exists($value['pid'],$result)){
  42. $result[$value['pid']]["child"][]=$value;
  43. }
  44. }
  45. return app_show(0,"获取成功",array_values($result));
  46. }
  47. /**
  48. * @return \think\response\Json
  49. * @throws \think\exception\DbException
  50. */
  51. public function DataAction(){
  52. $post =$this->request->post();
  53. $token = isset($post['token']) ? trim($post['token']) : "";
  54. if($token==""){
  55. return error_show(101,'token不能为空');
  56. }
  57. $effetc = VerifyTokens($token);
  58. if(!empty($effetc) && $effetc['code']!=0){
  59. return error_show($effetc['code'],$effetc['message']);
  60. }
  61. $data = Db::name("data_action")->where(["status"=>1])->select();
  62. return app_show(0,"获取成功",$data);
  63. }
  64. public function ActionList(){
  65. $post =$this->request->post();
  66. $token = isset($post['token']) ? trim($post['token']) : "";
  67. if($token==""){
  68. return error_show(101,'token不能为空');
  69. }
  70. $effetc = VerifyTokens($token);
  71. if(!empty($effetc) && $effetc['code']!=0){
  72. return error_show($effetc['code'],$effetc['message']);
  73. }
  74. $condition = isset($post['contidion']) ? $post['contidion'] :"1";
  75. $page = isset($post['page']) ? intval($post['page']) : 1;
  76. $size = isset($post['size']) ? intval($post['size']) : 10;
  77. $count = Db::name("action_list")->count();
  78. $total = ceil($count/$size)>1 ? ceil($count/$size) : 1;
  79. $page = $page>=$total?intval($total):$page;
  80. $list = Db::name("action_list")->page($page,$size)->select();
  81. $data =['list'=>$list,"count"=>$count];
  82. return app_show(0,'获取成功',$data);
  83. }
  84. /**@param id 存在更新 /不存在新建
  85. /**@param action_name
  86. /**@param action_desc
  87. /**@param status
  88. * @return \think\response\Json
  89. * @throws \think\exception\DbException
  90. */
  91. public function ActionSave(){
  92. $post =$this->request->post();
  93. $token = isset($post['token']) ? trim($post['token']) : "";
  94. if($token==""){
  95. return error_show(101,'token不能为空');
  96. }
  97. $effetc = VerifyTokens($token);
  98. if(!empty($effetc) && $effetc['code']!=0){
  99. return error_show($effetc['code'],$effetc['message']);
  100. }
  101. $actionid = isset($post['id']) ? intval($post['id']) : "";
  102. if($actionid!=""){
  103. $isf= Db::name("action_list")->where("id","=",$actionid)->find();
  104. if($isf==false){
  105. return error_show(1005,"未找到数据");
  106. }
  107. }
  108. $action = isset($post['action_name']) ? trim($post['action_name']) : "";
  109. if($action==""){
  110. return error_show(1003,'功能名称不能为空');
  111. }
  112. $desc = isset($post['action_desc']) ? trim($post['action_desc']) : "";
  113. $status = isset($post['status']) ? intval($post['status']) : 0;
  114. $data=[
  115. "action_name"=>$action,
  116. "action_desc"=>$desc,
  117. "action_code"=>"",
  118. ];
  119. $isTrue = Db::name("action_list")->where(["action_name"=>$action])->find();
  120. if($isTrue){
  121. if($isTrue['id']!=$actionid || $actionid==""){
  122. return error_show(1003,'功能名称不能重复');
  123. }
  124. }
  125. try{
  126. $message = "";
  127. if($actionid==""){
  128. $data['status']=$status;
  129. $data['is_show']=1;
  130. $message = "新建成功";
  131. }else{
  132. $data['status']=$status;
  133. $data['id']=$actionid;
  134. $message = "更新成功";
  135. }
  136. Db::name("action_list")->save($data);
  137. return app_show(0,$message);
  138. }catch (\Exception $e){
  139. return error_show(1005,$e->getMessage());
  140. }
  141. }
  142. /**@param id menu 主键id
  143. * @return \think\response\Json
  144. * @throws \think\exception\DbException
  145. */
  146. public function ActionInfo(){
  147. $post =$this->request->post();
  148. $token = isset($post['token']) ? trim($post['token']) : "";
  149. if($token==""){
  150. return error_show(101,'token不能为空');
  151. }
  152. $effetc = VerifyTokens($token);
  153. if(!empty($effetc) && $effetc['code']!=0){
  154. return error_show($effetc['code'],$effetc['message']);
  155. }
  156. $id = isset($post['id'])? intval($post['id']) :"";
  157. if($id==""){
  158. return error_show(1002,'功能id不能为空');
  159. }
  160. $menu = Db::name("action_list")->where("id","=",$id)->find();
  161. if(empty($menu)){
  162. return error_show(1003,"未找到对应的数据");
  163. }
  164. return app_show(0,"获取成功!",$menu);
  165. }
  166. /**@param id menu 主键id
  167. * @return \think\response\Json
  168. * @throws \think\exception\DbException
  169. */
  170. public function ActionStatus(){
  171. $post =$this->request->post();
  172. $token = isset($post['token']) ? trim($post['token']) : "";
  173. if($token==""){
  174. return error_show(101,'token不能为空');
  175. }
  176. $effetc = VerifyTokens($token);
  177. if(!empty($effetc) && $effetc['code']!=0){
  178. return error_show($effetc['code'],$effetc['message']);
  179. }
  180. $id = isset($post['id'])? intval($post['id']) :"";
  181. if($id==""){
  182. return error_show(1002,'功能id不能为空');
  183. }
  184. $status = isset($post['status'])? intval($post['status']) :"";
  185. if($status===""){
  186. return error_show(1002,'状态status不能为空');
  187. }
  188. $menu = Db::name("action_list")->where("id","=",$id)->save(['status'=>$status]);
  189. return $menu ? app_show(0,"更新成功!") : error_show(1004,"更新失败");
  190. }
  191. }