stats_809

This commit is contained in:
dengbw
2022-08-09 15:29:14 +08:00
parent 19f55ea06a
commit 0fb5b0c399
2 changed files with 183 additions and 27 deletions
+162 -22
View File
@@ -22,16 +22,44 @@ class order extends HD_Controller
public function get_dashboards()
{
$params = $this->input->get();
$this->data['params'] = $params;
!$params['type'] && $params['type'] = 1;
$start_date = date('Y-m', strtotime("-2 month"));//取最近3个月
$end_date = date('Y-m');
if ($params['time']) {
$time = explode(' ~ ', $params['time']);
$time[0] && $start_date = $time[0];
$time[1] && $end_date = $time[1];
} else {
$params['time'] = $start_date . ' ~ ' . $end_date;
}
$date_months = $this->dateMonths($start_date, $end_date);
rsort($date_months);
$days = [];
// $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]];
foreach ($date_months as $k => $v) {
$month = date('n', strtotime($v . '-01'));
$days[$v] = ['month' => $month, 'num' => 0];
}
$brands = [1 => '东风ev', 4 => '哪吒', 5 => '零跑'];//1,4,5 1,5,4
$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]];
//$brands = [1 => '东风ev', 5 => '哪吒', 4 => '零跑'];
$bizs = [20 => ['biz_name' => '厦门东风', 'rowspan' => 1], 99 => ['biz_name' => '晋江东风'], 55 => ['biz_name' => '福州东风']];//20,99,55 1,78,110
//$bizs = [1 => ['biz_name' => '厦门东风', 'rowspan' => 1], 78 => ['biz_name' => '晋江东风'], 110 => ['biz_name' => '福州东风']];
foreach ($bizs as $k => $v) {
$list = [];
foreach ($days as $k2 => $v2) {
$order_time = $this->getTime($k2);
$num = $this->mdOrders->count(['biz_id' => $k, 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
$c_time = $this->getTime($k2, 1);
if ($params['type'] == 2) {
$num = $this->mdOrders->count(['biz_id' => $k, 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
} else {
$num = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time']
, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']])
->count_all_results();
}
$list[$k2] = $num;
$days[$k2]['num'] = $v2['num'] + $num;
}
@@ -45,7 +73,17 @@ class order extends HD_Controller
$stats_per = $stats = [];
foreach ($days as $k3 => $v3) {
$order_time = $this->getTime($k3);
$num = $this->mdOrders->count(['biz_id' => $k, 'brand_id' => $k2, 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
$c_time = $this->getTime($k3, 1);
if ($params['type'] == 2) {
$num = $this->mdOrders->count(['biz_id' => $k, 'brand_id' => $k2, 'status>=' => 0, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
} else {
$num = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.brand_id' => $k2, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time']
, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']])
->count_all_results();
}
$stats_per[] = $this->getPercentage(['num' => $num, 'sum' => $v['list'][$k3]]);
$stats[] = $num;
}
@@ -65,9 +103,21 @@ class order extends HD_Controller
$c_time = $this->getTime($k3, 1);
$order_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, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
if ($params['type'] == 2) {
$num_ord = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time']
, 'a.order_time<=' => $order_time['e_time'], 'b.of_id' => $k2])
->count_all_results();
} else {
$num_ord = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time']
, 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']])
->count_all_results();
}
$cus_sum[$k3] += $num_cus;
$ord_sum[$k3] += $num_ord;
$stats_cus[] = $num_cus;
@@ -96,29 +146,59 @@ class order extends HD_Controller
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) {
$order_time = $this->getTime($k3);
$c_time = $this->getTime($k3, 1);
//线索数
$num_cus = 0;
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_cus[] = $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;
if ($params['type'] == 2) {
$num_into = $this->mdUsersLog->db->select('a.id')
->from('lc_receiver_customer_oplogs as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'],
'b.status>=' => 0, 'b.biz_id' => $k, 'b.of_id' => $k2])
->count_all_results();
} else {
$num_into = $this->mdUsersLog->db->select('a.id')
->from('lc_receiver_customer_oplogs as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.type' => 4, 'a.log' => '客户到店', 'a.c_time>=' => $c_time['s_time'], 'a.c_time<=' => $c_time['e_time'],
'b.status>=' => 0, 'b.biz_id' => $k, 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']])
->count_all_results();
}
$into_sum[$k3] += $num_into;
$stats_per_into[$k3] = $num_into;
$stats_into[] = $num_into;
$num_into_per = '';
if ($k2 != 1) {//转化率=进店数/客户数
$num_into_per = $this->getPercentage(['num' => $num_into, 'sum' => $num_cus]);
}
$stats_per_into[$k3] = $num_into_per;
//成交数
$order_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, 'order_time>=' => $order_time['s_time'], 'order_time<=' => $order_time['e_time']]);
$stats_ord[] = $num_ord;
if ($params['type'] == 2) {
$num_ord = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time']
, 'a.order_time<=' => $order_time['e_time'], 'b.of_id' => $k2])
->count_all_results();
} else {
$num_ord = $this->mdOrders->db->select('a.id')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
->where(['a.biz_id' => $k, 'a.status>=' => 0, 'a.order_time>=' => $order_time['s_time'], 'a.order_time<=' => $order_time['e_time']
, 'b.of_id' => $k2, 'b.c_time>=' => $c_time['s_time'], 'b.c_time<=' => $c_time['e_time']])
->count_all_results();
}
$ord_sum[$k3] += $num_ord;
$stats_per_ord[$k3] = $num_ord;
$stats_ord[] = $num_ord;
//转化率=订单数/进店数
$stats_per_ord[$k3] = $this->getPercentage(['num' => $num_ord, 'sum' => $num_into]);
}
if ($k2 != 1) {//不包括自然到店
$list_cus[] = ['name' => $v2['name'], 'stats_per' => $stats_per_cus, 'stats' => $stats_cus];
@@ -133,11 +213,71 @@ class order extends HD_Controller
$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];
, 'customers_stats' => $customers_stats, 'process' => $process, 'type_ary' => [1 => '仅限月线索销量模型', 2 => '月销量模型']];
$this->data['params'] = $params;
$this->data['_title'] = '东风品牌店群';
return $this->show_view('stats/order/dashboards', true);
}
/**
* Notes:计算出两个日期之间的月份
* Created on: 2022/8/9 14:38
* Created by: dengbw
* @param $start_date [开始日期,如2022-03]
* @param $end_date [结束日期,如2022-12]
* @param string $explode [年份和月份之间分隔符,此例为 - ]
* @param bool $addOne [算取完之后最后是否加一月,用于算取时间戳用]
* @return array [返回是两个月份之间所有月份字符串]
*/
private function dateMonths($start_date, $end_date, $explode = '-', $addOne = false)
{
//判断两个时间是不是需要调换顺序
$start_int = strtotime($start_date);
$end_int = strtotime($end_date);
if ($start_int > $end_int) {
$tmp = $start_date;
$start_date = $end_date;
$end_date = $tmp;
}
//结束时间月份+1,如果是13则为新年的一月份
$start_arr = explode($explode, $start_date);
$start_year = intval($start_arr[0]);
$start_month = intval($start_arr[1]);
$end_arr = explode($explode, $end_date);
$end_year = intval($end_arr[0]);
$end_month = intval($end_arr[1]);
$data = array();
$data[] = $start_date;
$tmp_month = $start_month;
$tmp_year = $start_year;
//如果起止不相等,一直循环
while (!(($tmp_month == $end_month) && ($tmp_year == $end_year))) {
$tmp_month++;
//超过十二月份,到新年的一月份
if ($tmp_month > 12) {
$tmp_month = 1;
$tmp_year++;
}
$data[] = $tmp_year . $explode . str_pad($tmp_month, 2, '0', STR_PAD_LEFT);
}
if ($addOne == true) {
$tmp_month++;
//超过十二月份,到新年的一月份
if ($tmp_month > 12) {
$tmp_month = 1;
$tmp_year++;
}
$data[] = $tmp_year . $explode . str_pad($tmp_month, 2, '0', STR_PAD_LEFT);
}
return $data;
}
private function getPercentage($params)
{
return number_format_com($params['num'] / $params['sum'] * 100, 2, '') . "";
+21 -5
View File
@@ -1,12 +1,13 @@
<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">
action="/stats/order/">
<input name="type" value="<?= $params['type'] ?>" type="hidden">
<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'] ?>"
<input id="id-time" name="time" type="text" value="<?= $params['time'] ?>"
placeholder="统计月份范围" autocomplete="off"/>
</div>
</div>
@@ -16,6 +17,21 @@
</div>
</div>
</form>
<div class="bs-example bs-example-tabs" data-example-id="togglable-tabs" style="font-size:15px;">
<ul class="nav nav-tabs" role="tablist">
<? foreach ($info['type_ary'] as $key => $val) { ?>
<li role="presentation"
class="<?= $params['type'] == $key ? 'active' : '' ?>">
<a href="javascript:void (0);"
data-open="/stats/order/?type=<?= $key ?>&time=<?= $params['time'] ?>">
<?= $val ?>
</a>
</li>
<? } ?>
</ul>
</div>
<div class="coms-table-bd">
<table class="am-table am-table-bordered">
@@ -199,7 +215,7 @@
<?= $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>
<td><?= $v3 ?></td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
@@ -227,7 +243,7 @@
<?= $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>
<td><?= $v3 ?></td>
<? } ?>
<? foreach ($v2['stats'] as $v4) { ?>
<td><?= $v4 ?></td>
@@ -250,7 +266,7 @@
<script>
require(['laydate', 'autocomplete'], function (laydate) {
laydate.render({
elem: '#id-bill-time', range: '~', format: 'yyyy-MM', type: 'month',
elem: '#id-time', range: '~', format: 'yyyy-MM', type: 'month',
});
});
</script>