123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace app\manage\controller;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- class Manager extends Base {
- public function index() {
- $rs = Db::table("institution")->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";
- }
- }
|