|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-declare (strict_types = 1);
|
|
|
+declare (strict_types=1);
|
|
|
|
|
|
namespace app\admin\controller;
|
|
|
|
|
@@ -11,202 +11,293 @@ use think\App;
|
|
|
class Action extends BaseController
|
|
|
{
|
|
|
|
|
|
- public function __construct(App $app)
|
|
|
- {
|
|
|
- parent::__construct($app);
|
|
|
- $post =$this->request->post();
|
|
|
- $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if($token==""){
|
|
|
- return error_show(101,'token不能为空');
|
|
|
-
|
|
|
- }
|
|
|
- $effetc = VerifyTokens($token);
|
|
|
- if(!empty($effetc) && $effetc['code']!=0){
|
|
|
- return error_show($effetc['code'],$effetc['message']);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
/**
|
|
|
- * 显示资源列表
|
|
|
+ * public function __construct(App $app)
|
|
|
+ * {
|
|
|
+ * parent::__construct($app);
|
|
|
+ * $post =$this->request->post();
|
|
|
+ * $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if($token==""){
|
|
|
+ * return json_show(101,'token不能为空');
|
|
|
*
|
|
|
- * @return \think\Response
|
|
|
- */
|
|
|
- public function ActionList(){
|
|
|
- $post =$this->request->post();
|
|
|
- $pageid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
- if($pageid==""){
|
|
|
- return error_show(1001,'页面id不能为空');
|
|
|
- }
|
|
|
- $condition = ['menuid'=>$pageid];
|
|
|
- $data=Db::name('action')->alias("a")->leftJoin("action_list l","a.action_code=l.action_code")->field
|
|
|
- ("a.*,action_name")->where($condition)->select();
|
|
|
- return app_show(0,"获取成功",$data);
|
|
|
- }
|
|
|
+ * }
|
|
|
+ * $effetc = VerifyTokens($token);
|
|
|
+ * if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ * return json_show($effetc['code'],$effetc['message']);
|
|
|
+ *
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * public function ActionList(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ * $pageid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
+ * if($pageid==""){
|
|
|
+ * return json_show(1001,'页面id不能为空');
|
|
|
+ * }
|
|
|
+ * $condition = ['menuid'=>$pageid];
|
|
|
+ * $data=Db::name('action')->alias("a")->leftJoin("action_list l","a.action_code=l.action_code")->field
|
|
|
+ * ("a.*,action_name")->where($condition)->select();
|
|
|
+ * return json_show(0,"获取成功",$data);
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * public function ActionSave(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ * $actionid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
+ * if($actionid!=""){
|
|
|
+ * $isf= Db::name("action_list")->where("id","=",$actionid)->find();
|
|
|
+ * if($isf==false){
|
|
|
+ * return json_show(1005,"未找到数据");
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ * $action = isset($post['action_name']) ? trim($post['action_name']) : "";
|
|
|
+ * if($action==""){
|
|
|
+ * return json_show(1003,'功能名称不能为空');
|
|
|
+ * }
|
|
|
+ * $desc = isset($post['action_desc']) ? trim($post['action_desc']) : "";
|
|
|
+ * $status = isset($post['status']) ? intval($post['status']) : 0;
|
|
|
+ * $data=[
|
|
|
+ * "action_name"=>$action,
|
|
|
+ * "action_desc"=>$desc,
|
|
|
+ * "action_code"=>"",
|
|
|
+ * ];
|
|
|
+ *
|
|
|
+ * $isTrue = Db::name("action_list")->where(["action_name"=>$action])->find();
|
|
|
+ * if($isTrue){
|
|
|
+ * if($isTrue['id']!=$actionid || $actionid==""){
|
|
|
+ * return json_show(1003,'功能名称不能重复');
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * try{
|
|
|
+ * $message = "";
|
|
|
+ * if($actionid==""){
|
|
|
+ * $data['status']=$status;
|
|
|
+ * $data['is_show']=1;
|
|
|
+ * $message = "新建成功";
|
|
|
+ * }else{
|
|
|
+ * $data['status']=$status;
|
|
|
+ * $data['id']=$actionid;
|
|
|
+ * $message = "更新成功";
|
|
|
+ * }
|
|
|
+ * Db::name("action_list")->save($data);
|
|
|
+ * return json_show(0,$message);
|
|
|
+ * }catch (\Exception $e){
|
|
|
+ * return json_show(1005,$e->getMessage());
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * public function ActionStatus(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ *
|
|
|
+ * $actid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
+ * if($actid==""){
|
|
|
+ * return json_show(1001,'功能id不能为空');
|
|
|
+ * }
|
|
|
+ * $status = isset($post['status']) ? intval($post['status']) : 1;
|
|
|
+ * try{
|
|
|
+ * $data = ['status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+ * $result=Db::name("action")->where("id","=",$actid)->save($data);
|
|
|
+ * if($result){
|
|
|
+ * return json_show(0,"更新成功");
|
|
|
+ * }else{
|
|
|
+ * return json_show(1004,"更新失败");
|
|
|
+ * }
|
|
|
+ * }catch (\Exception $e){
|
|
|
+ * return json_show(1003,$e->getMessage());
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * public function ActionAdd(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ *
|
|
|
+ * $pageid = isset($post['menuid']) ? intval($post['menuid']) : "";
|
|
|
+ * if($pageid==""){
|
|
|
+ * return json_show(1001,'页面id不能为空');
|
|
|
+ * }
|
|
|
+ * $code = isset($post['action_code']) ? trim($post['action_code']) : "";
|
|
|
+ *
|
|
|
+ * $status = isset($post['status']) ? intval($post['status']) : 1;
|
|
|
+ * if($code==""){
|
|
|
+ * return json_show(1002,'功能code不能为空');
|
|
|
+ * }
|
|
|
+ * try{
|
|
|
+ * $where = ['menuid'=>$pageid,'action_code'=>$code];
|
|
|
+ * $true =Db::name("action")->where($where)->find();
|
|
|
+ * $data = ['menuid'=>$pageid,'action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s"),"addtime"=>date("Y-m-d H:i:s")];
|
|
|
+ * if($true){
|
|
|
+ * return json_show(1003,'此功能已存在');
|
|
|
+ * }else{
|
|
|
+ * Db::name("action")->insert($data);
|
|
|
+ * return json_show(0,"添加成功");
|
|
|
+ * }
|
|
|
+ * }catch (\Exception $e){
|
|
|
+ * return json_show(1005,$e->getMessage());
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * public function index(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ * $data = Db::name("admin_menu")->where(["pid"=>0,"status"=>1,"is_del"=>0])->select();
|
|
|
+ * $result = [];
|
|
|
+ * if(empty($data)){
|
|
|
+ * return json_show(0,"获取成功",$result);
|
|
|
+ * }
|
|
|
+ * foreach ($data as $key=>$val){
|
|
|
+ * $val["child"]=[];
|
|
|
+ * $result[$val['id']] =$val;
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * $child =Db::name("admin_menu")->where([["pid","<>",0],['status',"=",1],["is_del","=",0]])->select();
|
|
|
+ * foreach ($child as $k=>$value){
|
|
|
+ * // $act = PasAction::all(['menuid'=>$value['id'],"status"=>1]);
|
|
|
+ * $act =Db::name("action")
|
|
|
+ * ->alias("a")
|
|
|
+ * ->leftJoin("action_list l","a.action_code=l.action_code")
|
|
|
+ * ->field("a.*,action_name")
|
|
|
+ * ->where(['a.menuid'=>$value['id'],"a.status"=>1])
|
|
|
+ * ->withAttr('id',function($val){
|
|
|
+ * return (string)$val;
|
|
|
+ * })
|
|
|
+ * ->select()
|
|
|
+ * ->toArray();
|
|
|
+ * $act_data = Db::name("action_field")->where(['menuid'=>$value['id'],"status"=>1])->select();
|
|
|
+ * $value['action'] = $act;
|
|
|
+ * $value['action_data'] = $act_data;
|
|
|
+ * if(array_key_exists($value['pid'],$result)){
|
|
|
+ * $result[$value['pid']]["child"][]=$value;
|
|
|
+ * }
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * return json_show(0,"获取成功",array_values($result));
|
|
|
+ * }
|
|
|
+ *
|
|
|
+ * public function ActionInfo(){
|
|
|
+ * $post =$this->request->post();
|
|
|
+ * $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ * if($token==""){
|
|
|
+ * return json_show(101,'token不能为空');
|
|
|
+ * }
|
|
|
+ * $effetc = VerifyTokens($token);
|
|
|
+ * if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ * return json_show($effetc['code'],$effetc['message']);
|
|
|
+ * }
|
|
|
+ * $id = isset($post['id'])? intval($post['id']) :"";
|
|
|
+ * if($id==""){
|
|
|
+ * return json_show(1002,'功能id不能为空');
|
|
|
+ * }
|
|
|
+ * $menu = Db::name("action_list")->where("id","=",$id)->find();
|
|
|
+ * if(empty($menu)){
|
|
|
+ * return json_show(1003,"未找到对应的数据");
|
|
|
+ * }
|
|
|
+ * return json_show(0,"获取成功!",$menu);
|
|
|
+ * }
|
|
|
+ * **/
|
|
|
|
|
|
- public function ActionSave(){
|
|
|
- $post =$this->request->post();
|
|
|
- $actionid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
- if($actionid!=""){
|
|
|
- $isf= Db::name("action_list")->where("id","=",$actionid)->find();
|
|
|
- if($isf==false){
|
|
|
- return error_show(1005,"未找到数据");
|
|
|
- }
|
|
|
- }
|
|
|
- $action = isset($post['action_name']) ? trim($post['action_name']) : "";
|
|
|
- if($action==""){
|
|
|
- return error_show(1003,'功能名称不能为空');
|
|
|
- }
|
|
|
- $desc = isset($post['action_desc']) ? trim($post['action_desc']) : "";
|
|
|
- $status = isset($post['status']) ? intval($post['status']) : 0;
|
|
|
- $data=[
|
|
|
- "action_name"=>$action,
|
|
|
- "action_desc"=>$desc,
|
|
|
- "action_code"=>"",
|
|
|
- ];
|
|
|
|
|
|
- $isTrue = Db::name("action_list")->where(["action_name"=>$action])->find();
|
|
|
- if($isTrue){
|
|
|
- if($isTrue['id']!=$actionid || $actionid==""){
|
|
|
- return error_show(1003,'功能名称不能重复');
|
|
|
- }
|
|
|
- }
|
|
|
+ //11获取素有菜单列表数据
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $post = $this->request->post();
|
|
|
|
|
|
- try{
|
|
|
- $message = "";
|
|
|
- if($actionid==""){
|
|
|
- $data['status']=$status;
|
|
|
- $data['is_show']=1;
|
|
|
- $message = "新建成功";
|
|
|
- }else{
|
|
|
- $data['status']=$status;
|
|
|
- $data['id']=$actionid;
|
|
|
- $message = "更新成功";
|
|
|
- }
|
|
|
- Db::name("action_list")->save($data);
|
|
|
- return app_show(0,$message);
|
|
|
- }catch (\Exception $e){
|
|
|
- return error_show(1005,$e->getMessage());
|
|
|
+ $where = [["status", "=", 1], ["is_del", "=", 0], ["level", ">=", $post["level"] ?? 1], ['menu_type', "=", 2]];
|
|
|
+ $data = Db::name("admin_menu")->where($where)->order("weight desc")->column("id,menu_name,menu_img,menu_route,menu_url,pid,level,is_show,is_private,menu_type,status");
|
|
|
+ $result = [];
|
|
|
+ if (empty($data)) {
|
|
|
+ return json_show(0, "获取成功", $result);
|
|
|
}
|
|
|
+ $list = [];
|
|
|
+ $menu = [];
|
|
|
+ foreach ($data as $k => $value) {
|
|
|
+ $action = Db::name("action")
|
|
|
+ ->alias("a")
|
|
|
+ ->leftJoin("action_list b", "a.action_code=b.action_code")
|
|
|
+ ->where(["menuid" => $value['id'], "a.status" => 1, "a.is_del" => 0, "b.is_del" => 0])
|
|
|
+ ->column("a.id,a.action_code,b.action_name");
|
|
|
+ if ($value['menu_type'] == 2) $value['action'] = $action;
|
|
|
+ $list[] = $value;
|
|
|
+ }
|
|
|
+ menuAction($list, $menu);
|
|
|
+ return json_show(0, "获取成功", array_values($menu));
|
|
|
}
|
|
|
|
|
|
- public function ActionStatus(){
|
|
|
- $post =$this->request->post();
|
|
|
-
|
|
|
- $actid = isset($post['id']) ? intval($post['id']) : "";
|
|
|
- if($actid==""){
|
|
|
- return error_show(1001,'功能id不能为空');
|
|
|
- }
|
|
|
- $status = isset($post['status']) ? intval($post['status']) : 1;
|
|
|
- try{
|
|
|
- $data = ['status'=>$status,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
- $result=Db::name("action")->where("id","=",$actid)->save($data);
|
|
|
- if($result){
|
|
|
- return app_show(0,"更新成功");
|
|
|
- }else{
|
|
|
- return error_show(1004,"更新失败");
|
|
|
- }
|
|
|
- }catch (\Exception $e){
|
|
|
- return error_show(1003,$e->getMessage());
|
|
|
- }
|
|
|
+ public function ActionList()
|
|
|
+ {
|
|
|
+ $post = $this->post;
|
|
|
+ $page = isset($post['page']) ? intval($post['page']) : 1;
|
|
|
+ $size = isset($post['size']) ? intval($post['size']) : 10;
|
|
|
+ $count = Db::name("action_list")->where(["is_del" => 0])->count();
|
|
|
+ $total = ceil($count / $size) > 1 ? ceil($count / $size) : 1;
|
|
|
+ $page = $page >= $total ? intval($total) : $page;
|
|
|
+ $list = Db::name("action_list")->where(["is_del" => 0])->page($page, $size)->select()->toArray();
|
|
|
+ $data = ['list' => $list, "count" => $count];
|
|
|
+ return json_show(0, '获取成功', $data);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
+
|
|
|
+ /** 菜单下功能信息状态修改
|
|
|
* @return \think\response\Json|void
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public function ActionAdd(){
|
|
|
- $post =$this->request->post();
|
|
|
-
|
|
|
- $pageid = isset($post['menuid']) ? intval($post['menuid']) : "";
|
|
|
- if($pageid==""){
|
|
|
- return error_show(1001,'页面id不能为空');
|
|
|
+ public function ActionAdd()
|
|
|
+ {
|
|
|
+ $post = $this->post;
|
|
|
+ $action_name = isset($post['action_name']) ? trim($post['action_name']) : "";
|
|
|
+ if ($action_name == "") {
|
|
|
+ return json_show(1001, '功能名称不能为空');
|
|
|
}
|
|
|
+ $action_desc = isset($post['action_desc']) ? trim($post['action_desc']) : "";
|
|
|
$code = isset($post['action_code']) ? trim($post['action_code']) : "";
|
|
|
-
|
|
|
- $status = isset($post['status']) ? intval($post['status']) : 1;
|
|
|
- if($code==""){
|
|
|
- return error_show(1002,'功能code不能为空');
|
|
|
+ if ($code == "") {
|
|
|
+ return json_show(1001, '功能代码不能为空');
|
|
|
}
|
|
|
- try{
|
|
|
- $where = ['menuid'=>$pageid,'action_code'=>$code];
|
|
|
- $true =Db::name("action")->where($where)->find();
|
|
|
- $data = ['menuid'=>$pageid,'action_code'=>$code,'status'=>$status,"updatetime"=>date("Y-m-d H:i:s"),"addtime"=>date("Y-m-d H:i:s")];
|
|
|
- if($true){
|
|
|
- return error_show(1003,'此功能已存在');
|
|
|
- }else{
|
|
|
- Db::name("action")->insert($data);
|
|
|
- return app_show(0,"添加成功");
|
|
|
- }
|
|
|
- }catch (\Exception $e){
|
|
|
- return error_show(1005,$e->getMessage());
|
|
|
+ $status = isset($post['status']) ? intval($post['status']) : 1;
|
|
|
+ try {
|
|
|
+ $action = [
|
|
|
+ "action_name" => $action_name,
|
|
|
+ "action_code" => $code,
|
|
|
+ "action_desc" => $action_desc,
|
|
|
+ "status" => $status,
|
|
|
+ "is_show" => 1,
|
|
|
+ "addtime" => date("Y-m-d H:i:s"),
|
|
|
+ "updatetime" => date("Y-m-d H:i:s")
|
|
|
+ ];
|
|
|
+ $up = Db::name("action_list")->insert($action);
|
|
|
+ return $up ? json_show(0, "新建成功") : json_show(1004, "新建失败");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return json_show(1005, $e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\db\exception\DataNotFoundException
|
|
|
- * @throws \think\db\exception\DbException
|
|
|
- * @throws \think\db\exception\ModelNotFoundException
|
|
|
+
|
|
|
+ /** 菜单下功能信息状态修改
|
|
|
+ * @return \think\response\Json|void
|
|
|
* @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public function index(){
|
|
|
- $post =$this->request->post();
|
|
|
- $data = Db::name("admin_menu")->where(["pid"=>0,"status"=>1,"is_del"=>0])->select();
|
|
|
- $result = [];
|
|
|
- if(empty($data)){
|
|
|
- return app_show(0,"获取成功",$result);
|
|
|
+ public function ActionDel()
|
|
|
+ {
|
|
|
+ $post = $this->post;
|
|
|
+ $action_id = isset($post['action_id']) ? intval($post['action_id']) : "";
|
|
|
+ if ($action_id === "") {
|
|
|
+ return json_show(1001, '参数action_id不能为空');
|
|
|
}
|
|
|
- foreach ($data as $key=>$val){
|
|
|
- $val["child"]=[];
|
|
|
- $result[$val['id']] =$val;
|
|
|
+ $action = Db::name("action_list")->where(["id" => $action_id, "is_del" => 0])->find();
|
|
|
+ if ($action == false) {
|
|
|
+ return json_show(1004, "未找到功能数据");
|
|
|
}
|
|
|
-
|
|
|
- $child =Db::name("admin_menu")->where([["pid","<>",0],['status',"=",1],["is_del","=",0]])->select();
|
|
|
- foreach ($child as $k=>$value){
|
|
|
- // $act = PasAction::all(['menuid'=>$value['id'],"status"=>1]);
|
|
|
- $act =Db::name("action")
|
|
|
- ->alias("a")
|
|
|
- ->leftJoin("action_list l","a.action_code=l.action_code")
|
|
|
- ->field("a.*,action_name")
|
|
|
- ->where(['a.menuid'=>$value['id'],"a.status"=>1])
|
|
|
- ->withAttr('id',function($val){
|
|
|
- return (string)$val;
|
|
|
- })
|
|
|
- ->select()
|
|
|
- ->toArray();
|
|
|
- $act_data = Db::name("action_field")->where(['menuid'=>$value['id'],"status"=>1])->select();
|
|
|
- $value['action'] = $act;
|
|
|
- $value['action_data'] = $act_data;
|
|
|
- if(array_key_exists($value['pid'],$result)){
|
|
|
- $result[$value['pid']]["child"][]=$value;
|
|
|
+ $upda = ["is_del" => 0, "updatetime" => date("Y-m-d H:i:s")];
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ $up = Db::name("action_list")->where($action)->update($upda);
|
|
|
+ if ($up) {
|
|
|
+ $upall = Db::name("action")->where(["action_code" => $action['action_code'], "is_del" => 0])->update($upda);
|
|
|
+ Db::commit();
|
|
|
+ return json_show(0, "删除成功");
|
|
|
}
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1005, "删除失败");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ return json_show(1005, $e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- return app_show(0,"获取成功",array_values($result));
|
|
|
}
|
|
|
|
|
|
- /**@param id menu 主键id
|
|
|
- * @return \think\response\Json
|
|
|
- * @throws \think\exception\DbException
|
|
|
- */
|
|
|
- public function ActionInfo(){
|
|
|
- $post =$this->request->post();
|
|
|
- $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
- if($token==""){
|
|
|
- return error_show(101,'token不能为空');
|
|
|
- }
|
|
|
- $effetc = VerifyTokens($token);
|
|
|
- if(!empty($effetc) && $effetc['code']!=0){
|
|
|
- return error_show($effetc['code'],$effetc['message']);
|
|
|
- }
|
|
|
- $id = isset($post['id'])? intval($post['id']) :"";
|
|
|
- if($id==""){
|
|
|
- return error_show(1002,'功能id不能为空');
|
|
|
- }
|
|
|
- $menu = Db::name("action_list")->where("id","=",$id)->find();
|
|
|
- if(empty($menu)){
|
|
|
- return error_show(1003,"未找到对应的数据");
|
|
|
- }
|
|
|
- return app_show(0,"获取成功!",$menu);
|
|
|
- }
|
|
|
}
|