From a38f1e18ad49976c6e2653ba7debce20db322139 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Sat, 13 Apr 2024 14:05:39 +0800 Subject: [PATCH] update --- .../FinancialCollectionPlanController.php | 108 ++++++++++++++ .../FinancialCollectionPlanLists.php | 106 ++++++++++++++ .../FinancialCollectionPlanLogic.php | 134 ++++++++++++++++++ .../FinancialCollectionPlanValidate.php | 119 ++++++++++++++++ .../financial/FinancialCollectionPlan.php | 38 +++++ 5 files changed, 505 insertions(+) create mode 100644 app/adminapi/controller/financial/FinancialCollectionPlanController.php create mode 100644 app/adminapi/lists/financial/FinancialCollectionPlanLists.php create mode 100644 app/adminapi/logic/financial/FinancialCollectionPlanLogic.php create mode 100644 app/adminapi/validate/financial/FinancialCollectionPlanValidate.php create mode 100644 app/common/model/financial/FinancialCollectionPlan.php diff --git a/app/adminapi/controller/financial/FinancialCollectionPlanController.php b/app/adminapi/controller/financial/FinancialCollectionPlanController.php new file mode 100644 index 000000000..76f582525 --- /dev/null +++ b/app/adminapi/controller/financial/FinancialCollectionPlanController.php @@ -0,0 +1,108 @@ +dataLists(new FinancialCollectionPlanLists()); + } + + + /** + * @notes 添加财务管理--合同收款计划 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function add() + { + $params = (new FinancialCollectionPlanValidate())->post()->goCheck('add'); + $result = FinancialCollectionPlanLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(FinancialCollectionPlanLogic::getError()); + } + + + /** + * @notes 编辑财务管理--合同收款计划 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function edit() + { + $params = (new FinancialCollectionPlanValidate())->post()->goCheck('edit'); + $result = FinancialCollectionPlanLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(FinancialCollectionPlanLogic::getError()); + } + + + /** + * @notes 删除财务管理--合同收款计划 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function delete() + { + $params = (new FinancialCollectionPlanValidate())->post()->goCheck('delete'); + FinancialCollectionPlanLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取财务管理--合同收款计划详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function detail() + { + $params = (new FinancialCollectionPlanValidate())->goCheck('detail'); + $result = FinancialCollectionPlanLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/financial/FinancialCollectionPlanLists.php b/app/adminapi/lists/financial/FinancialCollectionPlanLists.php new file mode 100644 index 000000000..6010d5fdd --- /dev/null +++ b/app/adminapi/lists/financial/FinancialCollectionPlanLists.php @@ -0,0 +1,106 @@ + ['contract_id'], + '%like%' => ['collection_user'], + ]; + } + + + /** + * @notes 获取财务管理--合同收款计划列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function lists(): array + { + $params = $this->request->get(); + $where = []; + if (!empty($params['contract_name'])) { + $contract_ids = MarketingContract::where('contract_name', 'like', '%' . $params['contract_name'] . '%')->column('id'); + $where[] = ['contract_id', 'in', $contract_ids]; + } + if (!empty($params['collection_date'])) { + $date = explode(',', $params['collection_date']); + $where[] = ['collection_date', 'between', [strtotime($date[0] . ' 00:00:00'), strtotime($date[1] . ' 23:59:59')]]; + } + return FinancialCollectionPlan::where($this->searchWhere)->where($where) + ->field(['id', 'contract_id', 'collection_amount', 'collection_date', 'collection_user', 'remark', 'annex']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($data) { + $contract = MarketingContract::field('contract_name,contract_type,business_nature,part_a,signed_amount,create_time')->where('id', $data['contract_id'])->findOrEmpty(); + $data['contract_name'] = $contract?->contract_name; + $data['contract_type'] = $contract?->contract_type_text; + $data['business_nature'] = $contract?->business_nature_text; + $data['signed_amount'] = $contract?->signed_amount; + $data['signed_date'] = $contract?->create_time; + }) + ->toArray(); + } + + + /** + * @notes 获取财务管理--合同收款计划数量 + * @return int + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function count(): int + { + $params = $this->request->get(); + $where = []; + if (!empty($params['contract_name'])) { + $contract_ids = MarketingContract::where('contract_name', 'like', '%' . $params['contract_name'] . '%')->column('id'); + $where[] = ['contract_id', 'in', $contract_ids]; + } + if (!empty($params['collection_date'])) { + $date = explode(',', $params['collection_date']); + $where[] = ['collection_date', 'between', [strtotime($date[0] . ' 00:00:00'), strtotime($date[1] . ' 23:59:59')]]; + } + return FinancialCollectionPlan::where($this->searchWhere)->where($where)->count(); + } + + } \ No newline at end of file diff --git a/app/adminapi/logic/financial/FinancialCollectionPlanLogic.php b/app/adminapi/logic/financial/FinancialCollectionPlanLogic.php new file mode 100644 index 000000000..b8b1b4125 --- /dev/null +++ b/app/adminapi/logic/financial/FinancialCollectionPlanLogic.php @@ -0,0 +1,134 @@ + $params['contract_id'], + 'collection_amount' => $params['collection_amount'], + 'collection_date' => !empty($params['collection_date']) ? strtotime($params['collection_date']) : 0, + 'collection_user' => $params['collection_user'], + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + ]); + 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/04/13 13:46 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + FinancialCollectionPlan::where('id', $params['id'])->update([ + 'contract_id' => $params['contract_id'], + 'collection_amount' => $params['collection_amount'], + 'collection_date' => !empty($params['collection_date']) ? strtotime($params['collection_date']) : 0, + 'collection_user' => $params['collection_user'], + 'remark' => $params['remark'] ?? '', + 'annex' => $params['annex'] ? json_encode($params['annex']) : null, + ]); + 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/04/13 13:46 + */ + public static function delete(array $params): bool + { + return FinancialCollectionPlan::destroy($params['id']); + } + + + /** + * @notes 获取财务管理--合同收款计划详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public static function detail($params): array + { + $data = FinancialCollectionPlan::withoutField('create_time,update_time,delete_time')->findOrEmpty($params['id']); + $contract = MarketingContract::field('contract_name,contract_type,business_nature,part_a,signed_amount,create_time')->where('id', $data['contract_id'])->findOrEmpty(); + $custom = MarketingCustom::field('name')->where('id', $contract['part_a'])->findOrEmpty(); + $data['contract_name'] = $contract?->contract_name; + $data['contract_type'] = $contract?->contract_type_text; + $data['business_nature'] = $contract?->business_nature_text; + $data['signed_amount'] = $contract?->signed_amount; + $data['signed_date'] = $contract?->create_time; + $data['part_a_name'] = $custom?->name; + //开票金额 + $data['total_invoice_amount'] = FinancialInvoice::where('contract_id', $data['contract_id'])->sum('apply_amount'); + //到账金额 + $data['total_refund_amount'] = FinancialRefund::where('contract_id', $data['contract_id'])->sum('amount'); + //结算金额 + $data['total_settlement_amount'] = FinancialSettlement::where('contract_id', $data['contract_id'])->sum('amount'); + return $data->toArray(); + } + } \ No newline at end of file diff --git a/app/adminapi/validate/financial/FinancialCollectionPlanValidate.php b/app/adminapi/validate/financial/FinancialCollectionPlanValidate.php new file mode 100644 index 000000000..c6e9e5441 --- /dev/null +++ b/app/adminapi/validate/financial/FinancialCollectionPlanValidate.php @@ -0,0 +1,119 @@ + 'require|checkData', + 'contract_id' => 'require|checkContract', + 'collection_amount' => 'require|float|egt:0', + 'collection_date' => 'require|dateFormat:Y-m-d', + 'collection_user' => 'require', + 'annex' => 'checkAnnex', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'contract_id' => '合同id', + 'collection_amount' => '计划收款金额', + 'collection_date' => '计划日期', + 'collection_user' => '计划人', + 'remark' => '备注', + + ]; + + + /** + * @notes 添加场景 + * @return FinancialCollectionPlanValidate + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function sceneAdd() + { + return $this->only(['contract_id', 'collection_amount', 'collection_date', 'collection_user', 'remark', 'annex']); + } + + + /** + * @notes 编辑场景 + * @return FinancialCollectionPlanValidate + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function sceneEdit() + { + return $this->only(['id', 'contract_id', 'collection_amount', 'collection_date', 'collection_user', 'remark', 'annex']); + } + + + /** + * @notes 删除场景 + * @return FinancialCollectionPlanValidate + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function sceneDelete() + { + return $this->only(['id'])->remove('id', 'checkData'); + } + + + /** + * @notes 详情场景 + * @return FinancialCollectionPlanValidate + * @author likeadmin + * @date 2024/04/13 13:46 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + + public function checkData($value): bool|string + { + $data = FinancialCollectionPlan::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '数据不存在' : true; + } + + public function checkContract($value): bool|string + { + $data = MarketingContract::where('id', $value)->findOrEmpty(); + return $data->isEmpty() ? '合同数据不存在' : true; + } + + } \ No newline at end of file diff --git a/app/common/model/financial/FinancialCollectionPlan.php b/app/common/model/financial/FinancialCollectionPlan.php new file mode 100644 index 000000000..a101d3f7d --- /dev/null +++ b/app/common/model/financial/FinancialCollectionPlan.php @@ -0,0 +1,38 @@ +