Examsubclass.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 Examsubclass extends Base {
  15. public function index() {
  16. return $this->fetch();
  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["exam_class.institution_id"] = $insid;
  25. }
  26. $classid = isset($params["class_id"]) ? $params["class_id"] : null;
  27. if ($classid != null && $classid != "") {
  28. $wheres["exam_class.id"] = $classid;
  29. }
  30. $name = isset($params["name"]) ? $params["name"] : null;
  31. if ($name != null && $name != "") {
  32. $wheres["exam_subclass.name"] = array("like", "%" . $name . "%");
  33. }
  34. $page = empty($params["page"]) ? 1 : $params["page"];
  35. $pagesize = empty($params["rows"]) ? 1 : $params["rows"];
  36. if (empty($page) || $page < 1) {
  37. $page = 1;
  38. }
  39. if (empty($pagesize) || $pagesize < 1) {
  40. $pagesize = 30;
  41. }
  42. $info = DB::view("exam_subclass", "id,name,exam_class_id")
  43. ->view("exam_class", "name as claName ", "exam_class.id=exam_subclass.exam_class_id")
  44. ->where($wheres)
  45. ->page($page, $pagesize)->select();
  46. foreach ($info as $k => $v) {
  47. $name = Db::table("exam_class")->where('id', $v['exam_class_id'])->field('name')->find();
  48. $info[$k]['class_name'] = $name['name'];
  49. }
  50. $num = DB::view("exam_subclass", "id,name")
  51. ->view("exam_class", "name as claName ", "exam_class.id=exam_subclass.exam_class_id")
  52. ->where($wheres)
  53. ->count();
  54. $data = array();
  55. $data['total'] = $num;
  56. $data['rows'] = $info;
  57. echo json_encode($data);
  58. }
  59. /**
  60. * 编辑窗口
  61. * @return type
  62. */
  63. public function edit() {
  64. if (isset($_GET["id"])) {
  65. $id = $_GET["id"];
  66. if ($id != null) {
  67. $exam_subclass = Db::table("exam_subclass")->where("id", $id)->select();
  68. if (count($exam_subclass) > 0) {
  69. $this->assign("exam_subclass", $exam_subclass[0]);
  70. }
  71. }
  72. }
  73. /*$class = DB::view('exam_class', 'id, institution_id, name ')
  74. ->view("institution", "name as insName", "exam_class.institution_id=institution.id")
  75. ->order(array("institution.id","1"))
  76. ->select();*/
  77. $class = DB::table('constant')->where('parent_id','exam_class')->field('id,constant_value as insName')->select();
  78. $this->assign("class", $class);
  79. return $this->fetch('edit');
  80. }
  81. public function save() {
  82. if (empty($_GET['id'])) {
  83. unset($_GET['id']);
  84. $id = UUIDs::uuid16();
  85. $info = $_GET;
  86. $info['id'] = $id;
  87. $a = DB::table('exam_subclass')->insert($info);
  88. SysLogs::log("exam_subclass", "C", json_encode($info));
  89. return 'insert_ok;' . $id;
  90. } else {
  91. $a = DB::table('exam_subclass')->where('id', $_GET['id'])->update($_GET);
  92. SysLogs::log("exam_subclass", "U", 'id = ' . $_GET['id'] . " --> " . json_encode($_GET));
  93. return 'update_ok';
  94. }
  95. }
  96. /**
  97. * 软删除记录
  98. */
  99. public function delete() {
  100. if (isset($_GET["ids"])) {
  101. $ids = $_GET["ids"];
  102. if (!empty($ids)) {
  103. $idArr = explode(",", $ids);
  104. if (count($idArr) > 0) {
  105. Db::table("exam_subclass")->where("id", "in", $idArr)->delete();
  106. }
  107. SysLogs::log("exam_subclass", "D", $ids);
  108. echo "delete_ok";
  109. return;
  110. }
  111. }
  112. echo "fail";
  113. }
  114. }