This commit is contained in:
weiz 2024-01-29 15:19:37 +08:00
parent ddcfe13594
commit 4a3de31f29

@ -0,0 +1,149 @@
<?php
namespace app\adminapi\controller\project;
use app\adminapi\controller\BaseAdminController;
use app\common\model\bid\BidBiddingDecision;
use app\common\model\bid\BidBuyBiddingDocument;
use app\common\model\bid\BidDocumentExamination;
use app\common\model\bid\BidResult;
use app\common\model\bid\BidSecurityApply;
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\contract\SubcontractingContract;
use app\common\model\contract\SubcontractingContractDetail;
use app\common\model\contract\SubcontractingContractNegotiation;
use app\common\model\custom\CustomerDemand;
use app\common\model\custom\CustomerDemandSolution;
use app\common\model\finance\FinanceInvoiceApply;
use app\common\model\finance\FinancePaymentApply;
use app\common\model\finance\FinancePaymentPlan;
use app\common\model\finance\FinanceReceiptRecord;
use app\common\model\finance\FinanceReturnedMoney;
use app\common\model\finance\FinanceReturnedRecord;
use app\common\model\project\Competitor;
use app\common\model\project\ProjectEstimate;
use app\common\model\project\ProjectFollowUp;
use app\common\model\project\ProjectSettlement;
use app\common\model\project\ProjectSubcontractSettlement;
use think\response\Json;
class ProjectStatisticsController extends BaseAdminController
{
//项目商务统计
public function business(): Json
{
$id = $this->request->get('project_id');
if(empty($id)){
return $this->fail('缺少必要参数');
}
//项目跟进
$follow_total = ProjectFollowUp::field('id')->where('project_id',$id)->count();
//项目需求
$demand_total = CustomerDemand::field('id')->where('project_id',$id)->count();
//项目方案
$solution_total = CustomerDemandSolution::field('id')->where('project_id',$id)->count();
//项目概算
$estimate_total = ProjectEstimate::field('id')->where('project_id',$id)->count();
//竞争对手
$competitor_total = Competitor::field('id')->where('project_id',$id)->count();
//投标决策
$decision_total = BidBiddingDecision::field('id')->where('project_id',$id)->count();
//购买标书
$document_total = BidBuyBiddingDocument::field('id')->where('project_id',$id)->count();
//标书审查
$document_ids = BidBuyBiddingDocument::where('project_id',$id)->column('id');
$examination_total = BidDocumentExamination::field('id')->where('project_id',$id)->where('buy_bidding_document_id','in',$document_ids)->count();
//中标项目
$successful_total = BidResult::field('id')->where('is_successful',1)->count();
//投标保证金
$decision_ids = BidSecurityApply::where('project_id',$id)->column('bidding_decision_id');
$security_amount = BidBiddingDecision::where('id','in',$decision_ids)->sum('margin_amount');
//已退保证金
$han_refund_security_amount = BidSecurityRefund::where('project_id',$id)->sum('refund_amount');
//未退保证金
$not_refund_security_amount = bcsub($security_amount,$han_refund_security_amount);
$result = compact('follow_total','demand_total','solution_total','estimate_total','competitor_total','decision_total','document_total','examination_total','successful_total','security_amount','han_refund_security_amount','not_refund_security_amount');
return $this->success('success',$result);
}
//项目合同统计
public function contracts(): Json
{
$id = $this->request->get('project_id');
if(empty($id)){
return $this->fail('缺少必要参数');
}
//项目合同金额
$project_contract_amount = Contract::where('project_id',$id)->sum('amount');
//项目合同洽商金额
$project_negotiation_amount = ContractNegotiation::where('project_id',$id)->sum('negotiation_amount');
//项目结算金额
$project_settlement_amount = ProjectSettlement::where('project_id',$id)->sum('settlement_amount');
//项目已开票金额
$project_invoicing_amount = FinanceInvoiceApply::where('project_id',$id)->sum('invoicing_amount');
//项目回款计划金额
$project_returned_plan_amount = FinanceReturnedMoney::where('project_id',$id)->sum('amount');
//项目回款金额
$project_returned_amount = FinanceReturnedRecord::where('project_id',$id)->sum('amount');
//项目未回款金额
$project_not_returned_amount = bcsub($project_returned_plan_amount,$project_returned_amount);
//项目回款比例
$project_returned_ratio = !empty($project_returned_plan_amount) ? number_format($project_returned_amount / $project_returned_plan_amount,2) : 0;
/*****************************************************************************************************************************************************************************************************************************************************************/
//分包合同金额
$subcontracting_contract_ids = SubcontractingContract::where('project_id',$id)->column('id');
$subcontracting_contract_amount = SubcontractingContractDetail::where('contract_id','in',$subcontracting_contract_ids)->sum('amount_including_tax');
//分包合同洽商金额
$subcontracting_negotiation_amount = SubcontractingContractNegotiation::where('project_id',$id)->sum('negotiation_amount');
//分包合同结算金额
$subcontracting_settlement_amount = ProjectSubcontractSettlement::where('project_id',$id)->sum('settlement_amount');
//分包合同收票金额
$subcontracting_invoicing_amount = FinanceReceiptRecord::where('project_id',$id)->where('contract_type',2)->sum('invoice_amount');
//分包合同付款计划金额
$subcontracting_payment_plan_amount = FinancePaymentPlan::where('project_id',$id)->where('contract_type',2)->sum('amount');
//分包合同付款金额
$subcontracting_payment_amount = FinancePaymentApply::where('project_id',$id)->where('contract_type',2)->sum('amount');
//分包合同未付款金额
$subcontracting_not_payment_amount = bcsub($subcontracting_payment_plan_amount,$subcontracting_payment_amount);
//分包合同付款比例
$subcontracting_payment_ratio = !empty($subcontracting_payment_plan_amount) ? number_format($subcontracting_payment_amount / $subcontracting_payment_plan_amount,2) : 0;
/*****************************************************************************************************************************************************************************************************************************************************************/
//采购合同金额
$procurement_contract_ids = ProcurementContract::where('project_id',$id)->column('id');
$procurement_contract_amount = ProcurementContractDetail::where('contract_id','in',$procurement_contract_ids)->sum('amount_including_tax');
//采购合同收票金额
$procurement_invoicing_amount = FinanceReceiptRecord::where('project_id',$id)->where('contract_type',1)->sum('invoice_amount');
//采购合同付款计划金额
$procurement_payment_plan_amount = FinancePaymentPlan::where('project_id',$id)->where('contract_type',1)->sum('amount');
//采购合同付款金额
$procurement_payment_amount = FinancePaymentApply::where('project_id',$id)->where('contract_type',1)->sum('amount');
//采购合同未付款金额
$procurement_not_payment_amount = bcsub($procurement_payment_plan_amount,$procurement_payment_amount);
//采购合同付款比例
$procurement_payment_ratio = !empty($procurement_payment_plan_amount) ? number_format($procurement_payment_amount / $procurement_payment_plan_amount,2) : 0;
//返回数据
$result = compact(
'project_contract_amount', 'project_negotiation_amount','project_settlement_amount','project_invoicing_amount','project_returned_amount','project_not_returned_amount','project_returned_ratio',
'subcontracting_contract_amount','subcontracting_negotiation_amount','subcontracting_settlement_amount','subcontracting_invoicing_amount','subcontracting_payment_amount','subcontracting_not_payment_amount','subcontracting_payment_ratio',
'procurement_contract_amount','procurement_invoicing_amount','procurement_payment_amount','procurement_not_payment_amount','procurement_payment_ratio'
);
return $this->success('success',$result);
}
//项目预算统计
public function budget() {
$id = $this->request->get('project_id');
if(empty($id)){
return $this->fail('缺少必要参数');
}
$column = ['总预算','材料预算','分包预算','人工预算','费用预算','机具预算'];
halt();
}
}