Device.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\manage\controller;
  3. use app\manage\model\DeviceModel;
  4. use app\manage\model\ExamClassModel;
  5. use app\manage\model\InstitutionModel;
  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 Device extends Base {
  18. public function index() {
  19. $allInstitutions = InstitutionModel::all();
  20. return $this->fetch("index", ['institutions' => $allInstitutions]);
  21. }
  22. //查询全部
  23. public function getAll() {
  24. $param = Request::instance()->param();
  25. $institution = $param['institution'];
  26. $model = new DeviceModel;
  27. $list = $model->queryAll($institution);
  28. echo json_encode($list);
  29. }
  30. public function goEdit() {
  31. $param = Request::instance()->param();
  32. $model = new DeviceModel;
  33. $obj = false;
  34. if (isset($param['id'])) {
  35. $id = $param['id'];
  36. $obj = $model->queryOne($id);
  37. }
  38. if (!$obj) {
  39. $obj = [
  40. 'id' => '',
  41. 'name' => '',
  42. 'exam_class_id' => '',
  43. 'insId' => ''
  44. ];
  45. }
  46. $ecMode = new ExamClassModel;
  47. $allExamClass = $ecMode->queryAll();
  48. return $this->fetch('edit', ['obj' => $obj, 'allExamClass' => $allExamClass]);
  49. }
  50. //保存修改
  51. public function save() {
  52. $param = Request::instance()->param();
  53. if (isset($param['id']) && $param['id']) {
  54. $id = $param['id'];
  55. //更新
  56. $device = DeviceModel::get($id);
  57. $deviceOld = clone $device;
  58. if (!$device) {
  59. return "faile";
  60. }
  61. $device->name = $param['name'];
  62. $device->exam_class_id = $param['exam_class_id'];
  63. $device->save();
  64. SysLogs::log("device", "U", json_encode($deviceOld) . " --> " . json_encode($param));
  65. } else {
  66. //修改
  67. $device = new DeviceModel;
  68. $device->id = UUIDs::uuid16();
  69. $device->name = $param['name'];
  70. $device->exam_class_id = $param['exam_class_id'];
  71. $device->save();
  72. SysLogs::log("device", "C", json_encode($device));
  73. }
  74. return "success";
  75. }
  76. public function del() {
  77. $param = Request::instance()->param();
  78. $id = $param['id'];
  79. $device = DeviceModel::get($id);
  80. $device->delete();
  81. SysLogs::log("device", "D", $id );
  82. return "delete_ok";
  83. }
  84. }