From 4f0252031fa1fe5d8834308b3aa76b616b68a2e8 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Fri, 5 Jul 2024 09:57:01 +0800 Subject: [PATCH] (Update: refactor code and improve statistics functions in ConsultStatisticsController, FinancialStatisticsController, BaseModel, FinancialBidMargin, FinancialBidMarginRecovery, and FinancialInvoice) --- .../ManageStatisticsController.php | 230 ++++++++------ .../SupervisionStatisticsController.php | 285 ++++++++++-------- .../consult_basic/ConsultStatisticsLogic.php | 73 ++++- .../financial/FinancialStatisticsLogic.php | 14 +- .../manage_basic/ManageStatisticsLogic.php | 93 ++++++ .../marketing/MarketingStatisticsLogic.php | 8 +- .../SupervisionProjectStatisticsLogic.php | 81 +++++ app/common/model/BaseModel.php | 27 +- 8 files changed, 569 insertions(+), 242 deletions(-) create mode 100644 app/adminapi/logic/manage_basic/ManageStatisticsLogic.php create mode 100644 app/adminapi/logic/supervision_project/SupervisionProjectStatisticsLogic.php diff --git a/app/adminapi/controller/manage_basic/ManageStatisticsController.php b/app/adminapi/controller/manage_basic/ManageStatisticsController.php index ffed1df70..70e3afecc 100644 --- a/app/adminapi/controller/manage_basic/ManageStatisticsController.php +++ b/app/adminapi/controller/manage_basic/ManageStatisticsController.php @@ -1,104 +1,134 @@ where([ - ['review_status','=', 1], - ['contract_type','=',0], - ['business_nature','=',2], - ['status','=',0] - ])->count(); - //已立项项目 - $approved_project_num = ManageProject::field('id')->count(); - $result['data'] = [ - [ - 'name' => '待立项项目', - 'value' => $pending_project_num - ], - [ - 'name' => '已立项项目', - 'value' => $approved_project_num - ] - ]; - return $this->success('success',$result); + $date = $this->request->get('date', ''); + $where = []; + $time = getDay($date); + $res = ManageStatisticsLogic::ManageStatistics($where, $time); + return $this->data($res); + } + + public function project() + { + //待立项项目 + $pending_project_num = MarketingContract::field('id')->where([ + ['review_status', '=', 1], + ['contract_type', '=', 0], + ['business_nature', '=', 2], + ['status', '=', 0] + ])->count(); + //已立项项目 + $approved_project_num = ManageProject::field('id')->count(); + $result['data'] = [ + [ + 'name' => '待立项项目', + 'value' => $pending_project_num + ], + [ + 'name' => '已立项项目', + 'value' => $approved_project_num + ] + ]; + return $this->success('success', $result); + } + + public function invoice() + { + $year = $this->request->get('year', date('Y')); + $contract_ids = ManageProject::column('contract'); + //总开票金额 + $total_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->sum('apply_amount'); + //年度开票金额 + $year_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereYear('create_time', $year)->sum('apply_amount'); + //总到账金额 + $total_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->sum('amount'); + $year_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + //总结算金额 + $total_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->sum('amount'); + //年度结算金额 + $year_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; + $invoice_series = [ + 'name' => '开票金额', + 'data' => [] + ]; + $refund_series = [ + 'name' => '到账金额', + 'data' => [] + ]; + $settlement_series = [ + 'name' => '结算金额', + 'data' => [] + ]; + foreach ($column as &$v) { + $invoice_series['data'][] = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereMonth('create_time', $year . '-' . $v)->sum('apply_amount'); + $refund_series['data'][] = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $settlement_series['data'][] = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $v = $v . '月'; } - - public function invoice(){ - $year = $this->request->get('year',date('Y')); - $contract_ids = ManageProject::column('contract'); - //总开票金额 - $total_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->sum('apply_amount'); - //年度开票金额 - $year_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->whereYear('create_time',$year)->sum('apply_amount'); - //总到账金额 - $total_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->sum('amount'); - $year_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - //总结算金额 - $total_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->sum('amount'); - //年度结算金额 - $year_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; - $invoice_series = [ - 'name' => '开票金额', - 'data' => [] - ]; - $refund_series = [ - 'name' => '到账金额', - 'data' => [] - ]; - $settlement_series = [ - 'name' => '结算金额', - 'data' => [] - ]; - foreach($column as &$v){ - $invoice_series['data'][] = FinancialInvoice::where('contract_id','in',$contract_ids)->whereMonth('create_time',$year.'-'.$v)->sum('apply_amount'); - $refund_series['data'][] = FinancialRefund::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $settlement_series['data'][] = FinancialSettlement::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $v = $v.'月'; - } - $result = compact('total_invoice_amount','year_invoice_amount','total_refund_amount','year_refund_amount','total_settlement_amount','year_settlement_amount', - 'column','invoice_series','refund_series','settlement_series'); - return $this->success('success',$result); + $result = compact( + 'total_invoice_amount', + 'year_invoice_amount', + 'total_refund_amount', + 'year_refund_amount', + 'total_settlement_amount', + 'year_settlement_amount', + 'column', + 'invoice_series', + 'refund_series', + 'settlement_series' + ); + return $this->success('success', $result); + } + + public function metered_payment() + { + $year = $this->request->get('year', date('Y')); + //统计总的进度 + $total_done = ManageMeteredPayment::sum('month_amount'); + //统计年度进度 + $year_done = ManageMeteredPayment::whereYear('date', $year)->sum('month_amount'); + //统计总的支付 + $total_payment = ManageMeteredPayment::sum('month_pay'); + //统计年度支付 + $year_payment = ManageMeteredPayment::whereYear('date', $year)->sum('month_pay'); + $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; + $complete_series = [ + 'name' => '完成总量', + 'data' => [] + ]; + $payment_series = [ + 'name' => '支付总量', + 'data' => [] + ]; + foreach ($column as &$v) { + $complete_series['data'][] = ManageMeteredPayment::whereMonth('date', $year . '-' . $v)->sum('month_amount'); + $payment_series['data'][] = ManageMeteredPayment::whereMonth('date', $year . '-' . $v)->sum('month_pay'); + $v = $v . '月'; } - - public function metered_payment(){ - $year = $this->request->get('year',date('Y')); - //统计总的进度 - $total_done = ManageMeteredPayment::sum('month_amount'); - //统计年度进度 - $year_done = ManageMeteredPayment::whereYear('date',$year)->sum('month_amount'); - //统计总的支付 - $total_payment = ManageMeteredPayment::sum('month_pay'); - //统计年度支付 - $year_payment = ManageMeteredPayment::whereYear('date',$year)->sum('month_pay'); - $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; - $complete_series = [ - 'name' => '完成总量', - 'data' => [] - ]; - $payment_series = [ - 'name' => '支付总量', - 'data' => [] - ]; - foreach($column as &$v){ - $complete_series['data'][] = ManageMeteredPayment::whereMonth('date',$year.'-'.$v)->sum('month_amount'); - $payment_series['data'][] = ManageMeteredPayment::whereMonth('date',$year.'-'.$v)->sum('month_pay'); - $v = $v.'月'; - } - $result = compact('total_done','year_done','total_payment','year_payment', - 'column','complete_series','payment_series'); - return $this->success('success',$result); - } - } \ No newline at end of file + $result = compact( + 'total_done', + 'year_done', + 'total_payment', + 'year_payment', + 'column', + 'complete_series', + 'payment_series' + ); + return $this->success('success', $result); + } +} diff --git a/app/adminapi/controller/supervision_project/SupervisionStatisticsController.php b/app/adminapi/controller/supervision_project/SupervisionStatisticsController.php index a1f4c9f70..221bcd583 100644 --- a/app/adminapi/controller/supervision_project/SupervisionStatisticsController.php +++ b/app/adminapi/controller/supervision_project/SupervisionStatisticsController.php @@ -1,132 +1,165 @@ where([ - ['review_status','=', 1], - ['contract_type','=',0], - ['business_nature','=',1], - ['status','=',0] - ])->count(); - //已立项项目 - $approved_project_num = SupervisionProject::field('id')->count(); - $result['data'] = [ - [ - 'name' => '待立项项目', - 'value' => $pending_project_num - ], - [ - 'name' => '已立项项目', - 'value' => $approved_project_num - ] + $date = $this->request->get('date', ''); + $where = []; + $time = getDay($date); + $res = SupervisionProjectStatisticsLogic::consultStatistics($where, $time); + return $this->data($res); + } + //项目立项统计 + public function project() + { + //待立项项目 + $pending_project_num = MarketingContract::field('id')->where([ + ['review_status', '=', 1], + ['contract_type', '=', 0], + ['business_nature', '=', 1], + ['status', '=', 0] + ])->count(); + //已立项项目 + $approved_project_num = SupervisionProject::field('id')->count(); + $result['data'] = [ + [ + 'name' => '待立项项目', + 'value' => $pending_project_num + ], + [ + 'name' => '已立项项目', + 'value' => $approved_project_num + ] + ]; + return $this->success('success', $result); + } + + //项目问题统计 + public function problem() + { + $problem_cate = DictData::where('type_value', 'problem_cate')->column('name', 'value'); + $data = []; + foreach ($problem_cate as $k => $v) { + $count = SupervisionProblem::where('problem_cate', $k)->count(); + $data[] = [ + 'name' => $v, + 'value' => $count ]; - return $this->success('success',$result); } - - //项目问题统计 - public function problem(){ - $problem_cate = DictData::where('type_value','problem_cate')->column('name','value'); - $data = []; - foreach($problem_cate as $k=>$v){ - $count = SupervisionProblem::where('problem_cate',$k)->count(); - $data[] = [ - 'name' => $v, - 'value' => $count - ]; - } - $result['data'] = $data; - return $this->success('success',$result); + $result['data'] = $data; + return $this->success('success', $result); + } + + //项目月报统计 + public function month_report() + { + $year = $this->request->get('year', date('Y')); + //统计总的进度 + $total_schedule = SupervisionProjectMonthlyReport::sum('this_month_progress'); + //统计年度进度 + $year_schedule = SupervisionProjectMonthlyReport::whereYear('date', $year)->sum('this_month_progress'); + //统计总的完成 + $total_complete = SupervisionProjectMonthlyReport::sum('total_amount'); + //统计年度完成 + $year_complete = SupervisionProjectMonthlyReport::whereYear('date', $year)->sum('total_amount'); + //统计总的支付 + $total_payment = SupervisionProjectMonthlyReport::sum('total_pay'); + //统计年度支付 + $year_payment = SupervisionProjectMonthlyReport::whereYear('date', $year)->sum('total_pay'); + $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; + $schedule_series = [ + 'name' => '工程进度', + 'data' => [] + ]; + $complete_series = [ + 'name' => '完成总量', + 'data' => [] + ]; + $payment_series = [ + 'name' => '支付总量', + 'data' => [] + ]; + foreach ($column as &$v) { + $schedule_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('this_month_progress'); + $complete_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('total_amount'); + $payment_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('total_pay'); + $v = $v . '月'; } - - //项目月报统计 - public function month_report(){ - $year = $this->request->get('year',date('Y')); - //统计总的进度 - $total_schedule = SupervisionProjectMonthlyReport::sum('this_month_progress'); - //统计年度进度 - $year_schedule = SupervisionProjectMonthlyReport::whereYear('date',$year)->sum('this_month_progress'); - //统计总的完成 - $total_complete = SupervisionProjectMonthlyReport::sum('total_amount'); - //统计年度完成 - $year_complete = SupervisionProjectMonthlyReport::whereYear('date',$year)->sum('total_amount'); - //统计总的支付 - $total_payment = SupervisionProjectMonthlyReport::sum('total_pay'); - //统计年度支付 - $year_payment = SupervisionProjectMonthlyReport::whereYear('date',$year)->sum('total_pay'); - $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; - $schedule_series = [ - 'name' => '工程进度', - 'data' => [] - ]; - $complete_series = [ - 'name' => '完成总量', - 'data' => [] - ]; - $payment_series = [ - 'name' => '支付总量', - 'data' => [] - ]; - foreach($column as &$v){ - $schedule_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('this_month_progress'); - $complete_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('total_amount'); - $payment_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('total_pay'); - $v = $v.'月'; - } - $result = compact('total_schedule','year_schedule','total_complete','year_complete','total_payment','year_payment', - 'column','schedule_series','complete_series','payment_series'); - return $this->success('success',$result); + $result = compact( + 'total_schedule', + 'year_schedule', + 'total_complete', + 'year_complete', + 'total_payment', + 'year_payment', + 'column', + 'schedule_series', + 'complete_series', + 'payment_series' + ); + return $this->success('success', $result); + } + + public function invoice() + { + $year = $this->request->get('year', date('Y')); + $contract_ids = SupervisionProject::column('contract'); + //总开票金额 + $total_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->sum('apply_amount'); + //年度开票金额 + $year_invoice_amount = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereYear('create_time', $year)->sum('apply_amount'); + //总到账金额 + $total_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->sum('amount'); + $year_refund_amount = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + //总结算金额 + $total_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->sum('amount'); + //年度结算金额 + $year_settlement_amount = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereYear('date', $year)->sum('amount'); + $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']; + $invoice_series = [ + 'name' => '开票金额', + 'data' => [] + ]; + $refund_series = [ + 'name' => '到账金额', + 'data' => [] + ]; + $settlement_series = [ + 'name' => '结算金额', + 'data' => [] + ]; + foreach ($column as &$v) { + $invoice_series['data'][] = FinancialInvoice::where('contract_id', 'in', $contract_ids)->whereMonth('create_time', $year . '-' . $v)->sum('apply_amount'); + $refund_series['data'][] = FinancialRefund::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $settlement_series['data'][] = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount'); + $v = $v . '月'; } - - public function invoice(){ - $year = $this->request->get('year',date('Y')); - $contract_ids = SupervisionProject::column('contract'); - //总开票金额 - $total_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->sum('apply_amount'); - //年度开票金额 - $year_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->whereYear('create_time',$year)->sum('apply_amount'); - //总到账金额 - $total_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->sum('amount'); - $year_refund_amount = FinancialRefund::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - //总结算金额 - $total_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->sum('amount'); - //年度结算金额 - $year_settlement_amount = FinancialSettlement::where('contract_id','in',$contract_ids)->whereYear('date',$year)->sum('amount'); - $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; - $invoice_series = [ - 'name' => '开票金额', - 'data' => [] - ]; - $refund_series = [ - 'name' => '到账金额', - 'data' => [] - ]; - $settlement_series = [ - 'name' => '结算金额', - 'data' => [] - ]; - foreach($column as &$v){ - $invoice_series['data'][] = FinancialInvoice::where('contract_id','in',$contract_ids)->whereMonth('create_time',$year.'-'.$v)->sum('apply_amount'); - $refund_series['data'][] = FinancialRefund::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $settlement_series['data'][] = FinancialSettlement::where('contract_id','in',$contract_ids)->whereMonth('date',$year.'-'.$v)->sum('amount'); - $v = $v.'月'; - } - $result = compact('total_invoice_amount','year_invoice_amount','total_refund_amount','year_refund_amount','total_settlement_amount','year_settlement_amount', - 'column','invoice_series','refund_series','settlement_series'); - return $this->success('success',$result); - } - } \ No newline at end of file + $result = compact( + 'total_invoice_amount', + 'year_invoice_amount', + 'total_refund_amount', + 'year_refund_amount', + 'total_settlement_amount', + 'year_settlement_amount', + 'column', + 'invoice_series', + 'refund_series', + 'settlement_series' + ); + return $this->success('success', $result); + } +} diff --git a/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php b/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php index cdb1b27be..7655fad30 100644 --- a/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php +++ b/app/adminapi/logic/consult_basic/ConsultStatisticsLogic.php @@ -1,12 +1,79 @@ consultStatistics($param); + $data = []; + $datearr = explode('-', $time); + $time = TimeConvert(['start_time' => $datearr[0], 'end_time' => $datearr[1]]); + $marketingContract = new MarketingContract(); + $consultProject = new ConsultProject(); + $financialInvoice = new FinancialInvoice(); + $financialRefund = new FinancialRefund(); + $financialSettlement = new FinancialSettlement(); + + $total_apply_amount = $marketingContract->statistics_count([], $time, 'sum', ''); + $apply_amount_value = $marketingContract->statistics_count([], $time, 'group', 'create_time'); + $data[] = [ + 'title' => '待立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + $total_apply_amount = $consultProject->statistics_count([], $time, 'sum', ''); + $apply_amount_value = $consultProject->statistics_count([], $time, 'group', 'create_time'); + $data[] = [ + 'title' => '已立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + + + $contract_ids = $consultProject->column('contract'); + //开票金额 + $where[]=['contract_id','in',$contract_ids]; + $total_apply_amount = $financialInvoice->ContractFinancialMoney($where, $time, 'sum', '', 'apply_amount'); + $apply_amount_value = $financialInvoice->ContractFinancialMoney($where, $time, 'group', 'create_time', 'apply_amount'); + $data[] = [ + 'title' => '开票金额', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + //回款金额 + $total_amount = $financialRefund->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialRefund->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '回款金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + //结算金额 + $total_amount = $financialSettlement->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialSettlement->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '结算金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + return $data; } } - diff --git a/app/adminapi/logic/financial/FinancialStatisticsLogic.php b/app/adminapi/logic/financial/FinancialStatisticsLogic.php index bd6811364..4ba04c002 100644 --- a/app/adminapi/logic/financial/FinancialStatisticsLogic.php +++ b/app/adminapi/logic/financial/FinancialStatisticsLogic.php @@ -72,7 +72,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '保证金申请', 'desc' => '', 'total_money' => $total_bid_margin, - 'value' => $bid_margin_value['y'], + 'value' => $bid_margin_value['y']??[], 'type' => 1, ]; //保证金回收 @@ -82,7 +82,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '保证金回收', 'desc' => '', 'total_money' => $total_pay_amount, - 'value' => $pay_amount_value['y'], + 'value' => $pay_amount_value['y']??[], 'type' => 1, ]; //履约申请 @@ -92,7 +92,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '履约申请', 'desc' => '', 'total_money' => $apply_amount, - 'value' => $apply_amount_value['y'], + 'value' => $apply_amount_value['y']??[], 'type' => 1, ]; //履约回收 @@ -102,7 +102,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '履约回收', 'desc' => '', 'total_money' => $recovery_amount, - 'value' => $recovery_amount_value['y'], + 'value' => $recovery_amount_value['y']??[], 'type' => 1, ]; //用款 @@ -112,7 +112,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '用款', 'desc' => '', 'total_money' => $has_pay_amount, - 'value' => $has_pay_amount_value['y'], + 'value' => $has_pay_amount_value['y']??[], 'type' => 1, ]; //借款 @@ -122,7 +122,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '借款', 'desc' => '', 'total_money' => $amount, - 'value' => $amount_value['y'], + 'value' => $amount_value['y']??[], 'type' => 1, ]; //还款 @@ -132,7 +132,7 @@ class FinancialStatisticsLogic extends BaseLogic 'title' => '还款', 'desc' => '', 'total_money' => $amount, - 'value' => $amount_value['y'], + 'value' => $amount_value['y']??[], 'type' => 1, ]; return $data; diff --git a/app/adminapi/logic/manage_basic/ManageStatisticsLogic.php b/app/adminapi/logic/manage_basic/ManageStatisticsLogic.php new file mode 100644 index 000000000..d1d419033 --- /dev/null +++ b/app/adminapi/logic/manage_basic/ManageStatisticsLogic.php @@ -0,0 +1,93 @@ + $datearr[0], 'end_time' => $datearr[1]]); + $marketingContract = new MarketingContract(); + $consultProject = new ConsultProject(); + + $financialInvoice = new FinancialInvoice(); + $financialRefund = new FinancialRefund(); + $financialSettlement = new FinancialSettlement(); + + $where_1=[ + ['review_status', '=', 1], + ['contract_type', '=', 0], + ['business_nature', '=', 2], + ['status', '=', 0] + ]; + $total_apply_amount = $marketingContract->statistics_count($where_1, $time, 'sum', ''); + $apply_amount_value = $marketingContract->statistics_count($where_1, $time, 'group', 'create_time'); + $data[] = [ + 'title' => '待立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + $total_apply_amount = $consultProject->statistics_count([], $time, 'sum', ''); + $apply_amount_value = $consultProject->statistics_count([], $time, 'group', 'create_time'); + $data[] = [ + 'title' => '已立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + + $contract_ids = $consultProject->column('contract'); + //开票金额 + $where[]=['contract_id','in',$contract_ids]; + $total_apply_amount = $financialInvoice->ContractFinancialMoney($where, $time, 'sum', '', 'apply_amount'); + $apply_amount_value = $financialInvoice->ContractFinancialMoney($where, $time, 'group', 'create_time', 'apply_amount'); + $data[] = [ + 'title' => '开票金额', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + //回款金额 + $total_amount = $financialRefund->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialRefund->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '回款金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + //结算金额 + $total_amount = $financialSettlement->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialSettlement->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '结算金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + return $data; + } +} diff --git a/app/adminapi/logic/marketing/MarketingStatisticsLogic.php b/app/adminapi/logic/marketing/MarketingStatisticsLogic.php index a5d0dbb3b..64bb708f9 100644 --- a/app/adminapi/logic/marketing/MarketingStatisticsLogic.php +++ b/app/adminapi/logic/marketing/MarketingStatisticsLogic.php @@ -26,7 +26,7 @@ class MarketingStatisticsLogic extends BaseLogic 'title' => '主合同', 'desc' => '', 'total_money' => $total_contract_type_0, - 'value' => $total_contract_type_0_value['y'], + 'value' => $total_contract_type_0_value['y']??[], 'type' => 1, ]; // //统计框架协议 @@ -36,7 +36,7 @@ class MarketingStatisticsLogic extends BaseLogic 'title' => '框架协议', 'desc' => '', 'total_money' => $total_contract_type_1, - 'value' => $total_contract_type_1_value['y'], + 'value' => $total_contract_type_1_value['y']??[], 'type' => 1, ]; // //统计补充协议 @@ -46,7 +46,7 @@ class MarketingStatisticsLogic extends BaseLogic 'title' => '补充协议', 'desc' => '', 'total_money' => $total_contract_type_2, - 'value' => $total_contract_type_2_value['y'], + 'value' => $total_contract_type_2_value['y']??[], 'type' => 1, ]; //统计客户 @@ -67,7 +67,7 @@ class MarketingStatisticsLogic extends BaseLogic 'title' => $value, 'desc' => '', 'total_money' => $count, - 'value' => $y_value['y'], + 'value' => $y_value['y']??[], 'type' => 1, ]; } diff --git a/app/adminapi/logic/supervision_project/SupervisionProjectStatisticsLogic.php b/app/adminapi/logic/supervision_project/SupervisionProjectStatisticsLogic.php new file mode 100644 index 000000000..15550d4d0 --- /dev/null +++ b/app/adminapi/logic/supervision_project/SupervisionProjectStatisticsLogic.php @@ -0,0 +1,81 @@ + $datearr[0], 'end_time' => $datearr[1]]); + $marketingContract = new MarketingContract(); + $consultProject = new ConsultProject(); + $financialInvoice = new FinancialInvoice(); + $financialRefund = new FinancialRefund(); + $financialSettlement = new FinancialSettlement(); + + $total_apply_amount = $marketingContract->statistics_count([], $time, 'sum', ''); + $apply_amount_value = $marketingContract->statistics_count([], $time, 'group', 'create_time'); + $data[] = [ + 'title' => '待立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + $total_apply_amount = $consultProject->statistics_count([], $time, 'sum', ''); + $apply_amount_value = $consultProject->statistics_count([], $time, 'group', 'create_time'); + $data[] = [ + 'title' => '已立项项目', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + $problem_cate = DictData::where('type_value', 'problem_cate')->column('name', 'value'); + + + $contract_ids = $consultProject->column('contract'); + //开票金额 + $where[]=['contract_id','in',$contract_ids]; + $total_apply_amount = $financialInvoice->ContractFinancialMoney($where, $time, 'sum', '', 'apply_amount'); + $apply_amount_value = $financialInvoice->ContractFinancialMoney($where, $time, 'group', 'create_time', 'apply_amount'); + $data[] = [ + 'title' => '开票金额', + 'desc' => '', + 'total_money' => $total_apply_amount, + 'value' => $apply_amount_value['y'] ?? 0, + 'type' => 1, + ]; + //回款金额 + $total_amount = $financialRefund->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialRefund->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '回款金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + //结算金额 + $total_amount = $financialSettlement->statistics($where, $time, 'sum', '', 'amount'); + $amount_value = $financialSettlement->statistics($where, $time, 'group', 'create_time', 'amount'); + $data[] = [ + 'title' => '结算金额', + 'desc' => '', + 'total_money' => $total_amount, + 'value' => $amount_value['y'] ?? 0, + 'type' => 1, + ]; + return $data; + } +} diff --git a/app/common/model/BaseModel.php b/app/common/model/BaseModel.php index c87bb8a37..722df1054 100755 --- a/app/common/model/BaseModel.php +++ b/app/common/model/BaseModel.php @@ -60,7 +60,7 @@ class BaseModel extends Model return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核'; } /** - * 统计 + * 统计sum */ public function statistics($where, $time, string $selectType, string $group = "", $sum = '') { @@ -74,7 +74,30 @@ class BaseModel extends Model $totalMoney = $this->getCurveData($where, $time, "sum($sum)", $group); break; default: - throw new \Exception($this->name.':selectType参数错误'); + throw new \Exception($this->name . ':selectType参数错误'); + } + + if ($group) { + $totalMoney = $this->trendYdata((array)$totalMoney, $time); + } + return $totalMoney; + } + /** + * 统计count + */ + public function statistics_count($where, $time, string $selectType, string $group = "",) + { + switch ($selectType) { + case "sum": + $totalMoney = $this->where($where)->when(isset($time), function ($query) use ($time) { + $query->whereBetweenTime('create_time', strtotime($time['start_time']), strtotime($time['end_time'])); + })->count(); + break; + case "group": + $totalMoney = $this->getCurveData($where, $time, "count(id)", $group); + break; + default: + throw new \Exception($this->name . ':selectType参数错误'); } if ($group) {