diff --git a/app/adminapi/controller/works/rcbg/OaPlanController.php b/app/adminapi/controller/works/rcbg/OaPlanController.php new file mode 100644 index 000000000..55caed84f --- /dev/null +++ b/app/adminapi/controller/works/rcbg/OaPlanController.php @@ -0,0 +1,108 @@ +dataLists(new OaPlanLists()); + } + + + /** + * @notes 添加日程安排 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function add() + { + $params = (new OaPlanValidate())->post()->goCheck('add'); + $result = OaPlanLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OaPlanLogic::getError()); + } + + + /** + * @notes 编辑日程安排 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function edit() + { + $params = (new OaPlanValidate())->post()->goCheck('edit'); + $result = OaPlanLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OaPlanLogic::getError()); + } + + + /** + * @notes 删除日程安排 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function delete() + { + $params = (new OaPlanValidate())->post()->goCheck('delete'); + OaPlanLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取日程安排详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function detail() + { + $params = (new OaPlanValidate())->goCheck('detail'); + $result = OaPlanLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/works/rcbg/OaPlanLists.php b/app/adminapi/lists/works/rcbg/OaPlanLists.php new file mode 100644 index 000000000..4794cd257 --- /dev/null +++ b/app/adminapi/lists/works/rcbg/OaPlanLists.php @@ -0,0 +1,79 @@ + ['title', 'type'], + ]; + } + + + /** + * @notes 获取日程安排列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function lists(): array + { + return OaPlan::where($this->searchWhere)->where('admin_id',$this->adminId) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $data['type_text'] = $data->type_text; + $data['remind_type_text'] = $data->remind_type_text; + }) + ->toArray(); + } + + + /** + * @notes 获取日程安排数量 + * @return int + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function count(): int + { + return OaPlan::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/works/rcbg/OaPlanLogic.php b/app/adminapi/logic/works/rcbg/OaPlanLogic.php new file mode 100644 index 000000000..39618bff9 --- /dev/null +++ b/app/adminapi/logic/works/rcbg/OaPlanLogic.php @@ -0,0 +1,168 @@ + $params['title'], + 'type' => $params['type'], + 'start_time' => $start_time, + 'end_time' => $end_time, + 'remind_type' => $params['remind_type'], + 'remind_time' => $remind_time, + 'remark' => $params['remark'] ?? '', + 'admin_id' => $admin_id + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑日程安排 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public static function edit(array $params): bool + { + $start_time = strtotime($params['start_time']); + $end_time = strtotime($params['end_time']); + $remind_time = 0; + if (isset($param['remind_type'])) { + if($param['remind_type']==1){ + $remind_time = $start_time-5*60; + } + if($param['remind_type']==2){ + $remind_time = $start_time-15*60; + } + if($param['remind_type']==3){ + $remind_time = $start_time-30*60; + } + if($param['remind_type']==4){ + $remind_time = $start_time-60*60; + } + if($param['remind_type']==5){ + $remind_time = $start_time-120*60; + } + if($param['remind_type']==6){ + $remind_time = $start_time-1440*60; + } + } + Db::startTrans(); + try { + OaPlan::where('id', $params['id'])->update([ + 'title' => $params['title'], + 'type' => $params['type'], + 'start_time' => $start_time, + 'end_time' => $end_time, + 'remind_type' => $params['remind_type'], + 'remind_time' => $remind_time, + 'remark' => $params['remark'] ?? '' + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除日程安排 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public static function delete(array $params): bool + { + return OaPlan::destroy($params['id']); + } + + + /** + * @notes 获取日程安排详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public static function detail($params): array + { + $data = OaPlan::findOrEmpty($params['id']); + $data['type_text'] = $data->type_text; + $data['remind_type_text'] = $data->remind_type_text; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/works/rcbg/OaPlanValidate.php b/app/adminapi/validate/works/rcbg/OaPlanValidate.php new file mode 100644 index 000000000..0ad3b8d77 --- /dev/null +++ b/app/adminapi/validate/works/rcbg/OaPlanValidate.php @@ -0,0 +1,111 @@ + 'require|checkData', + 'title' => 'require', + 'type' => 'require|integer|in:0,1,2,3,4', + 'start_time' => 'require|dateFormat:Y-m-d H:i', + 'end_time' => 'require|dateFormat:Y-m-d H:i', + 'remind_type' => 'require|integer|in:0,1,2,3,4,5,6', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'title' => '工作安排主题', + 'type' => '日程优先级', + 'start_time' => '开始时间', + 'end_time' => '结束时间', + 'remind_type' => '提醒类型', + ]; + + + /** + * @notes 添加场景 + * @return OaPlanValidate + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function sceneAdd() + { + return $this->only(['title','type','start_time','end_time','remind_type']); + } + + + /** + * @notes 编辑场景 + * @return OaPlanValidate + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function sceneEdit() + { + return $this->only(['id','title','type','start_time','end_time','remind_type']); + } + + + /** + * @notes 删除场景 + * @return OaPlanValidate + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OaPlanValidate + * @author likeadmin + * @date 2024/05/23 11:53 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = OaPlan::field('id')->where('id',$value)->findOrEmpty(); + return $data->isEmpty() ? '数据不存在' : true; + } + +} \ No newline at end of file diff --git a/app/common/model/works/rcbg/OaPlan.php b/app/common/model/works/rcbg/OaPlan.php new file mode 100644 index 000000000..f890a642d --- /dev/null +++ b/app/common/model/works/rcbg/OaPlan.php @@ -0,0 +1,59 @@ +'无优先级',1=>'不重要',2=>'次要',3=>'重要',4=>'紧急']; + return $arr[$data['type']]; + } + + public function getRemindTypeTextAttr($value,$data): string + { + $arr = [0=>'不提醒',1=>'提前5分钟',2=>'提前15分钟',3=>'提前30分钟',4=>'提前1小时',5=>'提前2小时',6=>'提前1天']; + return $arr[$data['remind_type']]; + } +} \ No newline at end of file