From 92a5a1b1f808fa18c401a5608395c82a7ab491f8 Mon Sep 17 00:00:00 2001 From: weiz <736250432@qq.com> Date: Mon, 15 Apr 2024 14:18:18 +0800 Subject: [PATCH] update --- .../MarketingCustomStatisticsController.php | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 app/adminapi/controller/marketing/MarketingCustomStatisticsController.php diff --git a/app/adminapi/controller/marketing/MarketingCustomStatisticsController.php b/app/adminapi/controller/marketing/MarketingCustomStatisticsController.php new file mode 100644 index 000000000..a1064f1d1 --- /dev/null +++ b/app/adminapi/controller/marketing/MarketingCustomStatisticsController.php @@ -0,0 +1,60 @@ + '客户总数量', 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')); + } + } \ No newline at end of file