(Update: refactor code and improve statistics functions in ConsultStatisticsController, FinancialStatisticsController, BaseModel, FinancialBidMargin, FinancialBidMarginRecovery, and FinancialInvoice)

This commit is contained in:
mkm 2024-07-05 09:57:01 +08:00
parent 3a194a6547
commit 4f0252031f
8 changed files with 569 additions and 242 deletions

View File

@ -1,24 +1,35 @@
<?php <?php
namespace app\adminapi\controller\manage_basic; namespace app\adminapi\controller\manage_basic;
use app\adminapi\controller\BaseAdminController; use app\adminapi\controller\BaseAdminController;
use app\common\model\financial\FinancialInvoice; use app\adminapi\logic\manage_basic\ManageStatisticsLogic;
use app\common\model\financial\FinancialRefund; use app\common\model\financial\FinancialInvoice;
use app\common\model\financial\FinancialSettlement; use app\common\model\financial\FinancialRefund;
use app\common\model\manage_basic\ManageProject; use app\common\model\financial\FinancialSettlement;
use app\common\model\manage_invest\ManageMeteredPayment; use app\common\model\manage_basic\ManageProject;
use app\common\model\marketing\MarketingContract; use app\common\model\manage_invest\ManageMeteredPayment;
use app\common\model\marketing\MarketingContract;
class ManageStatisticsController extends BaseAdminController class ManageStatisticsController extends BaseAdminController
{
public function index()
{
$date = $this->request->get('date', '');
$where = [];
$time = getDay($date);
$res = ManageStatisticsLogic::ManageStatistics($where, $time);
return $this->data($res);
}
public function project()
{ {
public function project(){
//待立项项目 //待立项项目
$pending_project_num = MarketingContract::field('id')->where([ $pending_project_num = MarketingContract::field('id')->where([
['review_status','=', 1], ['review_status', '=', 1],
['contract_type','=',0], ['contract_type', '=', 0],
['business_nature','=',2], ['business_nature', '=', 2],
['status','=',0] ['status', '=', 0]
])->count(); ])->count();
//已立项项目 //已立项项目
$approved_project_num = ManageProject::field('id')->count(); $approved_project_num = ManageProject::field('id')->count();
@ -32,24 +43,25 @@
'value' => $approved_project_num 'value' => $approved_project_num
] ]
]; ];
return $this->success('success',$result); return $this->success('success', $result);
} }
public function invoice(){ public function invoice()
$year = $this->request->get('year',date('Y')); {
$year = $this->request->get('year', date('Y'));
$contract_ids = ManageProject::column('contract'); $contract_ids = ManageProject::column('contract');
//总开票金额 //总开票金额
$total_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->sum('apply_amount'); $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'); $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'); $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'); $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'); $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'); $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']; $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
$invoice_series = [ $invoice_series = [
'name' => '开票金额', 'name' => '开票金额',
'data' => [] 'data' => []
@ -62,28 +74,39 @@
'name' => '结算金额', 'name' => '结算金额',
'data' => [] 'data' => []
]; ];
foreach($column as &$v){ foreach ($column as &$v) {
$invoice_series['data'][] = FinancialInvoice::where('contract_id','in',$contract_ids)->whereMonth('create_time',$year.'-'.$v)->sum('apply_amount'); $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'); $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'); $settlement_series['data'][] = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount');
$v = $v.'月'; $v = $v . '月';
} }
$result = compact('total_invoice_amount','year_invoice_amount','total_refund_amount','year_refund_amount','total_settlement_amount','year_settlement_amount', $result = compact(
'column','invoice_series','refund_series','settlement_series'); 'total_invoice_amount',
return $this->success('success',$result); '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(){ public function metered_payment()
$year = $this->request->get('year',date('Y')); {
$year = $this->request->get('year', date('Y'));
//统计总的进度 //统计总的进度
$total_done = ManageMeteredPayment::sum('month_amount'); $total_done = ManageMeteredPayment::sum('month_amount');
//统计年度进度 //统计年度进度
$year_done = ManageMeteredPayment::whereYear('date',$year)->sum('month_amount'); $year_done = ManageMeteredPayment::whereYear('date', $year)->sum('month_amount');
//统计总的支付 //统计总的支付
$total_payment = ManageMeteredPayment::sum('month_pay'); $total_payment = ManageMeteredPayment::sum('month_pay');
//统计年度支付 //统计年度支付
$year_payment = ManageMeteredPayment::whereYear('date',$year)->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']; $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
$complete_series = [ $complete_series = [
'name' => '完成总量', 'name' => '完成总量',
'data' => [] 'data' => []
@ -92,13 +115,20 @@
'name' => '支付总量', 'name' => '支付总量',
'data' => [] 'data' => []
]; ];
foreach($column as &$v){ foreach ($column as &$v) {
$complete_series['data'][] = ManageMeteredPayment::whereMonth('date',$year.'-'.$v)->sum('month_amount'); $complete_series['data'][] = ManageMeteredPayment::whereMonth('date', $year . '-' . $v)->sum('month_amount');
$payment_series['data'][] = ManageMeteredPayment::whereMonth('date',$year.'-'.$v)->sum('month_pay'); $payment_series['data'][] = ManageMeteredPayment::whereMonth('date', $year . '-' . $v)->sum('month_pay');
$v = $v.'月'; $v = $v . '月';
}
$result = compact('total_done','year_done','total_payment','year_payment',
'column','complete_series','payment_series');
return $this->success('success',$result);
} }
$result = compact(
'total_done',
'year_done',
'total_payment',
'year_payment',
'column',
'complete_series',
'payment_series'
);
return $this->success('success', $result);
} }
}

View File

@ -1,27 +1,37 @@
<?php <?php
namespace app\adminapi\controller\supervision_project; namespace app\adminapi\controller\supervision_project;
use app\adminapi\controller\BaseAdminController; use app\adminapi\controller\BaseAdminController;
use app\common\model\dict\DictData; use app\adminapi\logic\supervision_project\SupervisionProjectStatisticsLogic;
use app\common\model\financial\FinancialInvoice; use app\common\model\dict\DictData;
use app\common\model\financial\FinancialRefund; use app\common\model\financial\FinancialInvoice;
use app\common\model\financial\FinancialSettlement; use app\common\model\financial\FinancialRefund;
use app\common\model\marketing\MarketingContract; use app\common\model\financial\FinancialSettlement;
use app\common\model\supervision_connect\SupervisionProjectMonthlyReport; use app\common\model\marketing\MarketingContract;
use app\common\model\supervision_project\SupervisionProject; use app\common\model\supervision_connect\SupervisionProjectMonthlyReport;
use app\common\model\supervision_work\SupervisionProblem; use app\common\model\supervision_project\SupervisionProject;
use app\common\model\supervision_work\SupervisionProblem;
class SupervisionStatisticsController extends BaseAdminController class SupervisionStatisticsController extends BaseAdminController
{
public function index()
{ {
$date = $this->request->get('date', '');
$where = [];
$time = getDay($date);
$res = SupervisionProjectStatisticsLogic::consultStatistics($where, $time);
return $this->data($res);
}
//项目立项统计 //项目立项统计
public function project(){ public function project()
{
//待立项项目 //待立项项目
$pending_project_num = MarketingContract::field('id')->where([ $pending_project_num = MarketingContract::field('id')->where([
['review_status','=', 1], ['review_status', '=', 1],
['contract_type','=',0], ['contract_type', '=', 0],
['business_nature','=',1], ['business_nature', '=', 1],
['status','=',0] ['status', '=', 0]
])->count(); ])->count();
//已立项项目 //已立项项目
$approved_project_num = SupervisionProject::field('id')->count(); $approved_project_num = SupervisionProject::field('id')->count();
@ -35,40 +45,42 @@
'value' => $approved_project_num 'value' => $approved_project_num
] ]
]; ];
return $this->success('success',$result); return $this->success('success', $result);
} }
//项目问题统计 //项目问题统计
public function problem(){ public function problem()
$problem_cate = DictData::where('type_value','problem_cate')->column('name','value'); {
$problem_cate = DictData::where('type_value', 'problem_cate')->column('name', 'value');
$data = []; $data = [];
foreach($problem_cate as $k=>$v){ foreach ($problem_cate as $k => $v) {
$count = SupervisionProblem::where('problem_cate',$k)->count(); $count = SupervisionProblem::where('problem_cate', $k)->count();
$data[] = [ $data[] = [
'name' => $v, 'name' => $v,
'value' => $count 'value' => $count
]; ];
} }
$result['data'] = $data; $result['data'] = $data;
return $this->success('success',$result); return $this->success('success', $result);
} }
//项目月报统计 //项目月报统计
public function month_report(){ public function month_report()
$year = $this->request->get('year',date('Y')); {
$year = $this->request->get('year', date('Y'));
//统计总的进度 //统计总的进度
$total_schedule = SupervisionProjectMonthlyReport::sum('this_month_progress'); $total_schedule = SupervisionProjectMonthlyReport::sum('this_month_progress');
//统计年度进度 //统计年度进度
$year_schedule = SupervisionProjectMonthlyReport::whereYear('date',$year)->sum('this_month_progress'); $year_schedule = SupervisionProjectMonthlyReport::whereYear('date', $year)->sum('this_month_progress');
//统计总的完成 //统计总的完成
$total_complete = SupervisionProjectMonthlyReport::sum('total_amount'); $total_complete = SupervisionProjectMonthlyReport::sum('total_amount');
//统计年度完成 //统计年度完成
$year_complete = SupervisionProjectMonthlyReport::whereYear('date',$year)->sum('total_amount'); $year_complete = SupervisionProjectMonthlyReport::whereYear('date', $year)->sum('total_amount');
//统计总的支付 //统计总的支付
$total_payment = SupervisionProjectMonthlyReport::sum('total_pay'); $total_payment = SupervisionProjectMonthlyReport::sum('total_pay');
//统计年度支付 //统计年度支付
$year_payment = SupervisionProjectMonthlyReport::whereYear('date',$year)->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']; $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
$schedule_series = [ $schedule_series = [
'name' => '工程进度', 'name' => '工程进度',
'data' => [] 'data' => []
@ -81,32 +93,43 @@
'name' => '支付总量', 'name' => '支付总量',
'data' => [] 'data' => []
]; ];
foreach($column as &$v){ foreach ($column as &$v) {
$schedule_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('this_month_progress'); $schedule_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('this_month_progress');
$complete_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('total_amount'); $complete_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('total_amount');
$payment_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date',$year.'-'.$v)->sum('total_pay'); $payment_series['data'][] = SupervisionProjectMonthlyReport::whereMonth('date', $year . '-' . $v)->sum('total_pay');
$v = $v.'月'; $v = $v . '月';
} }
$result = compact('total_schedule','year_schedule','total_complete','year_complete','total_payment','year_payment', $result = compact(
'column','schedule_series','complete_series','payment_series'); 'total_schedule',
return $this->success('success',$result); '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(){ public function invoice()
$year = $this->request->get('year',date('Y')); {
$year = $this->request->get('year', date('Y'));
$contract_ids = SupervisionProject::column('contract'); $contract_ids = SupervisionProject::column('contract');
//总开票金额 //总开票金额
$total_invoice_amount = FinancialInvoice::where('contract_id','in',$contract_ids)->sum('apply_amount'); $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'); $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'); $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'); $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'); $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'); $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']; $column = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'];
$invoice_series = [ $invoice_series = [
'name' => '开票金额', 'name' => '开票金额',
'data' => [] 'data' => []
@ -119,14 +142,24 @@
'name' => '结算金额', 'name' => '结算金额',
'data' => [] 'data' => []
]; ];
foreach($column as &$v){ foreach ($column as &$v) {
$invoice_series['data'][] = FinancialInvoice::where('contract_id','in',$contract_ids)->whereMonth('create_time',$year.'-'.$v)->sum('apply_amount'); $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'); $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'); $settlement_series['data'][] = FinancialSettlement::where('contract_id', 'in', $contract_ids)->whereMonth('date', $year . '-' . $v)->sum('amount');
$v = $v.'月'; $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);
} }
}

View File

@ -1,12 +1,79 @@
<?php <?php
namespace app\adminapi\logic\consult_basic; namespace app\adminapi\logic\consult_basic;
use app\common\logic\BaseLogic; use app\common\logic\BaseLogic;
use app\common\model\consult_basic\ConsultProject;
use app\common\model\financial\FinancialInvoice;
use app\common\model\financial\FinancialRefund;
use app\common\model\financial\FinancialSettlement;
use app\common\model\marketing\MarketingContract;
class ConsultStatisticsLogic extends BaseLogic class ConsultStatisticsLogic extends BaseLogic
{ {
public static function consultStatistics($param) public static function consultStatistics($where, $time)
{ {
return app('consult_basic')->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;
} }
} }

View File

@ -72,7 +72,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '保证金申请', 'title' => '保证金申请',
'desc' => '', 'desc' => '',
'total_money' => $total_bid_margin, 'total_money' => $total_bid_margin,
'value' => $bid_margin_value['y'], 'value' => $bid_margin_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//保证金回收 //保证金回收
@ -82,7 +82,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '保证金回收', 'title' => '保证金回收',
'desc' => '', 'desc' => '',
'total_money' => $total_pay_amount, 'total_money' => $total_pay_amount,
'value' => $pay_amount_value['y'], 'value' => $pay_amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//履约申请 //履约申请
@ -92,7 +92,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '履约申请', 'title' => '履约申请',
'desc' => '', 'desc' => '',
'total_money' => $apply_amount, 'total_money' => $apply_amount,
'value' => $apply_amount_value['y'], 'value' => $apply_amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//履约回收 //履约回收
@ -102,7 +102,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '履约回收', 'title' => '履约回收',
'desc' => '', 'desc' => '',
'total_money' => $recovery_amount, 'total_money' => $recovery_amount,
'value' => $recovery_amount_value['y'], 'value' => $recovery_amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//用款 //用款
@ -112,7 +112,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '用款', 'title' => '用款',
'desc' => '', 'desc' => '',
'total_money' => $has_pay_amount, 'total_money' => $has_pay_amount,
'value' => $has_pay_amount_value['y'], 'value' => $has_pay_amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//借款 //借款
@ -122,7 +122,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '借款', 'title' => '借款',
'desc' => '', 'desc' => '',
'total_money' => $amount, 'total_money' => $amount,
'value' => $amount_value['y'], 'value' => $amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//还款 //还款
@ -132,7 +132,7 @@ class FinancialStatisticsLogic extends BaseLogic
'title' => '还款', 'title' => '还款',
'desc' => '', 'desc' => '',
'total_money' => $amount, 'total_money' => $amount,
'value' => $amount_value['y'], 'value' => $amount_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
return $data; return $data;

View File

@ -0,0 +1,93 @@
<?php
namespace app\adminapi\logic\manage_basic;
use app\common\logic\BaseLogic;
use app\common\model\consult_basic\ConsultProject;
use app\common\model\financial\FinancialInvoice;
use app\common\model\financial\FinancialRefund;
use app\common\model\financial\FinancialSettlement;
use app\common\model\marketing\MarketingContract;
/**
* 项目管理--统计
* Class ManageStatisticsLogic
* @package app\adminapi\logic\manage_basic
*/
class ManageStatisticsLogic extends BaseLogic
{
public static function ManageStatistics($where, $time)
{
$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();
$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;
}
}

View File

@ -26,7 +26,7 @@ class MarketingStatisticsLogic extends BaseLogic
'title' => '主合同', 'title' => '主合同',
'desc' => '', 'desc' => '',
'total_money' => $total_contract_type_0, 'total_money' => $total_contract_type_0,
'value' => $total_contract_type_0_value['y'], 'value' => $total_contract_type_0_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
// //统计框架协议 // //统计框架协议
@ -36,7 +36,7 @@ class MarketingStatisticsLogic extends BaseLogic
'title' => '框架协议', 'title' => '框架协议',
'desc' => '', 'desc' => '',
'total_money' => $total_contract_type_1, 'total_money' => $total_contract_type_1,
'value' => $total_contract_type_1_value['y'], 'value' => $total_contract_type_1_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
// //统计补充协议 // //统计补充协议
@ -46,7 +46,7 @@ class MarketingStatisticsLogic extends BaseLogic
'title' => '补充协议', 'title' => '补充协议',
'desc' => '', 'desc' => '',
'total_money' => $total_contract_type_2, 'total_money' => $total_contract_type_2,
'value' => $total_contract_type_2_value['y'], 'value' => $total_contract_type_2_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
//统计客户 //统计客户
@ -67,7 +67,7 @@ class MarketingStatisticsLogic extends BaseLogic
'title' => $value, 'title' => $value,
'desc' => '', 'desc' => '',
'total_money' => $count, 'total_money' => $count,
'value' => $y_value['y'], 'value' => $y_value['y']??[],
'type' => 1, 'type' => 1,
]; ];
} }

View File

@ -0,0 +1,81 @@
<?php
namespace app\adminapi\logic\supervision_project;
use app\common\logic\BaseLogic;
use app\common\model\consult_basic\ConsultProject;
use app\common\model\dict\DictData;
use app\common\model\financial\FinancialInvoice;
use app\common\model\financial\FinancialRefund;
use app\common\model\financial\FinancialSettlement;
use app\common\model\marketing\MarketingContract;
class SupervisionProjectStatisticsLogic extends BaseLogic
{
public static function consultStatistics($where, $time)
{
$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,
];
$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;
}
}

View File

@ -60,7 +60,7 @@ class BaseModel extends Model
return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核'; return !empty($data['approve_check_status']) ? $dict[$data['approve_check_status']] : '待审核';
} }
/** /**
* 统计 * 统计sum
*/ */
public function statistics($where, $time, string $selectType, string $group = "", $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); $totalMoney = $this->getCurveData($where, $time, "sum($sum)", $group);
break; break;
default: 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) { if ($group) {