From 2cf4b0c8565e9358b57f2cd3e8e54891cef77350 Mon Sep 17 00:00:00 2001 From: weiz Date: Thu, 14 Dec 2023 17:06:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E9=A2=84?= =?UTF-8?q?=E8=AD=A6=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectAlarmSetController.php | 108 +++++++++++++++ .../lists/project/ProjectAlarmSetLists.php | 93 +++++++++++++ .../logic/project/ProjectAlarmSetLogic.php | 117 ++++++++++++++++ .../project/ProjectAlarmSetValidate.php | 130 ++++++++++++++++++ app/common/model/project/ProjectAlarmSet.php | 34 +++++ 5 files changed, 482 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectAlarmSetController.php create mode 100644 app/adminapi/lists/project/ProjectAlarmSetLists.php create mode 100644 app/adminapi/logic/project/ProjectAlarmSetLogic.php create mode 100644 app/adminapi/validate/project/ProjectAlarmSetValidate.php create mode 100644 app/common/model/project/ProjectAlarmSet.php diff --git a/app/adminapi/controller/project/ProjectAlarmSetController.php b/app/adminapi/controller/project/ProjectAlarmSetController.php new file mode 100644 index 000000000..762487d7b --- /dev/null +++ b/app/adminapi/controller/project/ProjectAlarmSetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectAlarmSetLists()); + } + + + /** + * @notes 添加项目预警设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function add() + { + $params = (new ProjectAlarmSetValidate())->post()->goCheck('add'); + $result = ProjectAlarmSetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectAlarmSetLogic::getError()); + } + + + /** + * @notes 编辑项目预警设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function edit() + { + $params = (new ProjectAlarmSetValidate())->post()->goCheck('edit'); + $result = ProjectAlarmSetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectAlarmSetLogic::getError()); + } + + + /** + * @notes 删除项目预警设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function delete() + { + $params = (new ProjectAlarmSetValidate())->post()->goCheck('delete'); + ProjectAlarmSetLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取项目预警设置详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function detail() + { + $params = (new ProjectAlarmSetValidate())->goCheck('detail'); + $result = ProjectAlarmSetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectAlarmSetLists.php b/app/adminapi/lists/project/ProjectAlarmSetLists.php new file mode 100644 index 000000000..98b7203a9 --- /dev/null +++ b/app/adminapi/lists/project/ProjectAlarmSetLists.php @@ -0,0 +1,93 @@ +request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + return ProjectAlarmSet::where($this->searchWhere)->where($where) + ->field(['id', 'project_id', 'material_budget_expenditure_ratio', 'labour_budget_expenditure_ratio', 'cost_budget_expenditure_ratio', 'subcontract_budget_expenditure_ratio']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $project = Project::field('name,project_code')->where('id',$item['project_id'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['project_code'] = $project['project_code']; + return $item; + }) + ->toArray(); + } + + + /** + * @notes 获取项目预警设置数量 + * @return int + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function count(): int + { + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + return ProjectAlarmSet::where($this->searchWhere)->where($where)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectAlarmSetLogic.php b/app/adminapi/logic/project/ProjectAlarmSetLogic.php new file mode 100644 index 000000000..1231d032e --- /dev/null +++ b/app/adminapi/logic/project/ProjectAlarmSetLogic.php @@ -0,0 +1,117 @@ + $params['project_id'], + 'material_budget_expenditure_ratio' => $params['material_budget_expenditure_ratio'], + 'labour_budget_expenditure_ratio' => $params['labour_budget_expenditure_ratio'], + 'cost_budget_expenditure_ratio' => $params['cost_budget_expenditure_ratio'], + 'subcontract_budget_expenditure_ratio' => $params['subcontract_budget_expenditure_ratio'], + ]); + 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 16:24 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectAlarmSet::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'material_budget_expenditure_ratio' => $params['material_budget_expenditure_ratio'], + 'labour_budget_expenditure_ratio' => $params['labour_budget_expenditure_ratio'], + 'cost_budget_expenditure_ratio' => $params['cost_budget_expenditure_ratio'], + 'subcontract_budget_expenditure_ratio' => $params['subcontract_budget_expenditure_ratio'], + ]); + 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 16:24 + */ + public static function delete(array $params): bool + { + return ProjectAlarmSet::destroy($params['id']); + } + + + /** + * @notes 获取项目预警设置详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public static function detail($params): array + { + $data = ProjectAlarmSet::field('id,project_id,material_budget_expenditure_ratio,labour_budget_expenditure_ratio,cost_budget_expenditure_ratio,subcontract_budget_expenditure_ratio')->findOrEmpty($params['id'])->toArray(); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + return $data; + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectAlarmSetValidate.php b/app/adminapi/validate/project/ProjectAlarmSetValidate.php new file mode 100644 index 000000000..cf6b5f8be --- /dev/null +++ b/app/adminapi/validate/project/ProjectAlarmSetValidate.php @@ -0,0 +1,130 @@ + 'require|checkData', + 'project_id' => 'require|checkProject', + 'material_budget_expenditure_ratio' => 'float|egt:0', + 'labour_budget_expenditure_ratio' => 'float|egt:0', + 'cost_budget_expenditure_ratio' => 'float|egt:0', + 'subcontract_budget_expenditure_ratio' => 'float|egt:0', + ]; + + protected $message = [ + 'project_id.require' => '请选择项目', + 'material_budget_expenditure_ratio.float' => '材料预算花费比例必须是数字', + 'material_budget_expenditure_ratio.egt' => '材料预算花费比例必须大于等于0', + 'labour_budget_expenditure_ratio.float' => '人工预算花费比例必须是数字', + 'labour_budget_expenditure_ratio.egt' => '人工预算花费比例必须大于等于0', + 'cost_budget_expenditure_ratio.float' => '费用预算花费比例必须是数字', + 'cost_budget_expenditure_ratio.egt' => '费用预算花费比例必须大于等于0', + 'subcontract_budget_expenditure_ratio.float' => '分包预算花费比例必须是数字', + 'subcontract_budget_expenditure_ratio.egt' => '分包预算花费比例必须大于等于0', + ]; + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_id' => '项目id', + + ]; + + + /** + * @notes 添加场景 + * @return ProjectAlarmSetValidate + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectAlarmSetValidate + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectAlarmSetValidate + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectAlarmSetValidate + * @author likeadmin + * @date 2023/12/14 16:24 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = ProjectAlarmSet::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '数据不存在'; + } + return true; + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目不存在'; + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectAlarmSet.php b/app/common/model/project/ProjectAlarmSet.php new file mode 100644 index 000000000..5366e9f10 --- /dev/null +++ b/app/common/model/project/ProjectAlarmSet.php @@ -0,0 +1,34 @@ +