engineering/app/adminapi/controller/statistics/StatisticsController.php
2024-01-21 11:43:51 +08:00

84 lines
2.5 KiB
PHP

<?php
namespace app\adminapi\controller\statistics;
use app\adminapi\controller\BaseAdminController;
use app\common\model\custom\Custom;
use app\common\model\custom\CustomerDemand;
use app\common\model\custom\CustomerDemandSolution;
use app\common\model\project\Competitor;
use app\common\model\project\Project;
use app\common\model\project\ProjectEstimate;
use app\common\model\project\ProjectFollowUp;
use app\common\model\project\ProjectInsuranceManagement;
use app\common\model\project\ProjectTypeSet;
use think\response\Json;
class StatisticsController extends BaseAdminController
{
//客户统计数据
public function customs(): 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'];
$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() {
}
}