Manager.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. namespace app\manage\controller;
  3. use think\Controller;
  4. use think\Db;
  5. use think\Session;
  6. use think\Config;
  7. use think\Cookie;
  8. use think\Request;
  9. use app\common\library\SysLogs;
  10. use app\common\library\UUIDs;
  11. class Manager extends Base {
  12. public function index() {
  13. $rs = Db::table("institution")->select();
  14. $this->assign("institutions", $rs);
  15. return $this->fetch('index');
  16. }
  17. /**
  18. * 查询全部的管理员信息
  19. * 暂时不考虑分页
  20. */
  21. public function datas() {
  22. $request = Request::instance()->param();
  23. $username = isset($request["username"]) ? $request["username"] : null;
  24. $status = isset($request["status"]) ? $request["status"] : null;
  25. $page = $request["page"];
  26. $pageSize = $request["rows"];
  27. $whereArr = array();
  28. if ($username != null) {
  29. $whereArr["username"] = array("like", $username . "%");
  30. }
  31. if ($status != null) {
  32. $whereArr["status"] = $status;
  33. }
  34. //$count=(clone $tableReq )->where($whereArr)->count("1");
  35. $count = Db::table("manager")->where($whereArr)->count("1");
  36. $rows = Db::table("manager")->where($whereArr)->page($page, $pageSize)->select();
  37. //$count=30;
  38. $rs = array();
  39. $rs["total"] = $count;
  40. $rs["rows"] = $rows;
  41. echo json_encode($rs);
  42. }
  43. public function edit() {
  44. $rs = self::itsCombChild("");
  45. $this->assign("insJson", json_encode($rs));
  46. if (isset($_GET["id"])) {
  47. $id = $_GET["id"];
  48. if ($id != null) {
  49. $managers = Db::table("manager")->where("id", $id)->select();
  50. if (count($managers) > 0) {
  51. $this->assign("manager", $managers[0]);
  52. }
  53. }
  54. }
  55. return $this->fetch('edit');
  56. }
  57. public function itsCombChild($pid) {
  58. $rs = Db::table("institution")->where("parent_institution", $pid)->select();
  59. foreach ($rs as $key => $val) {
  60. $rs[$key]["text"] = $val["name"];
  61. $rs[$key]["children"] = self::itsCombChild($val["id"]);
  62. }
  63. return $rs;
  64. }
  65. /**
  66. * 更新或创建机构信息
  67. */
  68. public function save() {
  69. $id = $_GET["id"];
  70. $data = array();
  71. $data["username"] = $_GET["username"];
  72. $data["password"] = $_GET["password"];
  73. $data["role_id"] = $_GET["role_id"];
  74. $data["email"] = $_GET["email"];
  75. $data["phone"] = $_GET["phone"];
  76. $data["status"] = $_GET["status"];
  77. $data["institution_id"] = $_GET["institution_id"];
  78. $data["loginfailure"] = $_GET["loginfailure"];
  79. if(is_array($data["institution_id"])){
  80. $pids="";
  81. foreach($data["institution_id"] as $key => $val){
  82. $pids = $pids . "," . $val;
  83. }
  84. if(strlen($pids)>0 ){
  85. $data["institution_id"]= substr($pids, 1);
  86. }else{
  87. $data["institution_id"]= "";
  88. }
  89. }
  90. // ID有值,认为是更新
  91. if (empty($id)) {
  92. // 无值,认为是添加
  93. $data["id"] = UUIDs::uuid16();
  94. $data["createdAt"] = date("Y-m-d H:i:s");
  95. Db::table("manager")->insert($data);
  96. SysLogs::log("manager", "C", json_encode($data));
  97. echo "insert_ok;" . $data["id"];
  98. } else {
  99. $data["updatedAt"] = date("Y-m-d H:i:s");
  100. // 更新
  101. Db::table("manager")->where("id", $id)->update($data);
  102. SysLogs::log("manager", "U", "id = " . $id . " --> " . json_encode($data));
  103. echo "update_ok";
  104. }
  105. }
  106. /**
  107. * 删除记录
  108. */
  109. public function delete() {
  110. if (isset($_GET["ids"])) {
  111. $ids = $_GET["ids"];
  112. if (!empty($ids)) {
  113. $idArr = explode(",", $ids);
  114. if (count($idArr) > 0) {
  115. Db::table("manager")->where("id", "in", $idArr)->delete();
  116. }
  117. SysLogs::log("manager", "D", $ids);
  118. echo "delete_ok";
  119. return;
  120. }
  121. }
  122. echo "fail";
  123. }
  124. }