stats_805

This commit is contained in:
dengbw
2022-08-05 15:49:11 +08:00
committed by lccsw
parent e3b4a47e55
commit 955f0bd27c
2 changed files with 456 additions and 0 deletions
+195
View File
@@ -0,0 +1,195 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class order extends HD_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('receiver/order/receiver_orders_v2_model', 'mdOrders');
$this->load->model('receiver/receiver_customers_model', 'mdCustomers');
$this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog');
}
//首页信息
public function index()
{
return $this->get_dashboards();
}
public function get_dashboards()
{
$params = $this->input->get();
$this->data['params'] = $params;
$brands = [1 => '东风ev', 5 => '哪吒', 4 => '零跑'];//1,4,5
$days = ['2022-07' => ['month' => 7, 'num' => 0], '2022-06' => ['month' => 6, 'num' => 0],
'2022-05' => ['month' => 5, 'num' => 0], '2022-04' => ['month' => 4, 'num' => 0]];
$bizs = [1 => ['biz_name' => '厦门东风', 'rowspan' => 1], 78 => ['biz_name' => '晋江东风'], 110 => ['biz_name' => '福州东风']];//20,99,55
foreach ($bizs as $k => $v) {
$list = [];
foreach ($days as $k2 => $v2) {
$time = $this->getTime($k2);
$num = $this->mdOrders->count(['biz_id' => $k, 'status>=' => 0, 'bill_time>=' => $time['s_time'], 'bill_time<=' => $time['e_time']]);
$list[$k2] = $num;
$days[$k2]['num'] = $v2['num'] + $num;
}
$v['list'] = $list;
$bizs[$k] = $v;
}
$brands_stats = $customers_stats = $process = [];
foreach ($bizs as $k => $v) {
$list = [];
foreach ($brands as $k2 => $v2) {
$stats_per = $stats = [];
foreach ($days as $k3 => $v3) {
$time = $this->getTime($k3);
$num = $this->mdOrders->count(['biz_id' => $k, 'brand_id' => $k2, 'status>=' => 0, 'bill_time>=' => $time['s_time'], 'bill_time<=' => $time['e_time']]);
$stats_per[] = $this->getPercentage(['num' => $num, 'sum' => $v['list'][$k3]]);
$stats[] = $num;
}
$list[] = ['brand_name' => $v2, 'stats_per' => $stats_per, 'stats' => $stats];
}
$brands_stats[] = ['biz_name' => $v['biz_name'], 'list' => $list];
}
$offlineSources = $this->mdCustomers->offlineSources();
$offlineSources_count = count($offlineSources);
//线索成交情况
foreach ($bizs as $k => $v) {
$list = $cus_sum = $ord_sum = $cus_per = [];
$cus_1 = $ord_1 = [];//自然到店
foreach ($offlineSources as $k2 => $v2) {
$stats_per_cus = $stats_cus = $stats_per_ord = $stats_ord = [];
foreach ($days as $k3 => $v3) {
$c_time = $this->getTime($k3, 1);
$bill_time = $this->getTime($k3);
$num_cus = $this->mdCustomers->count(['biz_id' => $k, 'of_id' => $k2, 'status>=' => 0, 'c_time>=' => $c_time['s_time'], 'c_time<=' => $c_time['e_time']]);
$num_ord = $this->mdOrders->count([
"customer_id in(select id from lc_receiver_customers where biz_id={$k} and of_id={$k2} and status>=0)" => null,
'biz_id' => $k, 'status>=' => 0, 'bill_time>=' => $bill_time['s_time'], 'bill_time<=' => $bill_time['e_time']]);
$cus_sum[$k3] += $num_cus;
$ord_sum[$k3] += $num_ord;
$stats_cus[] = $num_cus;
$stats_ord[$k3] = $num_ord;
$stats_per_cus[] = $this->getPercentage(['num' => $num_ord, 'sum' => $num_cus]);
$stats_per_ord[$k3] = '0.00';
if ($k2 == 1) {//自然到店
$cus_1[$k3] = $num_cus;
$ord_1[$k3] = $num_ord;
}
}
$list[] = ['name' => "{$v2['name']}(转化率)", 'type' => 1, 'stats_per' => $stats_per_cus, 'stats' => $stats_cus];
$list[] = ['name' => "{$v2['name']}(订单占比)", 'type' => 2, 'stats_per' => $stats_per_ord, 'stats' => $stats_ord];
}
foreach ($days as $k3 => $v3) {
$ord = $ord_1[$k3] ? $ord_sum[$k3] - $ord_1[$k3] : $ord_sum[$k3];
$cus = $cus_1[$k3] ? $cus_sum[$k3] - $cus_1[$k3] : $cus_sum[$k3];
$cus_per[] = $this->getPercentage(['num' => $ord, 'sum' => $cus]);
}
$customers_stats[] = ['biz_name' => $v['biz_name'], 'cus_sum' => $cus_sum, 'ord_sum' => $ord_sum, 'cus_per' => $cus_per, 'list' => $list];
}
//过程数据
$process_cus = $process_into = $process_ord = [];
foreach ($bizs as $k => $v) {
$list_cus = $cus_sum = $list_into = $ord_into = $into_sum = $list_ord = $ord_sum = [];
foreach ($offlineSources as $k2 => $v2) {
$stats_per_cus = $stats_cus = $stats_per_into = $stats_into = $stats_per_ord = $stats_ord = [];
foreach ($days as $k3 => $v3) {
//线索数
if ($k2 != 1) {//不包括自然到店
$c_time = $this->getTime($k3, 1);
$num_cus = $this->mdCustomers->count(['biz_id' => $k, 'of_id' => $k2, 'status>=' => 0, 'c_time>=' => $c_time['s_time'], 'c_time<=' => $c_time['e_time']]);
$stats_cus[] = $num_cus;
$cus_sum[$k3] += $num_cus;
$stats_per_cus[$k3] = $num_cus;
}
//进店数
$log_date = $this->getTime($k3, 2);
$sum = $this->mdUsersLog->sum("customer_{$k2}", ['biz_id' => $k, 'log_date>=' => $log_date['s_time'], 'log_date<=' => $log_date['e_time']]);
$num_into = intval($sum["customer_{$k2}"]);
$stats_into[] = $num_into;
$into_sum[$k3] += $num_into;
$stats_per_into[$k3] = $num_into;
//成交数
$bill_time = $this->getTime($k3);
$num_ord = $this->mdOrders->count([
"customer_id in(select id from lc_receiver_customers where biz_id={$k} and of_id={$k2} and status>=0)" => null,
'biz_id' => $k, 'status>=' => 0, 'bill_time>=' => $bill_time['s_time'], 'bill_time<=' => $bill_time['e_time']]);
$stats_ord[] = $num_ord;
$ord_sum[$k3] += $num_ord;
$stats_per_ord[$k3] = $num_ord;
}
if ($k2 != 1) {//不包括自然到店
$list_cus[] = ['name' => $v2['name'], 'stats_per' => $stats_per_cus, 'stats' => $stats_cus];
}
$list_into[] = ['name' => $v2['name'], 'stats_per' => $stats_per_into, 'stats' => $stats_into];
$list_ord[] = ['name' => $v2['name'], 'stats_per' => $stats_per_ord, 'stats' => $stats_ord];
}
$process_cus[] = ['biz_name' => $v['biz_name'], 'num_sum' => $cus_sum, 'list' => $list_cus];
$process_into[] = ['biz_name' => $v['biz_name'], 'num_sum' => $into_sum, 'list' => $list_into];
$process_ord[] = ['biz_name' => $v['biz_name'], 'num_sum' => $ord_sum, 'list' => $list_ord];
}
$process = ['customers' => $process_cus, 'into_shop' => $process_into, 'orders' => $process_ord];
$this->data['info'] = ['days' => $days, 'bizs' => $bizs, 'bizs_count' => count($bizs), 'days_count' => count($days)
, 'brands_count' => count($brands), 'offlineSources_count' => $offlineSources_count, 'brands_stats' => $brands_stats
, 'customers_stats' => $customers_stats, 'process' => $process];
$this->data['_title'] = '东风品牌店群';
return $this->show_view('stats/order/dashboards', true);
}
private function getPercentage($params)
{
return number_format_com($params['num'] / $params['sum'] * 100, 2, '') . "";
}
private function getTime($day, $type = 0)
{
$s_time = "{$day}-01 00:00:00";//本月一日
$e_time = date('Y-m-d', strtotime("$s_time +1 month -1 day")) . ' 23:59:59';//本月最后一日
if ($type == 1) {
$s_time = strtotime($s_time);
$e_time = strtotime($e_time);
} else if ($type == 2) {
$s_time = "{$day}-01";
$e_time = date('Y-m-d', strtotime("$s_time +1 month -1 day"));
}
return ['s_time' => $s_time, 'e_time' => $e_time];
}
//数据列表
public function lists()
{
}
//展示单条数据
public function get()
{
}
//添加单条数据
public function add()
{
}
//编辑单条数据
public function edit()
{
}
//删除单条数据
public function del()
{
}
//批量操作(默认修改状态)
public function batch()
{
}
//导出数据列表
public function export()
{
}
}
+261
View File
@@ -0,0 +1,261 @@
<div class="coms-table-wrap mt10">
<form id="vue-app" class=" form-search coms-table-hd clearfix no-border" onsubmit="return false"
action="receiver/ownersTag">
<div class="am-form am-form-horizontal">
<div class="am-form-group fl">
<label class="am-para-label w80">统计月份:</label>
<div class="am-form-group fl">
<div class="am-para-inline w300">
<input id="id-bill-time" name="bill_time" type="text" value="<?= $params['bill_time'] ?>"
placeholder="统计月份范围" autocomplete="off"/>
</div>
</div>
</div>
<div class="am-form-group fl ml20">
<button type="submit" class="am-btn am-btn-success am-btn-sm w100">搜索</button>
</div>
</div>
</form>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
<thead>
<tr>
<th colspan="<?= $info['days_count'] + 3 ?>" width="50%" style="text-align: left;">目标完成情况</th>
<? foreach ($info['days'] as $v) { ?>
<th width="10%"><?= $v['month'] ?>月完成</th>
<? } ?>
</tr>
</thead>
<tbody>
<tr>
<td colspan="<?= $info['days_count'] + 3 ?>" align="left"><strong>本期的完成情况(订单台数)</strong></td>
<? foreach ($info['days'] as $v) { ?>
<td><strong><?= $v['num'] ?></strong></td>
<? } ?>
</tr>
<? foreach ($info['bizs'] as $v) { ?>
<tr>
<? if ($v['rowspan'] == 1) { ?>
<td rowspan="<?= $info['bizs_count'] ?>" class="td-middle">品牌店</td>
<? } ?>
<td colspan="<?= $info['days_count'] + 2 ?>"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $v2) { ?>
<td><?= $v2 ?></td>
<? } ?>
</tr>
<? } ?>
<tr>
<td rowspan="<?= $info['bizs_count'] * $info['brands_count'] + 1 ?>" class="td-middle">销售车型</td>
<td colspan="2">项目</td>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
</tr>
<? foreach ($info['brands_stats'] as $v) { ?>
<tr>
<td rowspan="<?= $info['brands_count'] ?>" class="td-middle"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $k2 => $v2) { ?>
<?= $k2 != 0 ? '<tr>' : '' ?>
<td><?= $v2['brand_name'] ?></td>
<? foreach ($v2['stats_per'] as $v3) { ?>
<td><?= $v3 ?></td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
<? } ?>
<?= $k2 != 0 ? '</tr>' : '' ?>
<? } ?>
</tr>
<? } ?>
</tbody>
</table>
<table class="am-table am-table-bordered" style="margin-top: 10px;">
<thead>
<tr>
<th colspan="<?= $info['days_count'] * 2 + 3 ?>">线索成交情况</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3" rowspan="2"></td>
<td colspan="<?= $info['days_count'] ?>">成交率</td>
<td colspan="<?= $info['days_count'] ?>">线索数/订单数</td>
</tr>
<tr>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
</tr>
<? foreach ($info['customers_stats'] as $k => $v) { ?>
<tr>
<? if ($k == 0) { ?>
<td rowspan="<?= ($info['offlineSources_count'] * 2 + 3) * $info['bizs_count'] ?>"
class="td-middle">线索成交率
</td>
<? } ?>
<td rowspan="<?= $info['offlineSources_count'] * 2 + 3 ?>"
class="td-middle"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $k2 => $v2) { ?>
<?= $k2 != 0 ? '<tr>' : '' ?>
<td align="left"><?= $v2['name'] ?></td>
<? foreach ($v2['stats_per'] as $k3 => $v3) { ?>
<? if ($v2['type'] == 2) { ?>
<td><?= number_format_com($v2['stats'][$k3] / $v['ord_sum'][$k3] * 100, 2, '') . "" ?></td>
<? } else { ?>
<td><?= $v3 ?></td>
<? } ?>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
<? } ?>
<?= $k2 != 0 ? '</tr>' : '' ?>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">线索数合计</td>
<? foreach ($v['cus_sum'] as $v5) { ?>
<td><?= $v5 ?></td>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">订单数合计</td>
<? foreach ($v['ord_sum'] as $v6) { ?>
<td><?= $v6 ?></td>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">线索成交率(不含自然到店)</td>
<? foreach ($v['cus_per'] as $v7) { ?>
<td><?= $v7 ?></td>
<? } ?>
</tr>
<? } ?>
</tbody>
</table>
<table class="am-table am-table-bordered" style="margin-top: 10px;">
<thead>
<tr>
<th colspan="<?= $info['days_count'] * 2 + 3 ?>">过程数据</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="17" class="td-middle">线索数</td>
<td colspan="2" rowspan="2"></td>
<td colspan="<?= $info['days_count'] ?>">转化率</td>
<td colspan="<?= $info['days_count'] ?>">数据</td>
</tr>
<tr>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
<? foreach ($info['days'] as $v) { ?>
<td><?= $v['month'] ?>月</td>
<? } ?>
</tr>
<? foreach ($info['process']['customers'] as $v) { ?>
<tr>
<td rowspan="<?= $info['offlineSources_count'] ?>" class="td-middle"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $k2 => $v2) { ?>
<?= $k2 != 0 ? '<tr>' : '' ?>
<td align="left"><?= $v2['name'] ?></td>
<? foreach ($v2['stats_per'] as $k3 => $v3) { ?>
<td><?= number_format_com($v3 / $v['num_sum'][$k3] * 100, 2, '') . "" ?> </td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
<? } ?>
<?= $k2 != 0 ? '</tr>' : '' ?>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">合计</td>
<? foreach ($v['num_sum'] as $v5) { ?>
<td><?= $v5 ?></td>
<? } ?>
</tr>
<? } ?>
<? foreach ($info['process']['into_shop'] as $k => $v) { ?>
<tr>
<? if ($k == 0) { ?>
<td rowspan="<?= ($info['offlineSources_count'] + 1) * $info['bizs_count'] ?>"
class="td-middle">进店数
</td>
<? } ?>
<td rowspan="<?= $info['offlineSources_count'] + 1 ?>" class="td-middle"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $k2 => $v2) { ?>
<?= $k2 != 0 ? '<tr>' : '' ?>
<td align="left"><?= $v2['name'] ?></td>
<? foreach ($v2['stats_per'] as $k3 => $v3) { ?>
<td><?= number_format_com($v3 / $v['num_sum'][$k3] * 100, 2, '') . "" ?> </td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
<? } ?>
<?= $k2 != 0 ? '</tr>' : '' ?>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">合计</td>
<? foreach ($v['num_sum'] as $v5) { ?>
<td><?= $v5 ?></td>
<? } ?>
</tr>
<? } ?>
<? foreach ($info['process']['orders'] as $k => $v) { ?>
<tr>
<? if ($k == 0) { ?>
<td rowspan="<?= ($info['offlineSources_count'] + 1) * $info['bizs_count'] ?>"
class="td-middle">成交数
</td>
<? } ?>
<td rowspan="<?= $info['offlineSources_count'] + 1 ?>" class="td-middle"><?= $v['biz_name'] ?></td>
<? foreach ($v['list'] as $k2 => $v2) { ?>
<?= $k2 != 0 ? '<tr>' : '' ?>
<td align="left"><?= $v2['name'] ?></td>
<? foreach ($v2['stats_per'] as $k3 => $v3) { ?>
<td><?= number_format_com($v3 / $v['num_sum'][$k3] * 100, 2, '') . "" ?> </td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
<? } ?>
<?= $k2 != 0 ? '</tr>' : '' ?>
<? } ?>
</tr>
<tr>
<td colspan="<?= $info['days_count'] + 1 ?>">合计</td>
<? foreach ($v['num_sum'] as $v5) { ?>
<td><?= $v5 ?></td>
<? } ?>
</tr>
<? } ?>
</tbody>
</table>
</div>
</div>
<script>
require(['laydate', 'autocomplete'], function (laydate) {
laydate.render({
elem: '#id-bill-time', range: '~', format: 'yyyy-MM', type: 'month',
});
});
</script>
<style>
.td-middle {
vertical-align: middle !important;
}
</style>