From ab2c41fa76459a12c286050d9b2cc8997504f1e7 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Mon, 22 Jan 2024 11:21:52 +0800 Subject: [PATCH] update --- .../statistics/StatisticsController.php | 45 ++++++++++++++++++- .../model/contract/SubcontractingContract.php | 6 +-- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/adminapi/controller/statistics/StatisticsController.php b/app/adminapi/controller/statistics/StatisticsController.php index e70bb5bd3..ccc6b726a 100644 --- a/app/adminapi/controller/statistics/StatisticsController.php +++ b/app/adminapi/controller/statistics/StatisticsController.php @@ -10,6 +10,8 @@ use app\common\model\bid\BidSecurityRefund; use app\common\model\contract\Contract; use app\common\model\contract\ContractNegotiation; + use app\common\model\contract\ProcurementContract; + use app\common\model\contract\ProcurementContractDetail; use app\common\model\custom\Custom; use app\common\model\custom\CustomerDemand; use app\common\model\custom\CustomerDemandSolution; @@ -207,7 +209,48 @@ } //采购合同 - public function procurementContract(){ + public function procurementContract(): Json + { + $year = $this->request->get('year'); + if(empty($year)){ + $year = date('Y'); + } + $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; + //总合同数 + $total_num = ProcurementContract::field('id')->count(); + //总合同金额 + $total_amount = ProcurementContractDetail::sum('amount_including_tax'); + //年度合同数 + $year_total_num = ProcurementContract::field('id')->whereYear('signing_date',$year)->count(); + //年度合同金额 + $year_procurement_contract_ids = ProcurementContract::whereYear('signing_date',$year)->column('id'); + $year_total_amount = ProcurementContractDetail::field('id')->where('contract_id','in',$year_procurement_contract_ids)->sum('amount_including_tax'); + $series = [ + 'name' => '合同金额', + 'data' => [] + ]; + foreach($column as &$v){ + $month = $v; + if($month < 10){ + $month = '0'.$month; + } + $month_procurement_contract_ids = ProcurementContract::whereMonth('signing_date',$year.'-'.$month)->column('id'); + $series['data'][] = ProcurementContractDetail::field('id')->where('contract_id','in',$month_procurement_contract_ids)->sum('amount_including_tax'); + $v = $v.'月'; + } + $result = [ + 'total_num' => $total_num, + 'total_amount' => $total_amount, + 'year_total_num' => $year_total_num, + 'year_total_amount' => $year_total_amount, + 'column' => $column, + 'series' => $series, + ]; + return $this->success('success',$result); + } + + //分包合同 + public function subcontractingContract() { $year = $this->request->get('year'); if(empty($year)){ $year = date('Y'); diff --git a/app/common/model/contract/SubcontractingContract.php b/app/common/model/contract/SubcontractingContract.php index c1a6959ba..4521f538f 100644 --- a/app/common/model/contract/SubcontractingContract.php +++ b/app/common/model/contract/SubcontractingContract.php @@ -42,17 +42,17 @@ class SubcontractingContract extends BaseModel public function getContractTypeTextAttr($value,$data){ $dict = DictData::where('type_value','divide_contract_type')->column('name','value'); - return $dict[$data['contract_type']]; + return !empty($data['contract_type']) ? $dict[$data['contract_type']] : ''; } public function getPayTypeTextAttr($value,$data){ $dict = DictData::where('type_value','pay_type')->column('name','value'); - return $dict[$data['pay_type']]; + return !empty($data['pay_type']) ? $dict[$data['pay_type']] : ''; } public function getAccountPeriodTextAttr($value,$data){ $dict = DictData::where('type_value','account_period')->column('name','value'); - return $dict[$data['account_period']]; + return !empty($data['account_period']) ? $dict[$data['account_period']] : ''; } } \ No newline at end of file