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']); * * } * } * 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->only(['id', 'action_code'], 'post', 'trim'); $val = Validate::rule([ 'id|ID' => 'require|number|gt:0', 'action_code' => 'require' ]); if ($val->check($post) == false) return error_show(1004, $val->getError()); $rs = Db::name("action") ->where(['is_del' => 0, 'id' => $post['id']]) ->update([ 'action_code' => $post['action_code'], 'updatetime' => date("Y-m-d H:i:s") ]); return $rs ? json_show(0, "修改成功") : json_show(0, "修改失败"); } 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); return $result ? json_show(0, "更新成功") : json_show(1004, "更新失败"); } catch (\Exception $e) { return json_show(1003, $e->getMessage()); } } //11获取所有菜单列表数据 public function index() { $post = $this->request->post(); $data = Db::name("admin_menu") ->where(["pid" => 0, "status" => 1, "is_del" => 0]) ->order(['weight'=>'desc','id'=>'desc']) ->select() ->toArray(); $result = []; if (empty($data)) { return app_show(0, "获取成功", $result); } foreach ($data as $key => $val) { $val["child"] = []; $result[$val['id']] = $val; } $child_where = [["pid", "<>", 0], ['status', "=", 1], ["is_del", "=", 0]]; if (isset($post['level']) && $post['level'] !== '') $child_where[] = ['level', 'in', $post['level']]; $child = Db::name("admin_menu") ->where($child_where) ->order(['weight'=>'desc','id'=>'desc']) ->select() ->toArray(); foreach ($child as $k => $value) { $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]) ->select() ->toArray(); $value['action'] = $act; $value['action_data'] =[]; if (array_key_exists($value['pid'], $result)) { $result[$value['pid']]["child"][] = $value; } } return json_show(0, "获取成功", array_values($result)); } 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() ->toArray(); return app_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不能为空'); } $code = isset($post['action_code']) ? trim($post['action_code']) : ""; if ($code == "") { return error_show(1002, '功能code不能为空'); } $status = isset($post['status']) ? intval($post['status']) : 1; try { $where = ['menuid' => $pageid, 'action_code' => $code]; $true = Db::name("action")->field('id')->where($where)->find(); if ($true) return error_show(1003, '此功能已存在'); else { $data = ['menuid' => $pageid, 'action_code' => $code, 'status' => $status, "updatetime" => date("Y-m-d H:i:s"), "addtime" => date("Y-m-d H:i:s")]; Db::name("action")->insert($data); return app_show(0, "添加成功"); } } catch (\Exception $e) { return error_show(1005, $e->getMessage()); } } /** 菜单下功能信息状态修改 * @return \think\response\Json|void * @throws \think\exception\DbException */ public function ActionDel() { $post = $this->request->filter('trim')->post(); $action_id = isset($post['action_id']) ? intval($post['action_id']) : ""; if ($action_id === "") { return json_show(1001, '参数action_id不能为空'); } $action = Db::name("action_list")->where(["id" => $action_id, "is_del" => 0])->find(); if ($action == false) { return json_show(1004, "未找到功能数据"); } $upda = ["is_del" => 1, "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 \think\response\Json|void * @throws \think\exception\DbException */ public function ActionCreate() { $post = $this->request->param(["action_name"=>"","action_code"=>"","is_del"=>0]); $valid = Validate::rule([ "action_name|功能名称"=>"require", "action_code|功能编号"=>"require|unique:action_list,action_code^is_del"]); if($valid->check($post)==false)return error_show(1004,$valid->getError()); $save=Db::name("action_list")->save($post); return $save? app_show(0,"创建成功"):error_show(1004,"创建失败"); } }