123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\manage\controller;
- use app\manage\model\DeviceModel;
- use app\manage\model\ExamClassModel;
- use app\manage\model\InstitutionModel;
- 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 Device extends Base {
- public function index() {
- $allInstitutions = InstitutionModel::all();
- return $this->fetch("index", ['institutions' => $allInstitutions]);
- }
- //查询全部
- public function getAll() {
- $param = Request::instance()->param();
- $institution = $param['institution'];
- $model = new DeviceModel;
- $list = $model->queryAll($institution);
- echo json_encode($list);
- }
- public function goEdit() {
- $param = Request::instance()->param();
- $model = new DeviceModel;
- $obj = false;
- if (isset($param['id'])) {
- $id = $param['id'];
- $obj = $model->queryOne($id);
- }
- if (!$obj) {
- $obj = [
- 'id' => '',
- 'name' => '',
- 'exam_class_id' => '',
- 'insId' => ''
- ];
- }
- $ecMode = new ExamClassModel;
- $allExamClass = $ecMode->queryAll();
- return $this->fetch('edit', ['obj' => $obj, 'allExamClass' => $allExamClass]);
- }
- //保存修改
- public function save() {
- $param = Request::instance()->param();
- if (isset($param['id']) && $param['id']) {
- $id = $param['id'];
- //更新
- $device = DeviceModel::get($id);
- $deviceOld = clone $device;
- if (!$device) {
- return "faile";
- }
- $device->name = $param['name'];
- $device->exam_class_id = $param['exam_class_id'];
- $device->save();
- SysLogs::log("device", "U", json_encode($deviceOld) . " --> " . json_encode($param));
- } else {
- //修改
- $device = new DeviceModel;
- $device->id = UUIDs::uuid16();
- $device->name = $param['name'];
- $device->exam_class_id = $param['exam_class_id'];
- $device->save();
- SysLogs::log("device", "C", json_encode($device));
- }
- return "success";
- }
- public function del() {
- $param = Request::instance()->param();
- $id = $param['id'];
- $device = DeviceModel::get($id);
- $device->delete();
- SysLogs::log("device", "D", $id );
- return "delete_ok";
- }
- }
|