From 962177d12ebe01b143382e3334f914a1ff0c8419 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Thu, 26 Jun 2025 14:53:24 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feature:=20=E6=B7=BB=E5=8A=A0=E6=8E=92?= =?UTF-8?q?=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/oa/CustomSchedule.php | 52 +++++++++++++------ .../admin/view/oa/custom_schedule/add.html | 18 ++++--- .../admin/view/oa/custom_schedule/index.html | 6 +++ .../assets/js/backend/oa/custom_schedule.js | 2 +- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/application/admin/controller/oa/CustomSchedule.php b/application/admin/controller/oa/CustomSchedule.php index aa90920..ae55e89 100644 --- a/application/admin/controller/oa/CustomSchedule.php +++ b/application/admin/controller/oa/CustomSchedule.php @@ -152,35 +152,53 @@ class CustomSchedule extends Backend if (empty($params)) { $this->error(__('Parameter %s can not be empty', '')); } - $params = $this->preExcludeFields($params); - if ($this->dataLimit && $this->dataLimitFieldAutoFill) { - $params[$this->dataLimitField] = $this->auth->id; - } - $result = false; Db::startTrans(); try { - //是否采用模型验证 - if ($this->modelValidate) { - $name = str_replace("\\model\\", "\\validate\\", get_class($this->model)); - $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate; - $this->model->validateFailException()->validate($validate); + + $dates = []; + + if ($params['period'] == 'month') { + $daysInMonth = date('t'); // 本月天数 + $month = date('Y-m'); // 当前年月 + for ($i = 1; $i <= $daysInMonth; $i++) { + $dates[] = $month . '-' . str_pad($i, 2, '0', STR_PAD_LEFT); + } + } elseif ($params['period'] == 'week') { + $start = strtotime('monday this week'); + for ($i = 0; $i < 7; $i++) { + $dates[] = date('Y-m-d', strtotime("+$i day", $start)); + } + } else { + $dates = [date('Y-m-d')]; + } + $type = $params['type']; + $execAdminIds = explode(',', $params['exec_admin_id']); + + $schedules = []; + foreach ($execAdminIds as $execAdminId) { + foreach ($dates as $date) { + $schedules[] = [ + 'exec_admin_id' => $execAdminId, + 'date' => $date, + 'type' => $type, + ]; + } } + Db::name('schedule') + ->whereIn('exec_admin_id', $execAdminIds) + ->whereIn('date', $dates) + ->delete(); - $params['create_time'] = date('Y-m-d H:i:s'); - $params['update_time'] = date('Y-m-d H:i:s'); + Db::name('schedule') + ->insertAll($schedules); - - $result = $this->model->allowField(true)->save($params); Db::commit(); } catch (ValidateException|PDOException|Exception $e) { Db::rollback(); $this->error($e->getMessage()); } - if ($result === false) { - $this->error(__('No rows were inserted')); - } $this->success(); } diff --git a/application/admin/view/oa/custom_schedule/add.html b/application/admin/view/oa/custom_schedule/add.html index 2f2fe7d..f104303 100644 --- a/application/admin/view/oa/custom_schedule/add.html +++ b/application/admin/view/oa/custom_schedule/add.html @@ -3,7 +3,17 @@
- + +
+
+
+ +
+
@@ -18,12 +28,6 @@
-
- -
- -
-