From 29e4f22ce977e58dacd14e588da0a1fc311e0fd7 Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 17 Jan 2024 14:08:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E6=88=90?= =?UTF-8?q?=E6=9C=AC=E8=B0=83=E6=95=B4=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectCostAdjustmentController.php | 108 +++++++++++++++ .../project/ProjectCostAdjustmentLists.php | 83 ++++++++++++ .../project/ProjectCostAdjustmentLogic.php | 125 ++++++++++++++++++ .../project/ProjectCostAdjustmentValidate.php | 119 +++++++++++++++++ .../model/project/ProjectCostAdjustment.php | 41 ++++++ 5 files changed, 476 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectCostAdjustmentController.php create mode 100644 app/adminapi/lists/project/ProjectCostAdjustmentLists.php create mode 100644 app/adminapi/logic/project/ProjectCostAdjustmentLogic.php create mode 100644 app/adminapi/validate/project/ProjectCostAdjustmentValidate.php create mode 100644 app/common/model/project/ProjectCostAdjustment.php diff --git a/app/adminapi/controller/project/ProjectCostAdjustmentController.php b/app/adminapi/controller/project/ProjectCostAdjustmentController.php new file mode 100644 index 000000000..b01594dfa --- /dev/null +++ b/app/adminapi/controller/project/ProjectCostAdjustmentController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectCostAdjustmentLists()); + } + + + /** + * @notes 添加成本调整 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function add() + { + $params = (new ProjectCostAdjustmentValidate())->post()->goCheck('add'); + $result = ProjectCostAdjustmentLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectCostAdjustmentLogic::getError()); + } + + + /** + * @notes 编辑成本调整 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function edit() + { + $params = (new ProjectCostAdjustmentValidate())->post()->goCheck('edit'); + $result = ProjectCostAdjustmentLogic::edit($params,$this->adminId); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectCostAdjustmentLogic::getError()); + } + + + /** + * @notes 删除成本调整 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function delete() + { + $params = (new ProjectCostAdjustmentValidate())->post()->goCheck('delete'); + ProjectCostAdjustmentLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取成本调整详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function detail() + { + $params = (new ProjectCostAdjustmentValidate())->goCheck('detail'); + $result = ProjectCostAdjustmentLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectCostAdjustmentLists.php b/app/adminapi/lists/project/ProjectCostAdjustmentLists.php new file mode 100644 index 000000000..389326481 --- /dev/null +++ b/app/adminapi/lists/project/ProjectCostAdjustmentLists.php @@ -0,0 +1,83 @@ + ['project_id'], + ]; + } + + + /** + * @notes 获取成本调整列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function lists(): array + { + return ProjectCostAdjustment::where($this->searchWhere) + ->field(['id', 'project_id', 'adjust_date', 'adjust_amount', 'remark', 'annex']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function($data){ + $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; + }) + ->toArray(); + } + + + /** + * @notes 获取成本调整数量 + * @return int + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function count(): int + { + return ProjectCostAdjustment::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectCostAdjustmentLogic.php b/app/adminapi/logic/project/ProjectCostAdjustmentLogic.php new file mode 100644 index 000000000..fe159f416 --- /dev/null +++ b/app/adminapi/logic/project/ProjectCostAdjustmentLogic.php @@ -0,0 +1,125 @@ + $params['project_id'], + 'adjust_date' => strtotime($params['adjust_date']), + 'adjust_amount' => $params['adjust_amount'], + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'add_user' => $admin_id, + 'update_user' => $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/01/17 13:43 + */ + public static function edit(array $params,$admin_id): bool + { + Db::startTrans(); + try { + ProjectCostAdjustment::where('id', $params['id'])->update([ + 'project_id' => $params['project_id'], + 'adjust_date' => strtotime($params['adjust_date']), + 'adjust_amount' => $params['adjust_amount'], + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'update_user' => $admin_id, + 'update_time' => time(), + ]); + 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/01/17 13:43 + */ + public static function delete(array $params): bool + { + return ProjectCostAdjustment::destroy($params['id']); + } + + + /** + * @notes 获取成本调整详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public static function detail($params): array + { + $data = ProjectCostAdjustment::field('id,project_id,adjust_date,adjust_amount,remark,annex,add_user,update_user,create_time,update_time')->findOrEmpty($params['id']); + $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); + $admin = Admin::where('id','in',[$data['add_user'],$data['update_user']])->column('name','id'); + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['add_user'] = $admin[$data['add_user']]; + $data['update_user'] = $admin[$data['update_user']]; + return $data->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectCostAdjustmentValidate.php b/app/adminapi/validate/project/ProjectCostAdjustmentValidate.php new file mode 100644 index 000000000..9591c9aea --- /dev/null +++ b/app/adminapi/validate/project/ProjectCostAdjustmentValidate.php @@ -0,0 +1,119 @@ + 'require', + 'project_id' => 'require|checkProject', + 'adjust_date' => 'require|dateFormat:Y-m-d', + 'adjust_amount' => 'require|float|gt:0', + 'annex' => 'checkAnnex', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'project_id' => '项目id', + 'adjust_date' => '调整日期', + 'adjust_amount' => '调整金额', + ]; + + + /** + * @notes 添加场景 + * @return ProjectCostAdjustmentValidate + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectCostAdjustmentValidate + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectCostAdjustmentValidate + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectCostAdjustmentValidate + * @author likeadmin + * @date 2024/01/17 13:43 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkProject($value): bool|string + { + $data = Project::where('id',$value)->findOrEmpty(); + if($data->isEmpty()){ + return '项目信息不存在'; + } + return true; + } + + public function checkAnnex($value): bool|string + { + if(!empty($value) && $value != ''){ + if(!is_array($value)){ + return '附件格式错误'; + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectCostAdjustment.php b/app/common/model/project/ProjectCostAdjustment.php new file mode 100644 index 000000000..2da50b10a --- /dev/null +++ b/app/common/model/project/ProjectCostAdjustment.php @@ -0,0 +1,41 @@ +