98 lines
3.2 KiB
PHP
98 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace app\adminapi\controller\consult_basic;
|
|
|
|
use app\adminapi\controller\BaseAdminController;
|
|
use app\adminapi\logic\consult_basic\ConsultStatisticsLogic;
|
|
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 ConsultStatisticsController extends BaseAdminController
|
|
{
|
|
|
|
public function index()
|
|
{
|
|
$date = $this->request->get('date', '');
|
|
$where = [];
|
|
$time = getDay($date);
|
|
$res = ConsultStatisticsLogic::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', '=', 3],
|
|
['status', '=', 0]
|
|
])->count();
|
|
//已立项项目
|
|
$approved_project_num = ConsultProject::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 = ConsultProject::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);
|
|
}
|
|
}
|