Examproject.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 ExamProject 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_project.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_project','id, name, exam_class_id, status ')
  43. ->view("exam_class", "name as claName ", "exam_class.id=exam_project.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_project','id, name, exam_class_id, status ')
  51. ->view("exam_class", "name as claName ", "exam_class.id=exam_project.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_project = Db::table("exam_project")->where("id", $id)->select();
  68. if (count($exam_project) > 0) {
  69. $this->assign("exam_project", $exam_project[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. $this->assign("class", $class);
  78. return $this->fetch('edit');
  79. }
  80. public function save() {
  81. if (empty($_GET['id'])) {
  82. unset($_GET['id']);
  83. $id = UUIDs::uuid16();
  84. $info = $_GET;
  85. $info['id'] = $id;
  86. $a = DB::table('exam_project')->insert($info);
  87. SysLogs::log("exam_project", "C", json_encode($info));
  88. return 'insert_ok;' . $id;
  89. } else {
  90. $a = DB::table('exam_project')->where('id', $_GET['id'])->update($_GET);
  91. SysLogs::log("exam_project", "U", "id = " . $_GET['id'] . " --> " . json_encode($_GET));
  92. return 'update_ok';
  93. }
  94. }
  95. /**
  96. * 软删除记录
  97. */
  98. public function delete() {
  99. if (isset($_GET["ids"])) {
  100. $ids = $_GET["ids"];
  101. if (!empty($ids)) {
  102. $idArr = explode(",", $ids);
  103. if (count($idArr) > 0) {
  104. Db::table("exam_project")->where("id", "in", $idArr)->delete();
  105. }
  106. echo "delete_ok";
  107. SysLogs::log("exam_project", "D", $ids);
  108. return;
  109. }
  110. }
  111. echo "fail";
  112. }
  113. }