This commit is contained in:
weiz 2024-04-15 14:18:18 +08:00
parent 376eaefb1d
commit 92a5a1b1f8

View File

@ -0,0 +1,60 @@
<?php
namespace app\adminapi\controller\marketing;
use app\adminapi\controller\BaseAdminController;
use app\common\model\dept\Dept;
use app\common\model\marketing\MarketingContract;
use app\common\model\marketing\MarketingCustom;
use think\response\Json;
class MarketingCustomStatisticsController extends BaseAdminController
{
//客户成交报表
public function custom_deal(): Json
{
$column = [0 => '客户总数量', 1 => '已成交数量'];
$total = MarketingCustom::count();
$deal_total = MarketingContract::where('status', 1)->count();
$data = [
['name' => '客户总数量', 'value' => $total],
['name' => '已成交数量', 'value' => $deal_total]
];
return $this->success('success', compact('column', 'data'));
}
//每日客户成交金额
public function daily_deal_amount(): Json
{
$dates = range(strtotime('-6 days'), strtotime('now'), 86400);
$column = array_map(function ($timestamp) {
return date('Y-m-d', $timestamp);
}, $dates);
$data = [];
foreach ($column as $v) {
$count = MarketingContract::field('id')->where('status', 1)->where('create_time', 'between', [strtotime($v . ' 00:00:00'), strtotime($v . ' 23:59:59')])->sum('signed_amount');
$data[] = [
'name' => $v,
'value' => $count
];
}
return $this->success('success', compact('column', 'data'));
}
//部门成交金额统计表
public function dept_deal_statistics(): Json
{
$dept_ids = MarketingCustom::distinct(true)->column('dept_id');
$column = Dept::where('id', 'in', $dept_ids)->column('name', 'id');
$data = [];
foreach ($column as $k => $v) {
$custom_ids = MarketingCustom::where('dept_id', $k)->column('id');
$count = MarketingContract::field('id')->where('status', 1)->where('part_a', 'in', $custom_ids)->sum('signed_amount');
$data[] = [
'name' => $v,
'value' => $count
];
}
return $this->success('success', compact('column', 'data'));
}
}