'fail', 'code' => '1001')); } } // 编辑页面 public function index() { return $this->fetch('index'); } /** * 查询数据 */ public function datas() { $rootMenuData = array(); // 准备根节点 $rootMenuData["id"] = "root"; $rootMenuData["pId"] = "0"; $rootMenuData["name"] = "科室管理"; $rootMenuData["url"] = ""; $rootMenuData["open"] = "true"; // 查询全部数据 $menuData = $info = DB::table('department')->select(); $jsonarray = array(); if ($menuData != null) { foreach ($menuData as $k => $val) { $data = array(); $data["id"] = $val["id"]; $data['pId'] = $val["parent_id"]; $data['name'] = $val["department_name"]; $data['institutionid'] = $val["institution_id"]; $data['isreport'] = $val["is_report"]; $data['ordernum'] = $val["order_num"]; array_push($jsonarray, $data); } } // 将根节点添加到树 array_unshift($jsonarray, $rootMenuData); // 返回JSON数据 echo json_encode($jsonarray); } // 添加或修改 public function update() { $id = $_GET["id"]; // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11 // ID有值,认为是更新 if (empty($id)) { $data = array(); // 无值,认为是添加 $data["id"] = UUIDs::uuid16(); $data["parent_id"] = $_GET["pid"]; $data["department_name"] = $_GET["name"]; $data["institution_id"] = $_GET["institutionid"]; $data["order_num"] = $_GET["ordernum"]; $data["is_report"] = $_GET["isreport"]; Db::table("department")->insert($data); echo "insert_ok"; SysLogs::log("constant", "C", json_encode($data) ); } else { // 更新 $data["id"] = $_GET["id"]; $data["parent_id"] = $_GET["pid"]; $data["department_name"] = $_GET["name"]; $data["institution_id"] = $_GET["institutionid"]; $data["order_num"] = $_GET["ordernum"]; $data["is_report"] = $_GET["isreport"]; Db::table("department")->where("id", $id)->update(["parent_id" => $data["parent_id"], "department_name" => $data["department_name"], "institution_id" => $data["institution_id"], "is_report" => $data["is_report"], "order_num" => $data["order_num"]]); echo "update_ok"; SysLogs::log("constant", "U",$id . " --> " . json_encode($data) ); } } /** * 删除 */ public function delete() { $id = $_GET["id"]; $result = Db::table("department")->delete($id); if ($result) { echo "delete_ok"; SysLogs::log("department", "D", $id . " --> delete_ok"); } else { echo "delete_fail"; SysLogs::log("department", "D", $id . " --> delete_fail"); } } }