select(); $this->assign("institutions", $rs); return $this->fetch('index'); } /** * 查询全部的管理员信息 * 暂时不考虑分页 */ public function datas() { $request = Request::instance()->param(); $username = isset($request["username"]) ? $request["username"] : null; $status = isset($request["status"]) ? $request["status"] : null; $page = $request["page"]; $pageSize = $request["rows"]; $whereArr = array(); if ($username != null) { $whereArr["username"] = array("like", $username . "%"); } if ($status != null) { $whereArr["status"] = $status; } //$count=(clone $tableReq )->where($whereArr)->count("1"); $count = Db::table("manager")->where($whereArr)->count("1"); $rows = Db::table("manager")->where($whereArr)->page($page, $pageSize)->select(); //$count=30; $rs = array(); $rs["total"] = $count; $rs["rows"] = $rows; echo json_encode($rs); } public function edit() { $rs = self::itsCombChild(""); $this->assign("insJson", json_encode($rs)); if (isset($_GET["id"])) { $id = $_GET["id"]; if ($id != null) { $managers = Db::table("manager")->where("id", $id)->select(); if (count($managers) > 0) { $this->assign("manager", $managers[0]); } } } return $this->fetch('edit'); } public function itsCombChild($pid) { $rs = Db::table("institution")->where("parent_institution", $pid)->select(); foreach ($rs as $key => $val) { $rs[$key]["text"] = $val["name"]; $rs[$key]["children"] = self::itsCombChild($val["id"]); } return $rs; } /** * 更新或创建机构信息 */ public function save() { $id = $_GET["id"]; $data = array(); $data["username"] = $_GET["username"]; $data["password"] = $_GET["password"]; $data["role_id"] = $_GET["role_id"]; $data["email"] = $_GET["email"]; $data["phone"] = $_GET["phone"]; $data["status"] = $_GET["status"]; $data["institution_id"] = $_GET["institution_id"]; $data["loginfailure"] = $_GET["loginfailure"]; if(is_array($data["institution_id"])){ $pids=""; foreach($data["institution_id"] as $key => $val){ $pids = $pids . "," . $val; } if(strlen($pids)>0 ){ $data["institution_id"]= substr($pids, 1); }else{ $data["institution_id"]= ""; } } // ID有值,认为是更新 if (empty($id)) { // 无值,认为是添加 $data["id"] = UUIDs::uuid16(); $data["createdAt"] = date("Y-m-d H:i:s"); Db::table("manager")->insert($data); SysLogs::log("manager", "C", json_encode($data)); echo "insert_ok;" . $data["id"]; } else { $data["updatedAt"] = date("Y-m-d H:i:s"); // 更新 Db::table("manager")->where("id", $id)->update($data); SysLogs::log("manager", "U", "id = " . $id . " --> " . json_encode($data)); echo "update_ok"; } } /** * 删除记录 */ public function delete() { if (isset($_GET["ids"])) { $ids = $_GET["ids"]; if (!empty($ids)) { $idArr = explode(",", $ids); if (count($idArr) > 0) { Db::table("manager")->where("id", "in", $idArr)->delete(); } SysLogs::log("manager", "D", $ids); echo "delete_ok"; return; } } echo "fail"; } }