request->get('year'); if(empty($year)){ $year = date('Y'); } $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; $series = [ 'name' => '客户数', 'data' => [] ]; foreach($column as &$v){ $month = $v; if($month < 10){ $month = '0'.$month; } $series['data'][] = Custom::field('id')->whereMonth('create_time', $year.'-'.$month)->count(); $v = $v.'月'; } $custom_total = Custom::field('id')->count(); $this_year_add = Custom::field('id')->whereYear('create_time',date('Y'))->count(); $result = [ 'column' => $column, 'series' => $series, 'custom_total' => $custom_total, 'this_year_add' => $this_year_add ]; return $this->success('success',$result); } //项目立项 public function projectInitiation(): Json { //立项总数 $project_total = Project::field('id')->count(); //项目跟进 $follow_total = ProjectFollowUp::field('id')->count(); //项目需求 $demand_total = CustomerDemand::field('id')->count(); //项目方案 $solution_total = CustomerDemandSolution::field('id')->count(); //项目概算 $estimate_total = ProjectEstimate::field('id')->count(); //竞争对手 $competitor_total = Competitor::field('id')->count(); //获取项目类型 $project_type = ProjectTypeSet::field('id,name')->select()->toArray(); $data = []; foreach($project_type as $v){ $count = Project::field('id')->where('project_type',$v['id'])->count(); $data[] = [ 'name' => $v['name'], 'value' => $count ]; } $result = compact('project_total','follow_total','demand_total','solution_total','estimate_total','competitor_total'); $result['data'] = $data; return $this->success('success',$result); } //投标统计 public function bidding(): Json { //投标决策 $decision = BidBiddingDecision::field('id')->count(); //购买标书 $document = BidBuyBiddingDocument::field('id')->count(); //标书审查 $examination = BidDocumentExamination::field('id')->count(); //中标项目 $successful = BidResult::field('id')->where('is_successful',1)->count(); //中标率 $bidding_rate = !empty($decision) ? number_format($successful / $decision,2) : 0; //总的投标保证金金额 $total_margin_amount = BidBiddingDecision::where('is_margin',1)->sum('margin_amount'); //已退保证金金额 $return_margin_amount = BidSecurityRefund::sum('refund_amount'); //未退保证金金额 $not_return_margin_amount = ($total_margin_amount - $return_margin_amount) > 0 ? $total_margin_amount - $return_margin_amount : 0; //返回 return $this->success('success',compact('decision','document','examination','successful','bidding_rate','not_return_margin_amount')); } //项目合同 public function contracts(): Json { $year = $this->request->get('year'); if(empty($year)){ $year = date('Y'); } //合同总数 $total_num = Contract::field('id')->count(); //签约总金额 $sign_total_amount = Contract::sum('amount'); //洽商金额 $total_negotiate_amount = ContractNegotiation::sum('negotiation_amount'); //年度合同总数 $year_total_num = Contract::field('id')->whereYear('contract_date',$year)->count(); //年度签约合同总金额 $year_total_sign_amount = Contract::whereYear('contract_date',$year)->sum('amount'); //年度签约合同id $year_sign_contract_ids = Contract::field('id')->whereYear('contract_date',$year)->column('id'); //年度洽商金额 $year_total_negotiate_amount = ContractNegotiation::where('contract_id','in',$year_sign_contract_ids)->sum('negotiation_amount'); $column = ['1','2','3','4','5','6','7','8','9','10','11','12']; $series = [ 'name' => '合同金额', 'data' => [] ]; foreach($column as &$v){ $month = $v; if($month < 10){ $month = '0'.$month; } $sign_amount = Contract::whereMonth('contract_date', $year.'-'.$month)->sum('amount'); $contract_ids = Contract::whereMonth('contract_date', $year.'-'.$month)->column('id'); $negotiate_amount = ContractNegotiation::where('contract_id','in',$contract_ids)->sum('negotiation_amount'); $series['data'][] = $sign_amount + $negotiate_amount; $v = $v.'月'; } $result = [ 'total_num' => $total_num, 'total_amount' => $sign_total_amount + $total_negotiate_amount, 'total_negotiate_amount' => $total_negotiate_amount, 'year_total_num' => $year_total_num, 'year_total_amount' => $year_total_sign_amount + $year_total_negotiate_amount, 'column' => $column, 'series' => $series ]; return $this->success('success',$result); } //项目回款 public function projectRefund(): 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']; //年度开票金额 $year_invoicing_amount = FinanceInvoiceApply::whereYear('invoicing_date',$year)->sum('invoicing_amount'); //年度回款计划金额 $year_refund_plan_amount = FinanceReturnedMoney::whereYear('return_date',$year)->sum('amount'); //年度回款金额 $year_refund_amount = FinanceReturnedRecord::whereYear('return_date',$year)->sum('amount'); $year_not_refund_amount= bcsub($year_refund_plan_amount,$year_refund_amount); $invoice_series = [ 'name' => '开票金额', 'data' => [] ]; $refund_plan_series = [ 'name' => '回款计划金额', 'data' => [] ]; $refund_series = [ 'name' => '回款金额', 'data' => [] ]; $not_refund_series = [ 'name' => '未回款金额', 'data' => [] ]; foreach($column as &$v){ $month = $v; if($month < 10){ $month = '0'.$month; } $invoice_series['data'][] = FinanceInvoiceApply::whereMonth('invoicing_date',$year.'-'.$month)->sum('invoicing_amount'); $refund_plan = FinanceReturnedMoney::whereMonth('return_date',$year.'-'.$month)->sum('amount'); $refund = FinanceReturnedRecord::whereMonth('return_date',$year.'-'.$month)->sum('amount'); $refund_plan_series['data'][] = $refund_plan; $refund_series['data'][] = $refund; $not_refund_series['data'][] = $refund_plan - $refund; $v = $v.'月'; } $result = [ 'year_invoicing_amount' => $year_invoicing_amount, 'year_refund_plan_amount' => $year_refund_plan_amount, 'year_refund_amount' => $year_refund_amount, 'year_not_refund_amount' => $year_not_refund_amount, 'invoice_series' => $invoice_series, 'refund_plan_series' => $refund_plan_series, 'refund_series' => $refund_series, 'not_refund_series' => $not_refund_series, 'column' => $column, ]; return $this->success('success',$result); } //采购合同 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(): 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 = SubcontractingContract::field('id')->count(); //合同签约总金额 $total_sign_amount = SubcontractingContractDetail::sum('amount_including_tax'); //合同洽商金额 $total_negotiation_amount = SubcontractingContractNegotiation::sum('negotiation_amount'); //合同总金额 $total_amount = $total_sign_amount + $total_negotiation_amount; //年度合同总数 $year_total_num = SubcontractingContract::field('id')->whereYear('signing_date',$year)->count(); //年度合同id $year_subcontracting_contract_ids = SubcontractingContract::whereYear('signing_date',$year)->column('id'); //年度合同签约金额 $year_total_sign_amount = SubcontractingContractDetail::where('contract_id','in',$year_subcontracting_contract_ids)->sum('amount_including_tax'); //年度合同洽商金额 $year_total_negotiation_amount = SubcontractingContractNegotiation::where('subcontracting_contract_id','in',$year_subcontracting_contract_ids)->sum('negotiation_amount'); //年度合同总金额 $year_total_amount = $year_total_sign_amount + $year_total_negotiation_amount; $series = [ 'name' => '合同金额', 'data' => [] ]; foreach($column as &$v){ $month = $v; if($month < 10){ $month = '0'.$month; } $month_subcontracting_contract_ids = SubcontractingContract::whereMonth('signing_date',$year.'-'.$month)->column('id'); //月度合同签约金额 $month_total_sign_amount = SubcontractingContractDetail::where('contract_id','in',$month_subcontracting_contract_ids)->sum('amount_including_tax'); //月度合同洽商金额 $month_total_negotiation_amount = SubcontractingContractNegotiation::where('subcontracting_contract_id','in',$month_subcontracting_contract_ids)->sum('negotiation_amount'); $series['data'][] = $month_total_sign_amount + $month_total_negotiation_amount; $v = $v.'月'; } $result = [ 'total_num' => $total_num, 'total_amount' => $total_amount, 'total_negotiation_amount' => $total_negotiation_amount, 'year_total_num' => $year_total_num, 'year_total_amount' => $year_total_amount, 'column' => $column, 'series' => $series, ]; return $this->success('success',$result); } //项目付款 public function projectPayment(): 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']; //年度收票金额 $year_invoicing_amount = FinanceReceiptRecord::whereYear('invoicing_date',$year)->sum('invoice_amount'); //年度付款计划金额 $year_payment_plan_amount = FinancePaymentPlan::whereYear('pay_date',$year)->sum('amount'); //年度付款金额 $year_payment_amount = FinancePaymentApply::whereYear('pay_date',$year)->sum('amount'); $invoice_series = [ 'name' => '收票金额', 'data' => [] ]; $payment_plan_series = [ 'name' => '付款计划金额', 'data' => [] ]; $payment_series = [ 'name' => '付款金额', 'data' => [] ]; foreach($column as &$v){ $month = $v; if($month < 10){ $month = '0'.$month; } $invoice_series['data'][] = FinanceReceiptRecord::whereMonth('invoicing_date',$year.'-'.$month)->sum('invoice_amount'); $payment_plan_series['data'][] = FinancePaymentPlan::whereMonth('pay_date',$year.'-'.$month)->sum('amount'); $payment_series['data'][] = FinancePaymentApply::whereMonth('pay_date',$year.'-'.$month)->sum('amount'); $v = $v.'月'; } $result = [ 'year_invoicing_amount' => $year_invoicing_amount, 'year_payment_plan_amount' => $year_payment_plan_amount, 'year_payment_amount' => $year_payment_amount, 'invoice_series' => $invoice_series, 'payment_plan_series' => $payment_plan_series, 'payment_series' => $payment_series, 'column' => $column, ]; return $this->success('success',$result); } }