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 @@
-
- -
- -
-