123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- namespace app\manage\controller;
- use app\manage\model\ExamClassModel;
- use app\manage\model\InstitutionModel;
- use app\manage\model\TemplateModel;
- use think\Controller;
- use think\Db;
- use think\Session;
- use think\Config;
- use think\Cookie;
- use think\Request;
- use app\common\library\SysLogs;
- use app\common\library\UUIDs;
- /**
- * 模版管理
- */
- class Template extends Base {
- public function index() {
- $examClassList = ExamClassModel::all();
- $institutionLis = InstitutionModel::all();
- $examclaData = Db::table("exam_class")->group("name")->field("name")->select();
-
- return $this->fetch('index', ['examClassList' => $examClassList, 'institutionLis' => $institutionLis ,'examcla' => $examclaData ]);
- }
- public function getDatas() {
- $model = new TemplateModel;
- $param = Request::instance()->param();
- $examcla = isset($param['examcla']) ? $param['examcla'] : false;
- $exam_class_id = isset($param['exam_class_id']) ? $param['exam_class_id'] : false;
- $userid = isset($param['userid']) ? $param['userid'] : false;
- $is_public = isset($param['is_public']) ? $param['is_public'] : false;
-
- $page = isset($param['page']) ? $param['page'] : 1;
- $pageSize = isset($param['rows']) ? $param['rows'] : 10;
- $data = array();
-
- $wheres=array();
- if ($examcla){
- $wheres["templates.exam_class_id"]=$examcla;
- }
- if($userid){
- $wheres["templates.create_user"]=$userid;
- }
- if($is_public){
- $wheres["templates.is_public"]=$is_public;
- }
- //echo json_encode($wheres) . "<br />";
- $data["total"] = $model->queryAllCount( $wheres, $page, $pageSize);
- $data["rows"] = $model->queryAll( $wheres, $page, $pageSize);
- echo json_encode($data);
- }
- public function goEdit() {
- $param = Request::instance()->param();
- $model = new TemplateModel;
- $obj = false;
- if (isset($param['id'])) {
- $id = $param['id'];
- $obj = TemplateModel::get($id);
- }
- if (!$obj) {
- $obj = [
- 'id' => '',
- 'title' => '',
- 'is_public' => '1',
- 'exam_class_id' => '',
- 'impression' => '',
- 'description' => '',
- 'create_user' => '',
- 'parent_id' => ''
- ];
- }
- $examclaData = Db::table("exam_class")->group("name")->field("name")->select();
- return $this->fetch('edit', ['obj' => $obj, 'allExamClass' => $examclaData]);
-
- }
- public function save() {
- $param = Request::instance()->param();
- if (isset($param['id']) && $param['id']) {
- $id = $param['id'];
- //更新
- $template = TemplateModel::get($id);
- if (!$template) {
- return "faile";
- }
- $template->title = $param['title'];
- $template->is_public = $param['is_public'];
- $template->exam_class_id = $param['exam_class_id'];
- $template->impression = $param['impression'];
- $template->description = $param['description'];
- $template->save();
- SysLogs::log("template", "U", json_encode($template));
- } else {
- $user = Session::get("session_manager");
- //修改
- $template = new TemplateModel;
- $template->id = UUIDs::uuid16();
- $template->title = $param['title'];
- $template->is_public = $param['is_public'];
- $template->exam_class_id = $param['exam_class_id'];
- $template->impression = $param['impression'];
- $template->description = $param['description'];
- $template->createdAt = date("Y-m-d H:i:s", time());
- $template->create_user = $user ? $user['id'] : '';
- $template->save();
- SysLogs::log("template", "C", json_encode($template));
- }
- return "success";
- }
- public function del() {
- $param = Request::instance()->param();
- $id = $param['id'];
- $device = TemplateModel::get($id);
- $device->delete();
- SysLogs::log("template", "D", $id);
- return "delete_ok";
- }
- }
|