From 67ef10773393d76aefaaf5530b551d404c165e4f Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 14 Dec 2023 11:43:21 +0800 Subject: [PATCH 1/2] update --- app/adminapi/validate/project/ProjectLogsValidate.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/adminapi/validate/project/ProjectLogsValidate.php b/app/adminapi/validate/project/ProjectLogsValidate.php index 460be7328..2b72de671 100644 --- a/app/adminapi/validate/project/ProjectLogsValidate.php +++ b/app/adminapi/validate/project/ProjectLogsValidate.php @@ -38,7 +38,7 @@ class ProjectLogsValidate extends BaseValidate 'project_id' => 'require|checkProject', 'theme' => 'require', 'date' => 'require|date', - 'follow_type' => 'checkFollowType', + 'follow_type' => 'require|checkFollowType', 'next_follow_up_date' => 'date|checkNextFollowUpDate', ]; @@ -48,6 +48,7 @@ class ProjectLogsValidate extends BaseValidate 'theme.require' => '主题不能为空', 'date.require' => '日期不能为空', 'date.date' => '日期格式不正确', + 'follow_type.require' => '请选择类型', 'next_follow_up_date.date' => '下次跟进时间格式不正确', ]; From 81961a30288164758ba0b57dbea8ab4980863644 Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 14 Dec 2023 14:14:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E8=B4=B9=E7=94=A8=E6=A8=A1=E6=9D=BF=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectCostTempSetController.php | 108 ++++++++++++++++ .../lists/project/ProjectCostTempSetLists.php | 95 ++++++++++++++ .../logic/project/ProjectCostTempSetLogic.php | 120 ++++++++++++++++++ .../project/ProjectCostTempSetValidate.php | 120 ++++++++++++++++++ .../model/project/ProjectCostTempSet.php | 34 +++++ 5 files changed, 477 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectCostTempSetController.php create mode 100644 app/adminapi/lists/project/ProjectCostTempSetLists.php create mode 100644 app/adminapi/logic/project/ProjectCostTempSetLogic.php create mode 100644 app/adminapi/validate/project/ProjectCostTempSetValidate.php create mode 100644 app/common/model/project/ProjectCostTempSet.php diff --git a/app/adminapi/controller/project/ProjectCostTempSetController.php b/app/adminapi/controller/project/ProjectCostTempSetController.php new file mode 100644 index 000000000..e5190361d --- /dev/null +++ b/app/adminapi/controller/project/ProjectCostTempSetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectCostTempSetLists()); + } + + + /** + * @notes 添加项目费用模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function add() + { + $params = (new ProjectCostTempSetValidate())->post()->goCheck('add'); + $result = ProjectCostTempSetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectCostTempSetLogic::getError()); + } + + + /** + * @notes 编辑项目费用模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function edit() + { + $params = (new ProjectCostTempSetValidate())->post()->goCheck('edit'); + $result = ProjectCostTempSetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectCostTempSetLogic::getError()); + } + + + /** + * @notes 删除项目费用模板 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function delete() + { + $params = (new ProjectCostTempSetValidate())->post()->goCheck('delete'); + ProjectCostTempSetLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取项目费用模板详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function detail() + { + $params = (new ProjectCostTempSetValidate())->goCheck('detail'); + $result = ProjectCostTempSetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectCostTempSetLists.php b/app/adminapi/lists/project/ProjectCostTempSetLists.php new file mode 100644 index 000000000..5f3f69029 --- /dev/null +++ b/app/adminapi/lists/project/ProjectCostTempSetLists.php @@ -0,0 +1,95 @@ + ['subject_code', 'first_level_subject', 'second_level_subject', 'third_level_subject', 'unit'], + '=' => ['is_travel'], + ]; + } + + + /** + * @notes 获取项目费用模板列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function lists(): array + { + $params = $this->request->param(); + $where = []; + if(isset($params['project_type_name']) && $params['project_type_name'] != ''){ + $projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id'); + $where[] = ['project_type_id','in',$projectTypeIds]; + } + return ProjectCostTempSet::where($this->searchWhere)->where($where) + ->field(['id', 'project_type_id', 'subject_code', 'first_level_subject', 'second_level_subject', 'third_level_subject', 'unit', 'is_travel']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $projectType = ProjectTypeSet::field('name')->where('id',$item['project_type_id'])->findOrEmpty(); + $item['project_type_name'] = $projectType['name']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取项目费用模板数量 + * @return int + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function count(): int + { + $params = $this->request->param(); + $where = []; + if(isset($params['project_type_name']) && $params['project_type_name'] != ''){ + $projectTypeIds = ProjectTypeSet::where('name','like','%'.$params['project_type_name'].'%')->column('id'); + $where[] = ['project_type_id','in',$projectTypeIds]; + } + return ProjectCostTempSet::where($this->searchWhere)->where($where)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectCostTempSetLogic.php b/app/adminapi/logic/project/ProjectCostTempSetLogic.php new file mode 100644 index 000000000..c09e2dbc0 --- /dev/null +++ b/app/adminapi/logic/project/ProjectCostTempSetLogic.php @@ -0,0 +1,120 @@ + $params['project_type_id'], + 'subject_code' => $params['subject_code'], + 'first_level_subject' => $params['first_level_subject'], + 'second_level_subject' => $params['second_level_subject'], + 'third_level_subject' => $params['third_level_subject'], + 'unit' => $params['unit'], + 'is_travel' => $params['is_travel'], + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑项目费用模板 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectCostTempSet::where('id', $params['id'])->update([ + 'project_type_id' => $params['project_type_id'], + 'subject_code' => $params['subject_code'], + 'first_level_subject' => $params['first_level_subject'], + 'second_level_subject' => $params['second_level_subject'], + 'third_level_subject' => $params['third_level_subject'], + 'unit' => $params['unit'], + 'is_travel' => $params['is_travel'], + ]); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除项目费用模板 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public static function delete(array $params): bool + { + return ProjectCostTempSet::destroy($params['id']); + } + + + /** + * @notes 获取项目费用模板详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public static function detail($params): array + { + $data = ProjectCostTempSet::field('id,project_type_id,subject_code,first_level_subject,second_level_subject,third_level_subject,unit,is_travel')->findOrEmpty($params['id'])->toArray(); + $projectType = ProjectTypeSet::field('name')->where('id',$data['project_type_id'])->findOrEmpty(); + $data['project_type_name'] = $projectType['name']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectCostTempSetValidate.php b/app/adminapi/validate/project/ProjectCostTempSetValidate.php new file mode 100644 index 000000000..439fce0e8 --- /dev/null +++ b/app/adminapi/validate/project/ProjectCostTempSetValidate.php @@ -0,0 +1,120 @@ + 'require', + 'project_type_id' => 'require|checkProjectType', + 'subject_code' => 'require|unique:'.ProjectCostTempSet::class, + 'first_level_subject' => 'require', + 'is_travel' => 'require|integer|in:1,2', + ]; + + protected $message = [ + 'id.require' => '缺少你要参数', + 'project_type_id.require' => '请选择项目类型', + 'subject_code.require' => '请填写科目编码', + 'subject_code.unique' => '科目编码不能重复', + 'first_level_subject' => '请填写一级科目', + 'is_travel.require' => '请选择是否是差旅科目', + 'is_travel.integer' => '差旅科目数据格式错误', + 'is_travel.in' => '差旅科目数据值错误' + ]; + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_type_id' => '项目类型id', + 'subject_code' => '科目编码', + 'first_level_subject' => '一级科目', + 'is_travel' => '是否是差旅科目 1-是 2-否', + ]; + + /** + * @notes 添加场景 + * @return ProjectCostTempSetValidate + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectCostTempSetValidate + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectCostTempSetValidate + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectCostTempSetValidate + * @author likeadmin + * @date 2023/12/14 11:54 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkProjectType($value): bool|string + { + $data = ProjectTypeSet::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目类型不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectCostTempSet.php b/app/common/model/project/ProjectCostTempSet.php new file mode 100644 index 000000000..28fe954d8 --- /dev/null +++ b/app/common/model/project/ProjectCostTempSet.php @@ -0,0 +1,34 @@ +