edit-api-stats

This commit is contained in:
lccsw
2023-02-13 15:33:36 +08:00
parent 8c04b65782
commit 1cc3dc25c6
2 changed files with 95 additions and 47 deletions
+22 -10
View File
@@ -636,10 +636,11 @@ class Statistics extends Wxapp{
//客户
$where = [
'status>=' => 0,
'cs_biz_id!=' => -1,
'c_time>=' => $c_time['s_time'],
'c_time<=' => $c_time['e_time']
'c_time<=' => $c_time['e_time'],
"biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$city_id && $where['city_id'] = $city_id;
$customers = $this->customers_model->count($where);
//进店
$where = [
@@ -648,8 +649,9 @@ class Statistics extends Wxapp{
'a.c_time>=' => $c_time['s_time'],
'a.c_time<=' => $c_time['e_time'],
'b.status>=' => 0,
'b.cs_biz_id!=' => -1,
"b.biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$city_id && $where['b.city_id'] = $city_id;
$intos = $this->customers_model->db->select('a.id')
->from('lc_receiver_customer_oplogs as a')
->join('lc_receiver_customers as b', "b.id=a.customer_id", 'left')
@@ -659,9 +661,12 @@ class Statistics extends Wxapp{
$where = [
'status>=' => 0,
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time']
'order_time<=' => $o_time['e_time'],
"customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$city_id && $where["customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})"] = null;
$orders = $this->mdOrders->count($where);
$where = [
'a.status>=' => 0,
@@ -669,9 +674,12 @@ class Statistics extends Wxapp{
'a.order_time<=' => $o_time['e_time'],
'a.status<>' => 2,
'b.pid_status' => 3,
'b.status in (1,2)' => null
'b.status in (1,2)' => null,
"a.customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$city_id && $where["customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})"] = null;
$bill_orders = $this->customers_model->db->select('a.id,count(b.status) as total')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_order_status as b', "b.o_id=a.id", 'left')
@@ -714,17 +722,21 @@ class Statistics extends Wxapp{
$o_time = ['s_time' => $s_time . ' 00:00:00', 'e_time' => $s_time . ' 23:59:59'];
$xAxis[] = $days > 7 ? date('d', strtotime($s_time)) : date('n-d', strtotime($s_time));
$where = [
'city_id' => $city_id,
'status>=' => 0,
'cs_biz_id!=' => -1,
'c_time>=' => $c_time['s_time'],
'c_time<=' => $c_time['e_time']
'c_time<=' => $c_time['e_time'],
"biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$customers[] = $this->customers_model->count($where);
$where = [
'status>=' => 0,
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})" => null
"customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$orders[] = $this->mdOrders->count($where);
}
+73 -37
View File
@@ -26,6 +26,7 @@ class Stats_entity{
'e_time' => strtotime(date('Y-m-d 23:59:59', strtotime($e_time)))
];
$pie1_level = $pie2_level = $pie1_offline = $bizs = $biz_customer = [];
$bottom3 = $bottom2 = $bottom1 = '';
$sdata_level = $this->ci->customers_model->get_sdata('level');
foreach ($sdata_level as $v) {
if($type){
@@ -34,9 +35,10 @@ class Stats_entity{
'a.log' => '客户到店',
'a.c_time>=' => $c_time['s_time'],
'a.c_time<=' => $c_time['e_time'],
'b.city_id' => $city_id,
'b.status>=' => 0,
'b.level' => $v
'b.cs_biz_id!=' => -1,
'b.level' => $v,
"b.biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$value = $this->ci->customers_model->db->select('a.id')
->from('lc_receiver_customer_oplogs as a')
@@ -46,14 +48,18 @@ class Stats_entity{
}else{
$where = [
'status>=' => 0,
'cs_biz_id!=' => -1,
'level' => $v,
'c_time>=' => $c_time['s_time'],
'c_time<=' => $c_time['e_time'],
'city_id' => $city_id
"biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$value = $this->ci->customers_model->count($where);
}
$value && $pie1_level[] = ['name' => $v, 'value' => $value];
if($value){
$pie1_level[] = ['name' => $v, 'value' => $value];
$bottom1 += $value;
}
}
$offlineSources = $this->ci->customers_model->offlineSources();
foreach ($offlineSources as $k => $v) {
@@ -64,6 +70,8 @@ class Stats_entity{
'a.c_time>=' => $c_time['s_time'],
'a.c_time<=' => $c_time['e_time'],
'b.status>=' => 0,
'b.cs_biz_id!=' => -1,
"b.biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null,
'b.of_id' => $k
];
$value = $this->ci->customers_model->db->select('a.id')
@@ -74,10 +82,11 @@ class Stats_entity{
}else{
$where = [
'status>=' => 0,
'cs_biz_id!=' => -1,
'of_id' => $k,
'c_time>=' => $c_time['s_time'],
'c_time<=' => $c_time['e_time'],
'city_id' => $city_id
"biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null
];
$value = $this->ci->customers_model->count($where);
}
@@ -89,7 +98,8 @@ class Stats_entity{
if($type){
$where = [
'b.status>=' => 0,
'b.city_id' => $city_id,
'b.cs_biz_id!=' => -1,
"b.biz_id in (select id from lc_biz where city_id={$city_id} and status=1)" => null,
'c.c_time>=' => $c_time['s_time'],
'c.c_time<=' => $c_time['e_time'],
'a.type' => $k,
@@ -105,9 +115,10 @@ class Stats_entity{
}else{
$where = [
'b.status>=' => 0,
'cs_biz_id!=' => -1,
'b.c_time>=' => $c_time['s_time'],
'b.c_time<=' => $c_time['e_time'],
'b.city_id' => $city_id,
"a.city_id" => $city_id,
'a.type' => $k
];
$value = $this->ci->customers_model->db->select('b.id')
@@ -117,6 +128,7 @@ class Stats_entity{
->count_all_results();
}
$pie2_level[] = ['name' => $v, 'value' => $value];
$bottom2 += $value;
}
$biz_rows = $this->ci->biz_model->select(['status' => 1,'city_id' => $city_id], 'id desc', 0, 0, 'id,biz_name');
foreach ($biz_rows as $k => $v) {
@@ -124,14 +136,13 @@ class Stats_entity{
if($type){
$where = [
'b.status>=' => 0,
'b.city_id' => $city_id,
'c.c_time>=' => $c_time['s_time'],
'c.c_time<=' => $c_time['e_time'],
'b.biz_id' => $k,
'b.biz_id' => $v['id'],
'c.type' => 4,
'c.log' => '客户到店',
];
$biz_customer[] = $this->ci->customers_model->db->select('b.id')
$value = $this->ci->customers_model->db->select('b.id')
->from('lc_receiver_customers as b')
->join('lc_receiver_customer_oplogs as c', "c.customer_id=b.id", 'left')
->where($where)
@@ -142,14 +153,15 @@ class Stats_entity{
'biz_id' => $v['id'],
'c_time>=' => $c_time['s_time'],
'c_time<=' => $c_time['e_time'],
'city_id' => $city_id
];
$biz_customer[] = $this->ci->customers_model->count($where);
$value = $this->ci->customers_model->count($where);
}
$biz_customer[] = $value;
$bottom3 += $value;
}
$data['pie1'] = ['title' => '客户来源', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline];
$data['pie2'] = ['title' => '门店类型', 'series_data_1' => $pie2_level];
$data['bar'] = ['title' => '门店列表', 'xAxis_data' => $bizs, 'series_data' => $biz_customer];
$data['pie1'] = ['title' => '客户来源', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline,'bottom' => "合计:{$bottom1}"];
$data['pie2'] = ['title' => '门店类型', 'series_data_1' => $pie2_level,'bottom' => "合计:{$bottom2}"];
$data['bar'] = ['title' => '门店列表', 'xAxis_data' => $bizs, 'series_data' => $biz_customer,'bottom' => "合计:{$bottom3}"];
$data['title'] = $type ? '到店客户' : '全部客户';
return $data;
}
@@ -166,6 +178,7 @@ class Stats_entity{
!$e_time && $e_time = date('Y-m-d');
$o_time = ['s_time' => $s_time . ' 00:00:00', 'e_time' => $e_time . ' 23:59:59'];
$pie1_level = $pie1_offline = $pie2_level = $pie23level = $bizs = $biz_customer = [];
$bottom4 = $bottom3 = $bottom2 = $bottom1 = 0;
$sdata_level = $this->ci->customers_model->get_sdata('level');
foreach ($sdata_level as $v) {
if($type){
@@ -176,7 +189,10 @@ class Stats_entity{
'a.status<>' => 2,
'b.pid_status' => 3,
'b.status in (1,2)' => null,
"a.customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id} and level='{$v}')" => null
"a.customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and level='{$v}' and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$value = $this->ci->db->select('a.id,count(b.status) as total')
->from('lc_receiver_orders_v2 as a')
@@ -188,11 +204,17 @@ class Stats_entity{
'status>=' => 0,
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id} and level='{$v}')" => null
"customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and level='{$v}' and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$value = $this->ci->mdOrders->count($where);
}
$value && $pie1_level[] = ['name' => $v, 'value' => $value];
if($value){
$pie1_level[] = ['name' => $v, 'value' => $value];
$bottom1 += $value;
}
}
$offlineSources = $this->ci->customers_model->offlineSources();
foreach ($offlineSources as $k => $v) {
@@ -204,7 +226,10 @@ class Stats_entity{
'a.status<>' => 2,
'b.pid_status' => 3,
'b.status in (1,2)' => null,
"a.customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id} and of_id=$k)" => null
"a.customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and of_id=$k and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$value = $this->ci->db->select('a.id,count(b.status) as total')
->from('lc_receiver_orders_v2 as a')
@@ -216,7 +241,10 @@ class Stats_entity{
'status>=' => 0,
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id} and of_id=$k)" => null
"customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and of_id=$k and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$value = $this->ci->mdOrders->count($where);
}
@@ -233,9 +261,10 @@ class Stats_entity{
'b.pid_status' => 3,
'b.status in (1,2)' => null,
"a.customer_id in (
select id from lc_receiver_customers where status>=0 and city_id={$city_id} and of_id=$k and biz_id in
(select id from lc_biz where type={$k})
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1 and type={$k})
)" => null
];
$value = $this->ci->db->select('a.id,count(b.status) as total')
->from('lc_receiver_orders_v2 as a')
@@ -248,16 +277,17 @@ class Stats_entity{
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (
select id from lc_receiver_customers where status>=0 and city_id={$city_id} and of_id=$k and biz_id in
(select id from lc_biz where type={$k})
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1 and type={$k})
)" => null
];
$value = $this->ci->mdOrders->count($where);
}
$pie2_level[] = ['name' => $v, 'value' => $value];
$value && $bottom2 += $value;
}
if($type){
$sql = "select * from (SELECT a.id,a.brand_id, count(b.status) as t
$sql = "select *,count(id) as t from (SELECT a.id,a.brand_id, count(b.status) as total
FROM lc_receiver_orders_v2 as a
LEFT JOIN lc_receiver_order_status as b ON b.o_id=a.id
WHERE a.status >= 0
@@ -265,11 +295,11 @@ class Stats_entity{
AND a.brand_id > 0
AND a.order_time>= '{$o_time['s_time']}'
AND a.order_time<= '{$o_time['e_time']}'
AND a.customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})
AND a.customer_id in (select id from lc_receiver_customers where status>=0 and biz_id in (select id from lc_biz where city_id={$city_id} and status=1))
AND b.pid_status = 3
AND b.status in (1,2)
GROUP BY b.o_id
HAVING t = 1) u group by brand_id";
HAVING total = 1) u group by brand_id";
$brand_lists = $this->ci->db->query($sql)->result_array();
}else{
$where = [
@@ -277,7 +307,10 @@ class Stats_entity{
'brand_id>' => 0,
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})" => null
"customer_id in (
select id from lc_receiver_customers where status>=0 and cs_biz_id!=-1 and
biz_id in (select id from lc_biz where city_id={$city_id} and status=1)
)" => null
];
$query = $this->ci->db->select('id,brand_id,count(id) as t')->from('lc_receiver_orders_v2')
->where($where)->group_by('brand_id')->get();
@@ -288,7 +321,10 @@ class Stats_entity{
$brand_ids = implode(',',array_column($brand_lists,'brand_id'));
$brand_ids && $brand_rows = $this->ci->auto_brand_model->map('id','name',"id in ($brand_ids)",'','','','id,name');
foreach ($brand_lists as $val) {
$brand_rows[$val['brand_id']] && $pie23level[] = ['name' => $brand_rows[$val['brand_id']], 'value' => $val['t']];
if($brand_rows[$val['brand_id']]){
$pie23level[] = ['name' => $brand_rows[$val['brand_id']], 'value' => $val['t']];
$bottom3 += $val['t'];
}
}
}
$biz_rows = $this->ci->biz_model->select(['status' => 1,'city_id' => $city_id], 'id desc', 0, 0, 'id,biz_name');
@@ -303,9 +339,8 @@ class Stats_entity{
'b.pid_status' => 3,
'b.status in (1,2)' => null,
'a.biz_id' => $v['id'],
"a.customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})" => null
];
$biz_customer[] = $this->ci->db->select('a.id,count(b.status) as total')
$value = $this->ci->db->select('a.id,count(b.status) as total')
->from('lc_receiver_orders_v2 as a')
->join('lc_receiver_order_status as b', "b.o_id=a.id", 'left')
->where($where)->group_by('b.o_id')->having('total=1')
@@ -316,15 +351,16 @@ class Stats_entity{
'biz_id' => $v['id'],
'order_time>=' => $o_time['s_time'],
'order_time<=' => $o_time['e_time'],
"customer_id in (select id from lc_receiver_customers where status>=0 and city_id={$city_id})" => null
];
$biz_customer[] = $this->ci->mdOrders->count($where);
$value = $this->ci->mdOrders->count($where);
}
$biz_customer[] = $value;
$bottom4 += $value;
}
$data['pie1'] = ['title' => '客户来源', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline];
$data['pie2'] = ['title' => '门店类型', 'series_data_1' => $pie2_level];
$data['pie3'] = ['title' => '品牌分布', 'series_data_1' => $pie23level];
$data['bar'] = ['title' => '门店列表', 'xAxis_data' => $bizs, 'series_data' => $biz_customer];
$data['pie1'] = ['title' => '来源占比', 'series_data_1' => $pie1_level, 'series_data_2' => $pie1_offline,'bottom'=>"合计:{$bottom1}"];
$data['pie2'] = ['title' => '门店占比', 'series_data_1' => $pie2_level,'bottom'=>"合计:{$bottom2}"];
$data['pie3'] = ['title' => '品牌占比', 'series_data_1' => $pie23level,'bottom'=>"合计:{$bottom3}"];
$data['bar'] = ['title' => '具体分布', 'xAxis_data' => $bizs, 'series_data' => $biz_customer,'bottom'=>"合计:{$bottom4}"];
$data['title'] = $type ? '开票数' : '订单数';
return $data;
}