Template.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\manage\controller;
  3. use app\manage\model\ExamClassModel;
  4. use app\manage\model\InstitutionModel;
  5. use app\manage\model\TemplateModel;
  6. use think\Controller;
  7. use think\Db;
  8. use think\Session;
  9. use think\Config;
  10. use think\Cookie;
  11. use think\Request;
  12. use app\common\library\SysLogs;
  13. use app\common\library\UUIDs;
  14. /**
  15. * 模版管理
  16. */
  17. class Template extends Base {
  18. public function index() {
  19. $examClassList = ExamClassModel::all();
  20. $institutionLis = InstitutionModel::all();
  21. $examclaData = Db::table("exam_class")->group("name")->field("name")->select();
  22. return $this->fetch('index', ['examClassList' => $examClassList, 'institutionLis' => $institutionLis ,'examcla' => $examclaData ]);
  23. }
  24. public function getDatas() {
  25. $model = new TemplateModel;
  26. $param = Request::instance()->param();
  27. $examcla = isset($param['examcla']) ? $param['examcla'] : false;
  28. $exam_class_id = isset($param['exam_class_id']) ? $param['exam_class_id'] : false;
  29. $userid = isset($param['userid']) ? $param['userid'] : false;
  30. $is_public = isset($param['is_public']) ? $param['is_public'] : false;
  31. $page = isset($param['page']) ? $param['page'] : 1;
  32. $pageSize = isset($param['rows']) ? $param['rows'] : 10;
  33. $data = array();
  34. $wheres=array();
  35. if ($examcla){
  36. $wheres["templates.exam_class_id"]=$examcla;
  37. }
  38. if($userid){
  39. $wheres["templates.create_user"]=$userid;
  40. }
  41. if($is_public){
  42. $wheres["templates.is_public"]=$is_public;
  43. }
  44. //echo json_encode($wheres) . "<br />";
  45. $data["total"] = $model->queryAllCount( $wheres, $page, $pageSize);
  46. $data["rows"] = $model->queryAll( $wheres, $page, $pageSize);
  47. echo json_encode($data);
  48. }
  49. public function goEdit() {
  50. $param = Request::instance()->param();
  51. $model = new TemplateModel;
  52. $obj = false;
  53. if (isset($param['id'])) {
  54. $id = $param['id'];
  55. $obj = TemplateModel::get($id);
  56. }
  57. if (!$obj) {
  58. $obj = [
  59. 'id' => '',
  60. 'title' => '',
  61. 'is_public' => '1',
  62. 'exam_class_id' => '',
  63. 'impression' => '',
  64. 'description' => '',
  65. 'create_user' => '',
  66. 'parent_id' => ''
  67. ];
  68. }
  69. $examclaData = Db::table("exam_class")->group("name")->field("name")->select();
  70. return $this->fetch('edit', ['obj' => $obj, 'allExamClass' => $examclaData]);
  71. }
  72. public function save() {
  73. $param = Request::instance()->param();
  74. if (isset($param['id']) && $param['id']) {
  75. $id = $param['id'];
  76. //更新
  77. $template = TemplateModel::get($id);
  78. if (!$template) {
  79. return "faile";
  80. }
  81. $template->title = $param['title'];
  82. $template->is_public = $param['is_public'];
  83. $template->exam_class_id = $param['exam_class_id'];
  84. $template->impression = $param['impression'];
  85. $template->description = $param['description'];
  86. $template->save();
  87. SysLogs::log("template", "U", json_encode($template));
  88. } else {
  89. $user = Session::get("session_manager");
  90. //修改
  91. $template = new TemplateModel;
  92. $template->id = UUIDs::uuid16();
  93. $template->title = $param['title'];
  94. $template->is_public = $param['is_public'];
  95. $template->exam_class_id = $param['exam_class_id'];
  96. $template->impression = $param['impression'];
  97. $template->description = $param['description'];
  98. $template->createdAt = date("Y-m-d H:i:s", time());
  99. $template->create_user = $user ? $user['id'] : '';
  100. $template->save();
  101. SysLogs::log("template", "C", json_encode($template));
  102. }
  103. return "success";
  104. }
  105. public function del() {
  106. $param = Request::instance()->param();
  107. $id = $param['id'];
  108. $device = TemplateModel::get($id);
  109. $device->delete();
  110. SysLogs::log("template", "D", $id);
  111. return "delete_ok";
  112. }
  113. }