From cb621e8d8ed016b46a4f8c939b66e4fd7fd031a2 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Mon, 8 Jan 2024 22:00:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=9D=90=E6=96=99=E9=A2=84?= =?UTF-8?q?=E7=AE=97=E6=98=8E=E7=BB=86=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectMaterialBudgetDetailController.php | 108 ++++++++++++++++ .../ProjectMaterialBudgetDetailLists.php | 77 ++++++++++++ .../ProjectMaterialBudgetDetailLogic.php | 118 ++++++++++++++++++ .../ProjectMaterialBudgetDetailValidate.php | 106 ++++++++++++++++ .../project/ProjectMaterialBudgetDetail.php | 34 +++++ 5 files changed, 443 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectMaterialBudgetDetailController.php create mode 100644 app/adminapi/lists/project/ProjectMaterialBudgetDetailLists.php create mode 100644 app/adminapi/logic/project/ProjectMaterialBudgetDetailLogic.php create mode 100644 app/adminapi/validate/project/ProjectMaterialBudgetDetailValidate.php create mode 100644 app/common/model/project/ProjectMaterialBudgetDetail.php diff --git a/app/adminapi/controller/project/ProjectMaterialBudgetDetailController.php b/app/adminapi/controller/project/ProjectMaterialBudgetDetailController.php new file mode 100644 index 000000000..01c885989 --- /dev/null +++ b/app/adminapi/controller/project/ProjectMaterialBudgetDetailController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectMaterialBudgetDetailLists()); + } + + + /** + * @notes 添加材料预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function add() + { + $params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('add'); + $result = ProjectMaterialBudgetDetailLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectMaterialBudgetDetailLogic::getError()); + } + + + /** + * @notes 编辑材料预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function edit() + { + $params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('edit'); + $result = ProjectMaterialBudgetDetailLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectMaterialBudgetDetailLogic::getError()); + } + + + /** + * @notes 删除材料预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function delete() + { + $params = (new ProjectMaterialBudgetDetailValidate())->post()->goCheck('delete'); + ProjectMaterialBudgetDetailLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取材料预算明细详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function detail() + { + $params = (new ProjectMaterialBudgetDetailValidate())->goCheck('detail'); + $result = ProjectMaterialBudgetDetailLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectMaterialBudgetDetailLists.php b/app/adminapi/lists/project/ProjectMaterialBudgetDetailLists.php new file mode 100644 index 000000000..e4fb0fce9 --- /dev/null +++ b/app/adminapi/lists/project/ProjectMaterialBudgetDetailLists.php @@ -0,0 +1,77 @@ + ['material_budget_id', 'material_id', 'budget_type'], + ]; + } + + + /** + * @notes 获取材料预算明细列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function lists(): array + { + return ProjectMaterialBudgetDetail::where($this->searchWhere) + ->field(['id', 'material_budget_id', 'material_id', 'budget_type', 'price', 'num', 'amount', 'remark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取材料预算明细数量 + * @return int + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function count(): int + { + return ProjectMaterialBudgetDetail::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectMaterialBudgetDetailLogic.php b/app/adminapi/logic/project/ProjectMaterialBudgetDetailLogic.php new file mode 100644 index 000000000..8b4b79bb5 --- /dev/null +++ b/app/adminapi/logic/project/ProjectMaterialBudgetDetailLogic.php @@ -0,0 +1,118 @@ + $params['material_budget_id'], + 'material_id' => $params['material_id'], + 'budget_type' => $params['budget_type'], + 'price' => $params['price'], + 'num' => $params['num'], + 'amount' => $params['amount'], + '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/01/08 21:52 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectMaterialBudgetDetail::where('id', $params['id'])->update([ + 'material_budget_id' => $params['material_budget_id'], + 'material_id' => $params['material_id'], + 'budget_type' => $params['budget_type'], + 'price' => $params['price'], + 'num' => $params['num'], + 'amount' => $params['amount'], + '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/01/08 21:52 + */ + public static function delete(array $params): bool + { + return ProjectMaterialBudgetDetail::destroy($params['id']); + } + + + /** + * @notes 获取材料预算明细详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public static function detail($params): array + { + return ProjectMaterialBudgetDetail::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectMaterialBudgetDetailValidate.php b/app/adminapi/validate/project/ProjectMaterialBudgetDetailValidate.php new file mode 100644 index 000000000..68c8cb9c6 --- /dev/null +++ b/app/adminapi/validate/project/ProjectMaterialBudgetDetailValidate.php @@ -0,0 +1,106 @@ + 'require', + 'material_budget_id' => 'require', + 'material_id' => 'require', + 'budget_type' => 'require', + 'price' => 'require', + 'num' => 'require', + 'amount' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'material_budget_id' => '材料预算id', + 'material_id' => '材料id', + 'budget_type' => '预算类型', + 'price' => '材料单价', + 'num' => '材料数量', + 'amount' => '金额', + ]; + + + /** + * @notes 添加场景 + * @return ProjectMaterialBudgetDetailValidate + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function sceneAdd() + { + return $this->only(['material_budget_id','material_id','budget_type','price','num','amount']); + } + + + /** + * @notes 编辑场景 + * @return ProjectMaterialBudgetDetailValidate + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function sceneEdit() + { + return $this->only(['id','material_budget_id','material_id','budget_type','price','num','amount']); + } + + + /** + * @notes 删除场景 + * @return ProjectMaterialBudgetDetailValidate + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectMaterialBudgetDetailValidate + * @author likeadmin + * @date 2024/01/08 21:52 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectMaterialBudgetDetail.php b/app/common/model/project/ProjectMaterialBudgetDetail.php new file mode 100644 index 000000000..82a8e2b45 --- /dev/null +++ b/app/common/model/project/ProjectMaterialBudgetDetail.php @@ -0,0 +1,34 @@ +