Department.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. /**
  12. *
  13. */
  14. class Department extends Base {
  15. public function _initialize() {
  16. $admin = Session::get('admin');
  17. if ($admin) {
  18. //已经登陆过
  19. return json_encode(array('status' => 'fail', 'code' => '1001'));
  20. }
  21. }
  22. // 编辑页面
  23. public function index() {
  24. return $this->fetch('index');
  25. }
  26. /**
  27. * 查询数据
  28. */
  29. public function datas() {
  30. $rootMenuData = array();
  31. // 准备根节点
  32. $rootMenuData["id"] = "root";
  33. $rootMenuData["pId"] = "0";
  34. $rootMenuData["name"] = "科室管理";
  35. $rootMenuData["url"] = "";
  36. $rootMenuData["open"] = "true";
  37. // 查询全部数据
  38. $menuData = $info = DB::table('department')->select();
  39. $jsonarray = array();
  40. if ($menuData != null) {
  41. foreach ($menuData as $k => $val) {
  42. $data = array();
  43. $data["id"] = $val["id"];
  44. $data['pId'] = $val["parent_id"];
  45. $data['name'] = $val["department_name"];
  46. $data['institutionid'] = $val["institution_id"];
  47. $data['isreport'] = $val["is_report"];
  48. $data['ordernum'] = $val["order_num"];
  49. array_push($jsonarray, $data);
  50. }
  51. }
  52. // 将根节点添加到树
  53. array_unshift($jsonarray, $rootMenuData);
  54. // 返回JSON数据
  55. echo json_encode($jsonarray);
  56. }
  57. // 添加或修改
  58. public function update() {
  59. $id = $_GET["id"];
  60. // id=&pid=root&name=%E5%A4%96%E7%A7%91&institutionid=&=0&ordernum=11
  61. // ID有值,认为是更新
  62. if (empty($id)) {
  63. $data = array();
  64. // 无值,认为是添加
  65. $data["id"] = UUIDs::uuid16();
  66. $data["parent_id"] = $_GET["pid"];
  67. $data["department_name"] = $_GET["name"];
  68. $data["institution_id"] = $_GET["institutionid"];
  69. $data["order_num"] = $_GET["ordernum"];
  70. $data["is_report"] = $_GET["isreport"];
  71. Db::table("department")->insert($data);
  72. echo "insert_ok";
  73. SysLogs::log("constant", "C", json_encode($data) );
  74. } else {
  75. // 更新
  76. $data["id"] = $_GET["id"];
  77. $data["parent_id"] = $_GET["pid"];
  78. $data["department_name"] = $_GET["name"];
  79. $data["institution_id"] = $_GET["institutionid"];
  80. $data["order_num"] = $_GET["ordernum"];
  81. $data["is_report"] = $_GET["isreport"];
  82. 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"]]);
  83. echo "update_ok";
  84. SysLogs::log("constant", "U",$id . " --> " . json_encode($data) );
  85. }
  86. }
  87. /**
  88. * 删除
  89. */
  90. public function delete() {
  91. $id = $_GET["id"];
  92. $result = Db::table("department")->delete($id);
  93. if ($result) {
  94. echo "delete_ok";
  95. SysLogs::log("department", "D", $id . " --> delete_ok");
  96. } else {
  97. echo "delete_fail";
  98. SysLogs::log("department", "D", $id . " --> delete_fail");
  99. }
  100. }
  101. }