From d81fb074ea87601c2f29a9e600bf874adcf4d911 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Tue, 26 Mar 2024 14:34:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E9=A2=84?= =?UTF-8?q?=E7=AE=97=E4=B9=A6=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FinancialBudgetDocController.php | 111 ++++++++++++ .../FinancialBudgetDocDetailController.php | 108 ++++++++++++ .../FinancialBudgetDocDetailLists.php | 77 ++++++++ .../financial/FinancialBudgetDocLists.php | 85 +++++++++ .../FinancialBudgetDocDetailLogic.php | 113 ++++++++++++ .../financial/FinancialBudgetDocLogic.php | 166 ++++++++++++++++++ .../FinancialBudgetDocDetailValidate.php | 132 ++++++++++++++ .../financial/FinancialBudgetDocValidate.php | 156 ++++++++++++++++ .../model/financial/FinancialBudgetDoc.php | 38 ++++ .../financial/FinancialBudgetDocDetail.php | 34 ++++ 10 files changed, 1020 insertions(+) create mode 100644 app/adminapi/controller/financial/FinancialBudgetDocController.php create mode 100644 app/adminapi/controller/financial/FinancialBudgetDocDetailController.php create mode 100644 app/adminapi/lists/financial/FinancialBudgetDocDetailLists.php create mode 100644 app/adminapi/lists/financial/FinancialBudgetDocLists.php create mode 100644 app/adminapi/logic/financial/FinancialBudgetDocDetailLogic.php create mode 100644 app/adminapi/logic/financial/FinancialBudgetDocLogic.php create mode 100644 app/adminapi/validate/financial/FinancialBudgetDocDetailValidate.php create mode 100644 app/adminapi/validate/financial/FinancialBudgetDocValidate.php create mode 100644 app/common/model/financial/FinancialBudgetDoc.php create mode 100644 app/common/model/financial/FinancialBudgetDocDetail.php diff --git a/app/adminapi/controller/financial/FinancialBudgetDocController.php b/app/adminapi/controller/financial/FinancialBudgetDocController.php new file mode 100644 index 000000000..7c7b01848 --- /dev/null +++ b/app/adminapi/controller/financial/FinancialBudgetDocController.php @@ -0,0 +1,111 @@ +dataLists(new FinancialBudgetDocLists()); + } + + + /** + * @notes 添加财务管理--项目预算书 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function add() + { + $params = (new FinancialBudgetDocValidate())->post()->goCheck('add'); + $result = FinancialBudgetDocLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FinancialBudgetDocLogic::getError()); + } + + + /** + * @notes 编辑财务管理--项目预算书 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function edit() + { + $params = (new FinancialBudgetDocValidate())->post()->goCheck('edit'); + $result = FinancialBudgetDocLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FinancialBudgetDocLogic::getError()); + } + + + /** + * @notes 删除财务管理--项目预算书 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function delete() + { + $params = (new FinancialBudgetDocValidate())->post()->goCheck('delete'); + $result = FinancialBudgetDocLogic::delete($params); + if (true === $result) { + return $this->success('删除成功', [], 1, 1); + } + return $this->fail(FinancialBudgetDocLogic::getError()); + } + + + /** + * @notes 获取财务管理--项目预算书详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function detail() + { + $params = (new FinancialBudgetDocValidate())->goCheck('detail'); + $result = FinancialBudgetDocLogic::detail($params); + return $this->data($result); + } + + + } \ No newline at end of file diff --git a/app/adminapi/controller/financial/FinancialBudgetDocDetailController.php b/app/adminapi/controller/financial/FinancialBudgetDocDetailController.php new file mode 100644 index 000000000..579f90d26 --- /dev/null +++ b/app/adminapi/controller/financial/FinancialBudgetDocDetailController.php @@ -0,0 +1,108 @@ +dataLists(new FinancialBudgetDocDetailLists()); + } + + + /** + * @notes 添加财务管理--项目预算书--预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function add() + { + $params = (new FinancialBudgetDocDetailValidate())->post()->goCheck('add'); + $result = FinancialBudgetDocDetailLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FinancialBudgetDocDetailLogic::getError()); + } + + + /** + * @notes 编辑财务管理--项目预算书--预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function edit() + { + $params = (new FinancialBudgetDocDetailValidate())->post()->goCheck('edit'); + $result = FinancialBudgetDocDetailLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FinancialBudgetDocDetailLogic::getError()); + } + + + /** + * @notes 删除财务管理--项目预算书--预算明细 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function delete() + { + $params = (new FinancialBudgetDocDetailValidate())->post()->goCheck('delete'); + FinancialBudgetDocDetailLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取财务管理--项目预算书--预算明细详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function detail() + { + $params = (new FinancialBudgetDocDetailValidate())->goCheck('detail'); + $result = FinancialBudgetDocDetailLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/financial/FinancialBudgetDocDetailLists.php b/app/adminapi/lists/financial/FinancialBudgetDocDetailLists.php new file mode 100644 index 000000000..6c4566f52 --- /dev/null +++ b/app/adminapi/lists/financial/FinancialBudgetDocDetailLists.php @@ -0,0 +1,77 @@ + ['budget_doc_id', 'dept_id', 'type'], + ]; + } + + + /** + * @notes 获取财务管理--项目预算书--预算明细列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function lists(): array + { + return FinancialBudgetDocDetail::withoutField('create_time,update_time,delete_time')->where($this->searchWhere) + ->field(['id', 'budget_doc_id', 'dept_id', 'type', 'amount', 'remark']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取财务管理--项目预算书--预算明细数量 + * @return int + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function count(): int + { + return FinancialBudgetDocDetail::where($this->searchWhere)->count(); + } + + } \ No newline at end of file diff --git a/app/adminapi/lists/financial/FinancialBudgetDocLists.php b/app/adminapi/lists/financial/FinancialBudgetDocLists.php new file mode 100644 index 000000000..65f2e1a91 --- /dev/null +++ b/app/adminapi/lists/financial/FinancialBudgetDocLists.php @@ -0,0 +1,85 @@ + ['contract_id'], + '%like%' => ['code', 'name'], + + ]; + } + + + /** + * @notes 获取财务管理--项目预算书列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function lists(): array + { + return FinancialBudgetDoc::where($this->searchWhere) + ->field(['id', 'contract_id', 'code', 'name', 'issue_date']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($data) { + $contract = CostApprovedProject::field('contract_name')->where('id', $data['contract_id'])->findOrEmpty(); + $data['contract_name'] = $contract['contract_name']; + $data['total_amount'] = FinancialBudgetDocDetail::where('budget_doc_id', $data['id'])->sum('amount'); + }) + ->toArray(); + } + + + /** + * @notes 获取财务管理--项目预算书数量 + * @return int + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function count(): int + { + return FinancialBudgetDoc::where($this->searchWhere)->count(); + } + + } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialBudgetDocDetailLogic.php b/app/adminapi/logic/financial/FinancialBudgetDocDetailLogic.php new file mode 100644 index 000000000..7f310440d --- /dev/null +++ b/app/adminapi/logic/financial/FinancialBudgetDocDetailLogic.php @@ -0,0 +1,113 @@ + $params['budget_doc_id'], + 'dept_id' => $params['dept_id'], + 'type' => $params['type'], + '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/03/26 13:54 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + FinancialBudgetDocDetail::where('id', $params['id'])->update([ + 'budget_doc_id' => $params['budget_doc_id'], + 'dept_id' => $params['dept_id'], + 'type' => $params['type'], + 'amount' => $params['amount'], + 'remark' => $params['remark'], + '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/03/26 13:54 + */ + public static function delete(array $params): bool + { + return FinancialBudgetDocDetail::withoutField('create_time,update_time,delete_time')->destroy($params['id']); + } + + + /** + * @notes 获取财务管理--项目预算书--预算明细详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public static function detail($params): array + { + return FinancialBudgetDocDetail::findOrEmpty($params['id'])->toArray(); + } + } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialBudgetDocLogic.php b/app/adminapi/logic/financial/FinancialBudgetDocLogic.php new file mode 100644 index 000000000..d5c260bda --- /dev/null +++ b/app/adminapi/logic/financial/FinancialBudgetDocLogic.php @@ -0,0 +1,166 @@ + $params['contract_id'], + 'code' => date('YSS'), + 'name' => $params['name'], + 'issue_date' => !empty($params['issue_date']) ? strtotime($params['issue_date']) : 0, + 'remark' => $params['remark'], + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time(), + ]); + if (!empty($params['detail'])) { + foreach ($params['detail'] as $v) { + FinancialBudgetDocDetail::create([ + 'budget_doc_id' => $res->id, + 'dept_id' => $v['dept_id'], + 'type' => $v['type'], + 'amount' => $v['amount'], + 'remark' => $v['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/03/26 13:54 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + FinancialBudgetDoc::where('id', $params['id'])->update([ + 'contract_id' => $params['contract_id'], + 'name' => $params['name'], + 'issue_date' => !empty($params['issue_date']) ? strtotime($params['issue_date']) : 0, + 'remark' => $params['remark'], + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + 'create_user' => $params['create_user'], + 'create_time' => !empty($params['create_time']) ? strtotime($params['create_time']) : time(), + 'update_time' => time() + ]); + if (!empty($params['detail'])) { + foreach ($params['detail'] as $v) { + if (!empty($v['id'])) { + FinancialBudgetDocDetail::where('id', $v['id'])->update([ + 'budget_doc_id' => $params['id'], + 'dept_id' => $v['dept_id'], + 'type' => $v['type'], + 'amount' => $v['amount'], + 'remark' => $v['remark'], + 'update_time' => time(), + ]); + } else { + FinancialBudgetDocDetail::create([ + 'budget_doc_id' => $params['id'], + 'dept_id' => $v['dept_id'], + 'type' => $v['type'], + 'amount' => $v['amount'], + 'remark' => $v['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/03/26 13:54 + */ + public static function delete(array $params): bool + { + $detail = FinancialBudgetDocDetail::where('budget_doc_id', 'in', $params['id'])->findOrEmpty(); + if (!$detail->isEmpty()) { + self::setError('此数据关联了预算明细信息,需删除预算明细信息'); + return false; + } + return FinancialBudgetDoc::destroy($params['id']); + } + + + /** + * @notes 获取财务管理--项目预算书详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public static function detail($params): array + { + $data = FinancialBudgetDoc::withoutField('update_time,delete_time')->findOrEmpty($params['id']); + $contract = CostApprovedProject::field('contract_name,part_a,create_date,money,contract_type')->where('id', $data['contract_id'])->findOrEmpty(); + $data['contract_name'] = $contract['contract_name']; + $data['part_a'] = $contract['part_a']; + $data['create_date'] = $contract['create_date']; + $data['money'] = $contract['money']; + $data['contract_type'] = $contract['contract_type']; + $data['contract_type_text'] = $contract->contract_type_text; + return $data->toArray(); + } + } \ No newline at end of file diff --git a/app/adminapi/validate/financial/FinancialBudgetDocDetailValidate.php b/app/adminapi/validate/financial/FinancialBudgetDocDetailValidate.php new file mode 100644 index 000000000..9e3d9b460 --- /dev/null +++ b/app/adminapi/validate/financial/FinancialBudgetDocDetailValidate.php @@ -0,0 +1,132 @@ + 'require|checkData', + 'budget_doc_id' => 'require|checkBudgetDoc', + 'dept_id' => 'require|checkDept', + 'type' => 'require|checkType', + 'amount' => 'require|float|gt:0', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'budget_doc_id' => '预算书id', + 'dept_id' => '部门', + 'type' => '预算分成方式', + 'amount' => '预算分成金额', + 'remark' => '备注', + + ]; + + + /** + * @notes 添加场景 + * @return FinancialBudgetDocDetailValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneAdd() + { + return $this->only(['budget_doc_id', 'dept_id', 'type', 'amount', 'remark']); + } + + + /** + * @notes 编辑场景 + * @return FinancialBudgetDocDetailValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneEdit() + { + return $this->only(['id', 'budget_doc_id', 'dept_id', 'type', 'amount', 'remark']); + } + + + /** + * @notes 删除场景 + * @return FinancialBudgetDocDetailValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneDelete() + { + return $this->only(['id'])->remove('id', 'checkData'); + } + + + /** + * @notes 详情场景 + * @return FinancialBudgetDocDetailValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = FinancialBudgetDocDetail::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '数据不存在' : true; + } + + public function checkBudgetDoc($value): bool|string + { + $data = FinancialBudgetDoc::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '项目预算书信息不存在' : true; + } + + public function checkDept($value): bool|string + { + $data = Dept::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '部门信息不存在' : true; + } + + public function checkType($value): bool|string + { + $dict = DictData::where('type_value', 'budget_share_method')->column('value'); + return !in_array($value, $dict) ? '预算分成方式数据值无效' : true; + } + + } \ No newline at end of file diff --git a/app/adminapi/validate/financial/FinancialBudgetDocValidate.php b/app/adminapi/validate/financial/FinancialBudgetDocValidate.php new file mode 100644 index 000000000..ea4b45333 --- /dev/null +++ b/app/adminapi/validate/financial/FinancialBudgetDocValidate.php @@ -0,0 +1,156 @@ + 'require|checkData', + 'contract_id' => 'require|checkContract', + 'name' => 'require', + 'issue_date' => 'require|dateFormat:Y-m-d', + 'create_user' => 'require', + 'create_time' => 'require|dateFormat:Y-m-d H:i:s', + 'annex' => 'checkAnnex', + 'detail' => 'checkDetail' + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'contract_id' => '合同id', + 'name' => '预算书名称', + 'issue_date' => '下达日期', + 'remark' => '备注', + 'create_user' => '创建人', + 'create_time' => '创建时间' + ]; + + + /** + * @notes 添加场景 + * @return FinancialBudgetDocValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneAdd() + { + return $this->only(['contract_id', 'name', 'issue_date', 'remark', 'create_user', 'create_time', 'annex']); + } + + + /** + * @notes 编辑场景 + * @return FinancialBudgetDocValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneEdit() + { + return $this->only(['id', 'contract_id', 'name', 'issue_date', 'remark', 'create_user', 'create_time', 'annex']); + } + + + /** + * @notes 删除场景 + * @return FinancialBudgetDocValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneDelete() + { + return $this->only(['id'])->remove('id', 'checkData'); + } + + + /** + * @notes 详情场景 + * @return FinancialBudgetDocValidate + * @author likeadmin + * @date 2024/03/26 13:54 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = FinancialBudgetDoc::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '数据不存在' : true; + } + + public function checkContract($value): bool|string + { + $data = CostApprovedProject::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '合同信息不存在' : true; + } + + public function checkDetail($value): bool|string + { + if (empty($value) || $value == '') return true; + if (!is_array($value)) return '预算明细数据格式错误'; + foreach ($value as $k => $v) { + if (isset($v['id']) && !empty($v['id'])) { + $data = FinancialBudgetDocDetail::where('id', $v['id'])->findOrEmpty(); + if ($data->isEmpty()) { + return '第' . ($k + 1) . '行预算明细信息不存在'; + } + } + if (empty($v['dept_id'])) { + return '第' . ($k + 1) . '行部门为空'; + } else { + $dept = Dept::where('id', $v['dept_id'])->findOrEmpty(); + if ($dept->isEmpty()) return '第' . ($k + 1) . '行部门信息不存在'; + } + if (empty($v['type'])) { + return '第' . ($k + 1) . '行预算分成方式为空'; + } else { + $dict = DictData::where('type_value', 'budget_share_method')->column('value'); + if (!in_array($v['type'], $dict)) return '第' . ($k + 1) . '行预算分成方式数据值无效'; + } + if (empty($v['amount'])) { + return '第' . ($k + 1) . '行预算分成金额为空'; + } else { + if (!is_numeric($v['amount']) || $v['amount'] < 0) return '第' . ($k + 1) . '行预算分成金额必须是大于零的数字'; + } + } + return true; + } + + } \ No newline at end of file diff --git a/app/common/model/financial/FinancialBudgetDoc.php b/app/common/model/financial/FinancialBudgetDoc.php new file mode 100644 index 000000000..c340919f9 --- /dev/null +++ b/app/common/model/financial/FinancialBudgetDoc.php @@ -0,0 +1,38 @@ +