123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace app\manage\controller;
- 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 Examclass extends Base {
- public function index() {
- return $this->fetch("index");
- }
- public function datas() {
- $request = Request::instance();
- $params = $request->param();
- $wheres = array();
- $insid = isset($params["insid"]) ? $params["insid"] : null;
- if ($insid != null && $insid != "") {
- $wheres["institution_id"] = $insid;
- }
- $insMap = array();
- $insArr = Db::table("institution")->field("id, name")->select();
- if (!empty($insArr)) {
- foreach ($insArr as $key => $val) {
- $insMap[$val["id"]] = $val["name"];
- }
- }
- $page = empty($params["page"]) ? 1 : $params["page"];
- $pagesize = empty($params["rows"]) ? 1 : $params["rows"];
- if (empty($page) || $page < 1) {
- $page = 1;
- }
- if (empty($pagesize) || $pagesize < 1) {
- $pagesize = 30;
- }
- $info = DB::table('exam_class')->where($wheres)->page($page, $pagesize)->select();
- foreach ($info as $k => $val) {
- if (isset($insMap[$val["institution_id"]])) {
- $info[$k]["institution_name"] = $insMap[$val["institution_id"]];
- } else {
- $info[$k]["institution_name"] = $val["institution_id"];
- }
- }
- $num = DB::table('exam_class')->where($wheres)->count();
- $data = array();
- $data['total'] = $num;
- $data['rows'] = $info;
- echo json_encode($data);
- }
- /**
- * 编辑窗口
- * @return type
- */
- public function edit() {
- $rs = self::itsCombChild("");
- $this->assign("insJson", json_encode($rs));
- if (isset($_GET["id"])) {
- $id = $_GET["id"];
- if ($id != null) {
- $exam_class = Db::table("exam_class")->where("id", $id)->find();
- $this->assign("exam_class", $exam_class);
- }
- }
- return $this->fetch('edit');
- }
- public function save() {
- if (empty($_GET['id'])) {
- unset($_GET['id']);
- $id = UUIDs::uuid16();
- $info = $_GET;
- $info['id'] = $id;
- $a = DB::table('exam_class')->insert($info);
- SysLogs::log("exam_class", "C", json_encode($info));
- return 'insert_ok;' . $id;
- } else {
- $a = DB::table('exam_class')->where('id', $_GET['id'])->update($_GET);
- SysLogs::log("exam_class", "C", 'id=' . $_GET['id'] . " --> " . json_encode($_GET));
- return 'update_ok';
- }
- }
- /**
- * 软删除记录
- */
- public function delete() {
- if (isset($_GET["ids"])) {
- $ids = $_GET["ids"];
- if (!empty($ids)) {
- $idArr = explode(",", $ids);
- if (count($idArr) > 0) {
- Db::table("exam_class")->where("id", "in", $idArr)->delete();
- }
- echo "delete_ok";
- SysLogs::log("exam_class", "D", $ids);
- return;
- }
- }
- echo "fail";
- }
- public function itsCombChild($pid) {
- $rs = Db::table("institution")->where("parent_institution", $pid)->select();
- foreach ($rs as $key => $val) {
- $rs[$key]["text"] = $val["name"];
- $rs[$key]["children"] = self::itsCombChild($val["id"]);
- }
- return $rs;
- }
- }
|