From 73974b9e7c43f1dd9a25e3c4845513426409246e Mon Sep 17 00:00:00 2001 From: Dai Date: Mon, 15 Jul 2024 23:51:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E5=B8=88=E6=8E=92=E8=AF=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/model/TeacherScheduleTime.php | 14 +- .../app/controller/TeacherController.php | 67 +- .../TeacherScheduleTimeController.php | 57 +- .../app/view/teacher-schedule-time/index.html | 757 +++++++++--------- .../schedule_time_setting.html | 3 +- .../view/teacher-schedule-time/update.html | 24 +- .../app/view/teacher/check_schedule.html | 348 ++++++++ plugin/admin/app/view/teacher/index.html | 25 +- 8 files changed, 897 insertions(+), 398 deletions(-) create mode 100644 plugin/admin/app/view/teacher/check_schedule.html diff --git a/app/common/model/TeacherScheduleTime.php b/app/common/model/TeacherScheduleTime.php index f50d68c..f3ba403 100644 --- a/app/common/model/TeacherScheduleTime.php +++ b/app/common/model/TeacherScheduleTime.php @@ -20,17 +20,27 @@ class TeacherScheduleTime extends BaseModel { public function teacher() + { + return $this->hasOne(Teacher::class, 'id', 'teacher_id')->bind([ + 'teacher_account' => 'account', + 'teacher_name', + 'time_zone_name' + ]); + } + + public function teacherAttr() { return $this->hasOne(Teacher::class, 'id', 'teacher_id'); } public function subject() { - return $this->hasOne(Subject::class, 'id', 'subject_id')->bind(['subject_name','english_name']); + return $this->hasOne(Subject::class, 'id', 'subject_id')->bind(['subject_name', 'english_name']); } + public function subjectArr() { return $this->hasOne(Subject::class, 'id', 'subject_id'); } - + } diff --git a/plugin/admin/app/controller/TeacherController.php b/plugin/admin/app/controller/TeacherController.php index 558296e..e000db9 100644 --- a/plugin/admin/app/controller/TeacherController.php +++ b/plugin/admin/app/controller/TeacherController.php @@ -2,6 +2,7 @@ namespace plugin\admin\app\controller; +use app\common\model\TeacherScheduleTime; use app\constant\ResponseCode; use support\Request; use support\Response; @@ -147,6 +148,70 @@ class TeacherController extends Crud return view('teacher/update'); } + /** + * @desc 查看教师日程安排 + * @param Request $request + * @return Response + */ + public function check_schedule(Request $request) + { + + $data = $request->get(); + + return view('teacher/check_schedule', ['teacher_id' => $data['id']]); + } + + + /** + * @desc 获取教师课程安排统计 + * @param Request $request + * @return Response + */ + public function getTeacherScheduleMonth(Request $request) + { + try { + $data = $request->get(); + $schedule_time = TeacherScheduleTime::where(['teacher_id' => $data['teacher_id']]) + ->field(' + teacher_id, + month, + COUNT(id) AS total_courses, + SUM(hour) AS total_hours, + SUM(CASE WHEN subject_id > 0 THEN 1 ELSE 0 END) AS has_subject, + SUM(CASE WHEN subject_id = 0 THEN 1 ELSE 0 END) AS has_no_subject, + SUM(CASE WHEN subject_id = 0 THEN hour ELSE 0 END) AS total_nonscheduled_hours, + SUM(CASE WHEN subject_id != 0 THEN hour ELSE 0 END) AS total_scheduled_hours, + SUM(CASE WHEN subject_id != 0 AND is_publish = 1 THEN hour ELSE 0 END) AS total_published_scheduled_hours, + SUM(CASE WHEN subject_id != 0 AND is_publish = 0 THEN hour ELSE 0 END) AS total_unpublished_scheduled_hours, + + SUM(CASE WHEN is_publish = 1 THEN 1 ELSE 0 END) AS published_courses, + SUM(CASE WHEN is_publish = 0 THEN 1 ELSE 0 END) AS unpublished_courses + ') + ->group('month') + ->with(['teacher']); + + $limit = (int)$request->get('limit', 10); + $limit = $limit <= 0 ? 10 : $limit; + $page = (int)$request->get('page'); + $page = $page > 0 ? $page : 1; + + $total = $schedule_time->count(); + $list = $schedule_time->page($page, $limit)->select(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => $list, + 'count' => $total, + 'msg' => 'ok' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } + } + /** * @desc 重置密码 * @param Request $request @@ -165,7 +230,7 @@ class TeacherController extends Crud 'salt' => $salt, 'password' => $password ]); - if(!$res){ + if (!$res) { throw new Exception('重置失败'); } diff --git a/plugin/admin/app/controller/TeacherScheduleTimeController.php b/plugin/admin/app/controller/TeacherScheduleTimeController.php index cdebe65..79c2b89 100644 --- a/plugin/admin/app/controller/TeacherScheduleTimeController.php +++ b/plugin/admin/app/controller/TeacherScheduleTimeController.php @@ -10,6 +10,7 @@ use support\Response; use plugin\admin\app\model\TeacherScheduleTime; use plugin\admin\app\controller\Crud; use support\exception\BusinessException; +use think\Exception; /** * 教师空闲时间 @@ -37,7 +38,53 @@ class TeacherScheduleTimeController extends Crud */ public function index(): Response { - return view('teacher-schedule-time/index'); + //获取所有老师 + $teacher = Teacher::order('id asc')->field('id,teacher_name,account')->select()->toArray(); + //所有课程 + $subject = Subject::order('sort desc,id asc')->field('id,subject_name,english_name')->select()->toArray(); + return view('teacher-schedule-time/index', ['teacher' => $teacher, 'subject' => $subject]); + } + + public function select(Request $request): Response + { + try { + $data = $request->get(); + $teacherSchedule = \app\common\model\TeacherScheduleTime::order('id asc'); + if (isset($data['teacher_id']) && $data['teacher_id']) { + $teacherSchedule->where(['teacher_id' => $data['teacher_id']]); + } + if (isset($data['date']) && $data['date']) { + $teacherSchedule->where(['date' => $data['date']]); + } + if (isset($data['month']) && $data['month']) { + $teacherSchedule->where(['month' => $data['month']]); + } + if (isset($data['subject_id']) && $data['subject_id']) { + $teacherSchedule->where(['subject_id' => $data['subject_id']]); + } + if (isset($data['is_publish']) && $data['is_publish'] !== '') { + $teacherSchedule->where(['is_publish' => $data['is_publish']]); + } + $limit = (int)$request->get('limit', 10); + $limit = $limit <= 0 ? 10 : $limit; + $page = (int)$request->get('page'); + $page = $page > 0 ? $page : 1; + + $total = $teacherSchedule->count(); + $list = $teacherSchedule->with(['subject', 'teacher'])->page($page, $limit)->select(); + + return json([ + 'code' => ResponseCode::WEB_API_SUCCESS, + 'data' => $list, + 'count' => $total, + 'msg' => 'success' + ]); + } catch (Exception $e) { + return json([ + 'code' => ResponseCode::WEB_API_FAIL, + 'msg' => $e->getMessage() + ]); + } } @@ -85,7 +132,7 @@ class TeacherScheduleTimeController extends Crud { if ($request->method() === 'POST') { - if($request->post('is_publish')){ + if ($request->post('is_publish')) { $request->post('is_publish', 0); } // parent::update($request); @@ -120,10 +167,10 @@ class TeacherScheduleTimeController extends Crud foreach ($list as $item) { $time_period = explode('-', $item['time']); if ($item['subject_id']) { - $title = $item['time'] . ' - ' . $item['subject_name'] . '/' .$item['english_name']; - if($item['is_publish'] == 0){ + $title = $item['time'] . ' - ' . $item['subject_name'] . '/' . $item['english_name']; + if ($item['is_publish'] == 0) { $color = 'orange'; - }else{ + } else { $color = 'green'; } } else { diff --git a/plugin/admin/app/view/teacher-schedule-time/index.html b/plugin/admin/app/view/teacher-schedule-time/index.html index cb01338..d80ec2c 100644 --- a/plugin/admin/app/view/teacher-schedule-time/index.html +++ b/plugin/admin/app/view/teacher-schedule-time/index.html @@ -1,398 +1,419 @@ - - - - 浏览页面 - - - - - - -
-
-
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
+ + + 浏览页面 + + + + -
- -
- -
-
+ +
+
+ -
- -
- -
-
- -
- -
- -
-
- -
- -
-
-
-
- -
- - - -
-
- 展开 - 收起 -
- +
+ +
+ +
-
- - -
-
-
+ +
+ +
+ +
-
- - + + + + + + - - + + + + + + - - - - - - - // 表格顶部工具栏事件 - table.on("toolbar(data-table)", function(obj) { - if (obj.event === "add") { - add(); - } else if (obj.event === "refresh") { - refreshTable(); - } else if (obj.event === "batchRemove") { - batchRemove(obj); - } - }); + + - // 表格顶部搜索事件 - form.on("submit(table-query)", function(data) { - table.reload("data-table", { - page: { - curr: 1 - }, - where: data.field - }) - return false; - }); - - // 表格顶部搜索重置事件 - form.on("submit(table-reset)", function(data) { - table.reload("data-table", { - where: [] - }) - }); - - // 字段允许为空 - form.verify({ - phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"], - email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"], - url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"], - number: [/(^$)|^\d+$/,'只能填写数字'], - date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"], - identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"] - }); + + + + - // 表格排序事件 - table.on("sort(data-table)", function(obj){ - table.reload("data-table", { - initSort: obj, - scrollPos: "fixed", - where: { - field: obj.field, - order: obj.type - } - }); - }); + - + // 表格顶部搜索重置事件 + form.on("submit(table-reset)", function (data) { + table.reload("data-table", { + where: [] + }) + }); + + // 字段允许为空 + form.verify({ + phone: [/(^$)|^1\d{10}$/, "请输入正确的手机号"], + email: [/(^$)|^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/, "邮箱格式不正确"], + url: [/(^$)|(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/, "链接格式不正确"], + number: [/(^$)|^\d+$/, '只能填写数字'], + date: [/(^$)|^(\d{4})[-\/](\d{1}|0\d{1}|1[0-2])([-\/](\d{1}|0\d{1}|[1-2][0-9]|3[0-1]))*$/, "日期格式不正确"], + identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"] + }); + + // 表格排序事件 + table.on("sort(data-table)", function (obj) { + table.reload("data-table", { + initSort: obj, + scrollPos: "fixed", + where: { + field: obj.field, + order: obj.type + } + }); + }); + + // 表格新增数据 + let add = function () { + layer.open({ + type: 2, + title: "新增", + shade: 0.1, + maxmin: true, + area: [common.isModile() ? "100%" : "500px", common.isModile() ? "100%" : "450px"], + content: INSERT_URL + }); + } + + // 表格编辑数据 + let edit = function (obj) { + let value = obj.data[PRIMARY_KEY]; + layer.open({ + type: 2, + title: "修改", + shade: 0.1, + maxmin: true, + area: [common.isModile() ? "100%" : "1080px", common.isModile() ? "100%" : "750px"], + content: UPDATE_URL + "?" + PRIMARY_KEY + "=" + value + }); + } + + // 删除一行 + let remove = function (obj) { + return doRemove(obj.data[PRIMARY_KEY]); + } + + // 删除多行 + let batchRemove = function (obj) { + let checkIds = common.checkField(obj, PRIMARY_KEY); + if (checkIds === "") { + layui.popup.warning("未选中数据"); + return false; + } + doRemove(checkIds.split(",")); + } + + // 执行删除 + let doRemove = function (ids) { + let data = {}; + data[PRIMARY_KEY] = ids; + layer.confirm("确定删除?", { + icon: 3, + title: "提示" + }, function (index) { + layer.close(index); + let loading = layer.load(); + $.ajax({ + url: DELETE_API, + data: data, + dataType: "json", + type: "post", + success: function (res) { + layer.close(loading); + if (res.code) { + return layui.popup.failure(res.msg); + } + return layui.popup.success("操作成功", refreshTable); + } + }) + }); + } + + // 刷新表格数据 + window.refreshTable = function () { + table.reloadData("data-table", { + scrollPos: "fixed", + done: function (res, curr) { + if (curr > 1 && res.data && !res.data.length) { + curr = curr - 1; + table.reloadData("data-table", { + page: { + curr: curr + }, + }) + } + } + }); + } + }) + + + diff --git a/plugin/admin/app/view/teacher-schedule-time/schedule_time_setting.html b/plugin/admin/app/view/teacher-schedule-time/schedule_time_setting.html index 1ba65dd..11eb076 100644 --- a/plugin/admin/app/view/teacher-schedule-time/schedule_time_setting.html +++ b/plugin/admin/app/view/teacher-schedule-time/schedule_time_setting.html @@ -18,7 +18,7 @@
- +
@@ -183,6 +183,7 @@ } return layui.popup.success("操作成功", function () { // parent.refreshTable(); + parent.refreshTable(); parent.location.reload(); parent.layer.close(parent.layer.getFrameIndex(window.name)); }); diff --git a/plugin/admin/app/view/teacher-schedule-time/update.html b/plugin/admin/app/view/teacher-schedule-time/update.html index e66d299..855b6a9 100644 --- a/plugin/admin/app/view/teacher-schedule-time/update.html +++ b/plugin/admin/app/view/teacher-schedule-time/update.html @@ -291,26 +291,16 @@ identity: [/(^$)|(^\d{15}$)|(^\d{17}(x|X|\d)$)/, "请输入正确的身份证号"] }); layui.form.on("submit(save)", function (data) { - data.field[PRIMARY_KEY] = layui.url().search[PRIMARY_KEY]; - layui.$.ajax({ - url: UPDATE_API, - type: "POST", - dateType: "json", - data: data.field, - success: function (res) { - if (res.code) { - return layui.popup.failure(res.msg); - } - return layui.popup.success("操作成功", function () { - parent.refreshTable(); - parent.layer.close(parent.layer.getFrameIndex(window.name)); - }); - } - }); - return false; + parent.refreshTable(); + parent.layer.close(parent.layer.getFrameIndex(window.name)); + // return false; }); }); + // 刷新表格数据 + window.refreshTable = function() { + parent.refreshTable(); + } diff --git a/plugin/admin/app/view/teacher/check_schedule.html b/plugin/admin/app/view/teacher/check_schedule.html new file mode 100644 index 0000000..c98dfeb --- /dev/null +++ b/plugin/admin/app/view/teacher/check_schedule.html @@ -0,0 +1,348 @@ + + + + + + 浏览页面 + + + + + + +
+
+
+
+
+ + + + + + + + + + + + + + + diff --git a/plugin/admin/app/view/teacher/index.html b/plugin/admin/app/view/teacher/index.html index 67848b5..0936db4 100644 --- a/plugin/admin/app/view/teacher/index.html +++ b/plugin/admin/app/view/teacher/index.html @@ -80,9 +80,10 @@ @@ -159,7 +160,7 @@ toolbar: "#table-bar", align: "center", fixed: "right", - width: 180, + width: 265, } ]; @@ -190,6 +191,8 @@ remove(obj); } else if (obj.event === "edit") { edit(obj); + } else if (obj.event === "check_schedule") { + check_schedule(obj); } else if (obj.event === "rest_password") { rest_password(obj); } @@ -271,6 +274,20 @@ }); } // 表格编辑数据 + let check_schedule = function(obj) { + let value = obj.data[PRIMARY_KEY]; + let index = layer.open({ + type: 2, + title: "修改", + shade: 0.1, + maxmin: true, + area: [common.isModile()?"100%":"950px", common.isModile()?"100%":"750px"], + content: '/app/admin/teacher/check_schedule?id=' + value + }); + + layer.full(index); + } + // 表格编辑数据 let rest_password = function(obj) { console.log() let data = {};