Examclass.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 Examclass extends Base {
  15. public function index() {
  16. return $this->fetch("index");
  17. }
  18. public function datas() {
  19. $request = Request::instance();
  20. $params = $request->param();
  21. $wheres = array();
  22. $insid = isset($params["insid"]) ? $params["insid"] : null;
  23. if ($insid != null && $insid != "") {
  24. $wheres["institution_id"] = $insid;
  25. }
  26. $insMap = array();
  27. $insArr = Db::table("institution")->field("id, name")->select();
  28. if (!empty($insArr)) {
  29. foreach ($insArr as $key => $val) {
  30. $insMap[$val["id"]] = $val["name"];
  31. }
  32. }
  33. $page = empty($params["page"]) ? 1 : $params["page"];
  34. $pagesize = empty($params["rows"]) ? 1 : $params["rows"];
  35. if (empty($page) || $page < 1) {
  36. $page = 1;
  37. }
  38. if (empty($pagesize) || $pagesize < 1) {
  39. $pagesize = 30;
  40. }
  41. $info = DB::table('exam_class')->where($wheres)->page($page, $pagesize)->select();
  42. foreach ($info as $k => $val) {
  43. if (isset($insMap[$val["institution_id"]])) {
  44. $info[$k]["institution_name"] = $insMap[$val["institution_id"]];
  45. } else {
  46. $info[$k]["institution_name"] = $val["institution_id"];
  47. }
  48. }
  49. $num = DB::table('exam_class')->where($wheres)->count();
  50. $data = array();
  51. $data['total'] = $num;
  52. $data['rows'] = $info;
  53. echo json_encode($data);
  54. }
  55. /**
  56. * 编辑窗口
  57. * @return type
  58. */
  59. public function edit() {
  60. $rs = self::itsCombChild("");
  61. $this->assign("insJson", json_encode($rs));
  62. if (isset($_GET["id"])) {
  63. $id = $_GET["id"];
  64. if ($id != null) {
  65. $exam_class = Db::table("exam_class")->where("id", $id)->find();
  66. $this->assign("exam_class", $exam_class);
  67. }
  68. }
  69. return $this->fetch('edit');
  70. }
  71. public function save() {
  72. if (empty($_GET['id'])) {
  73. unset($_GET['id']);
  74. $id = UUIDs::uuid16();
  75. $info = $_GET;
  76. $info['id'] = $id;
  77. $a = DB::table('exam_class')->insert($info);
  78. SysLogs::log("exam_class", "C", json_encode($info));
  79. return 'insert_ok;' . $id;
  80. } else {
  81. $a = DB::table('exam_class')->where('id', $_GET['id'])->update($_GET);
  82. SysLogs::log("exam_class", "C", 'id=' . $_GET['id'] . " --> " . json_encode($_GET));
  83. return 'update_ok';
  84. }
  85. }
  86. /**
  87. * 软删除记录
  88. */
  89. public function delete() {
  90. if (isset($_GET["ids"])) {
  91. $ids = $_GET["ids"];
  92. if (!empty($ids)) {
  93. $idArr = explode(",", $ids);
  94. if (count($idArr) > 0) {
  95. Db::table("exam_class")->where("id", "in", $idArr)->delete();
  96. }
  97. echo "delete_ok";
  98. SysLogs::log("exam_class", "D", $ids);
  99. return;
  100. }
  101. }
  102. echo "fail";
  103. }
  104. public function itsCombChild($pid) {
  105. $rs = Db::table("institution")->where("parent_institution", $pid)->select();
  106. foreach ($rs as $key => $val) {
  107. $rs[$key]["text"] = $val["name"];
  108. $rs[$key]["children"] = self::itsCombChild($val["id"]);
  109. }
  110. return $rs;
  111. }
  112. }