From f52132acf070f105994f2afbf6bdea33ee9951df Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Thu, 23 May 2024 15:12:35 +0800 Subject: [PATCH] update --- .../works/rcbg/OaScheduleController.php | 108 ++++++++++++++++ app/adminapi/lists/works/rcbg/OaPlanLists.php | 2 +- .../lists/works/rcbg/OaScheduleLists.php | 80 ++++++++++++ .../logic/works/rcbg/OaScheduleLogic.php | 122 ++++++++++++++++++ .../works/rcbg/OaScheduleValidate.php | 104 +++++++++++++++ app/common/model/works/rcbg/OaSchedule.php | 54 ++++++++ 6 files changed, 469 insertions(+), 1 deletion(-) create mode 100644 app/adminapi/controller/works/rcbg/OaScheduleController.php create mode 100644 app/adminapi/lists/works/rcbg/OaScheduleLists.php create mode 100644 app/adminapi/logic/works/rcbg/OaScheduleLogic.php create mode 100644 app/adminapi/validate/works/rcbg/OaScheduleValidate.php create mode 100644 app/common/model/works/rcbg/OaSchedule.php diff --git a/app/adminapi/controller/works/rcbg/OaScheduleController.php b/app/adminapi/controller/works/rcbg/OaScheduleController.php new file mode 100644 index 000000000..2656ce3fb --- /dev/null +++ b/app/adminapi/controller/works/rcbg/OaScheduleController.php @@ -0,0 +1,108 @@ +dataLists(new OaScheduleLists()); + } + + + /** + * @notes 添加工作记录 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function add() + { + $params = (new OaScheduleValidate())->post()->goCheck('add'); + $result = OaScheduleLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(OaScheduleLogic::getError()); + } + + + /** + * @notes 编辑工作记录 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function edit() + { + $params = (new OaScheduleValidate())->post()->goCheck('edit'); + $result = OaScheduleLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(OaScheduleLogic::getError()); + } + + + /** + * @notes 删除工作记录 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function delete() + { + $params = (new OaScheduleValidate())->post()->goCheck('delete'); + OaScheduleLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取工作记录详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function detail() + { + $params = (new OaScheduleValidate())->goCheck('detail'); + $result = OaScheduleLogic::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 index 4794cd257..d5b8d259d 100644 --- a/app/adminapi/lists/works/rcbg/OaPlanLists.php +++ b/app/adminapi/lists/works/rcbg/OaPlanLists.php @@ -73,7 +73,7 @@ class OaPlanLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return OaPlan::where($this->searchWhere)->count(); + return OaPlan::where($this->searchWhere)->where('admin_id',$this->adminId)->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/works/rcbg/OaScheduleLists.php b/app/adminapi/lists/works/rcbg/OaScheduleLists.php new file mode 100644 index 000000000..80f250032 --- /dev/null +++ b/app/adminapi/lists/works/rcbg/OaScheduleLists.php @@ -0,0 +1,80 @@ + ['labor_type','cid'], + '%like%' => ['title'], + ]; + } + + + /** + * @notes 获取工作记录列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function lists(): array + { + return OaSchedule::where($this->searchWhere)->where('admin_id',$this->adminId) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $data['cid_text'] = $data->cid_text; + $data['labor_type_text'] = $data->labor_type_text; + }) + ->toArray(); + } + + + /** + * @notes 获取工作记录数量 + * @return int + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function count(): int + { + return OaSchedule::where($this->searchWhere)->where('admin_id',$this->adminId)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/works/rcbg/OaScheduleLogic.php b/app/adminapi/logic/works/rcbg/OaScheduleLogic.php new file mode 100644 index 000000000..6f1863489 --- /dev/null +++ b/app/adminapi/logic/works/rcbg/OaScheduleLogic.php @@ -0,0 +1,122 @@ + $params['title'], + 'start_time' => strtotime($params['start_time']), + 'end_time' => strtotime($params['end_time']), + 'labor_time' => (strtotime($params['end_time']) - strtotime($params['start_time'])) / 3600, + 'labor_type' => $params['labor_type'], + 'cid' => $params['cid'], + '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 14:27 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + OaSchedule::where('id', $params['id'])->update([ + 'title' => $params['title'], + 'start_time' => strtotime($params['start_time']), + 'end_time' => strtotime($params['end_time']), + 'labor_time' => (strtotime($params['end_time']) - strtotime($params['start_time'])) / 3600, + 'labor_type' => $params['labor_type'], + 'cid' => $params['cid'], + '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 14:27 + */ + public static function delete(array $params): bool + { + return OaSchedule::destroy($params['id']); + } + + + /** + * @notes 获取工作记录详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public static function detail($params): array + { + $data = OaSchedule::findOrEmpty($params['id']); + $data['cid_text'] = $data->cid_text; + $data['labor_type_text'] = $data->labor_type_text; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/works/rcbg/OaScheduleValidate.php b/app/adminapi/validate/works/rcbg/OaScheduleValidate.php new file mode 100644 index 000000000..81bb93992 --- /dev/null +++ b/app/adminapi/validate/works/rcbg/OaScheduleValidate.php @@ -0,0 +1,104 @@ + 'require', + 'title' => 'require', + 'start_time' => 'require|dateFormat:Y-m-d H:i', + 'end_time' => 'require|dateFormat:Y-m-d H:i', + 'labor_type' => 'require|integer|in:1,2', + 'cid' => 'require|integer|in:0,1,2,3,4,5,6,7', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'title' => '工作内容', + 'start_time' => '开始时间', + 'end_time' => '结束时间', + 'labor_type' => '工作类型', + 'cid' => '工作类别', + ]; + + + /** + * @notes 添加场景 + * @return OaScheduleValidate + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function sceneAdd() + { + return $this->only(['title','start_time','end_time','labor_type','cid','remark']); + } + + + /** + * @notes 编辑场景 + * @return OaScheduleValidate + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function sceneEdit() + { + return $this->only(['id','title','start_time','end_time','labor_type','cid','remark']); + } + + + /** + * @notes 删除场景 + * @return OaScheduleValidate + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return OaScheduleValidate + * @author likeadmin + * @date 2024/05/23 14:27 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/works/rcbg/OaSchedule.php b/app/common/model/works/rcbg/OaSchedule.php new file mode 100644 index 000000000..b19314d44 --- /dev/null +++ b/app/common/model/works/rcbg/OaSchedule.php @@ -0,0 +1,54 @@ +'其他',1=>'方案策划',2=>'撰写文档',3=>'需求调研',4=>'需求沟通',5=>'参加会议',6=>'拜访客户',7=>'接待客户']; + return $arr[$data['cid']]; + } + + public function getLaborTypeTextAttr($value,$data): string + { + $arr = [1=>'案头', 2=>'外勤']; + return !empty($data['labor_type']) ? $arr[$data['labor_type']] : ''; + } + + public function getStartTimeAttr($value): string + { + return !empty($value) ? date('Y-m-d H:i',$value) : ''; + } + + public function getEndTimeAttr($value): string + { + return !empty($value) ? date('Y-m-d H:i',$value) : ''; + } +} \ No newline at end of file