customer statplan add data_log

This commit is contained in:
qianhy
2023-04-19 16:19:28 +08:00
committed by lccsw
parent b80aee45eb
commit d7413dcecf
2 changed files with 191 additions and 4 deletions
+177 -4
View File
@@ -34,6 +34,7 @@ class Customer extends HD_Controller
}
$this->load->model('receiver/Receiver_customer_stat_plan_model', 'statplan');
$this->load->model('receiver/Receiver_customer_stat_data_model', 'statdata');
$this->load->model('receiver/Receiver_customer_stat_data_log_model', 'statdatalog');
$where = array('s_date <= DATE(now()) and DATE(now()) <= e_date and last_date < DATE(now())'=> null);
$plans = $this->statplan->select($where, '', 0, 0);
@@ -49,6 +50,10 @@ class Customer extends HD_Controller
$s_date = $plan['s_date'];
$stat_date = date('Y-m-d');
$c_time = time();
# 先删除今日数据
$this->statdata->delete(array('spid' => $spid, 'stat_date' => $stat_date));
$this->statdatalog->delete(array('spid' => $spid, 'stat_date' => $stat_date));
# 1 生成统计数据
$sql = "
select * from (
select 1 as group_id, '<b>总数</b>' as k, count(*) as v from lc_receiver_customers c where of_id = @of_id and of2_id = @of2_id and c_time >= UNIX_TIMESTAMP('@s_date')
@@ -75,7 +80,12 @@ class Customer extends HD_Controller
union all
select 10021 as group_id, ' - 战败-有购车意向-对产品不满意' as k, count(*) as v from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and c.status = 3 and id in (select c_id from lc_receiver_customers_tagdata where t_id in (select id from lc_receiver_customers_tag where tag_type = 1 and pid in (111))) group by k
union all
select 10030 as group_id, '<b>加V(扣除 战败-无购车意向)</b>' as k, count(*) as v from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and id not in (select c_id from lc_receiver_customers_tagdata where t_id in (select id from lc_receiver_customers_tag where tag_type = 1 and pid in (103, 107))) and wxgr = 1 group by k
select 10030 as group_id, '<b>加V(扣除 战败-无购车意向)</b>' as k, count(*) as v from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and id not in (
select c.id from lc_receiver_customers c
where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date')
and c.status = 3
and id in (select c_id from lc_receiver_customers_tagdata where t_id in (select id from lc_receiver_customers_tag where tag_type = 1 and pid in (103, 107)))
) and wxgr = 1 group by k
union all
select 10040 as group_id, '<b>未见客户的见面意向</b>' as k, count(*) as v from lc_receiver_customers_tagdata td join lc_receiver_customers_tag t on td.t_id = t.id where t.tag_type = 2 and t.pid in (120) and td.c_id in (select id from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and c.status = 0) group by k
union all
@@ -111,12 +121,175 @@ class Customer extends HD_Controller
$data[] = $row;
}
$res = $this->statdata->add_batch($data);
if ($res){
# 2 生成统计数据的log
$sql = "
insert into lc_receiver_customers_stat_data_log(
spid,
stat_date,
c_time,
c_id,
biz_id,
biz_name,
city_id,
city_name,
admin_id,
admin_name,
status,
wxqy,
wxgr,
tag_id_1_1,
tag_id_1_1_name,
tag_id_1_2,
tag_id_1_2_name,
tag_id_2_1,
tag_id_2_1_pid,
tag_id_2_1_name,
tag_id_2_1_pid_name,
tag_id_2_2,
tag_id_2_2_pid,
tag_id_2_2_name,
tag_id_2_2_pid_name,
o_id,
brand_id,
brand_name,
s_id,
s_name
)
select
@spid as spid,
date(now()) as stat_date,
UNIX_TIMESTAMP() as c_time,
c.id as c_id,
c.biz_id,
b.biz_name,
b.city_id,
ct.name as city_name,
c.admin_id,
u.uname as admin_name,
c.status,
c.wxqy,
c.wxgr,
tg11.tag_id_pid as tag_id_1_1,
tg11.tag_id_pid_name as tag_id_1_1_name,
tg12.tag_id_pid as tag_id_1_2,
tg12.tag_id_pid_name as tag_id_1_2_name,
tg21.tag_id as tag_id_2_1,
tg21.tag_id_pid as tag_id_2_1_pid,
tg21.tag_id_name as tag_id_2_1_name,
tg21.tag_id_pid_name as tag_id_2_1_pid_name,
tg22.tag_id as tag_id_2_2,
tg22.tag_id_pid as tag_id_2_2_pid,
tg22.tag_id_name as tag_id_2_2_name,
tg22.tag_id_pid_name as tag_id_2_2_pid_name,
null as o_id,
null as brand_id,
'' as brand_name,
null as s_id,
'' as s_name
from lc_receiver_customers c
left join lc_biz b on c.biz_id = b.id
left join lc_sys_city ct on b.city_id = ct.city_id
left join lc_app_licheb_users u on c.admin_id = u.id
left join (
select distinct td.c_id, t.pid as tag_id_pid, tp.name as tag_id_pid_name
from lc_receiver_customers_tagdata td left join lc_receiver_customers_tag t on td.t_id = t.id
left join lc_receiver_customers_tag tp on t.pid = tp.id
where t.tag_type = 1
and t.pid in (103, 107)
and td.c_id in (select id from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date'))
) tg11 on c.id = tg11.c_id
left join (
select distinct td.c_id, t.pid as tag_id_pid, tp.name as tag_id_pid_name
from lc_receiver_customers_tagdata td left join lc_receiver_customers_tag t on td.t_id = t.id
left join lc_receiver_customers_tag tp on t.pid = tp.id
where t.tag_type = 1
and t.pid in (100, 110, 111)
and td.c_id in (select id from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date'))
) tg12 on c.id = tg12.c_id
left join (
select td.c_id, td.t_id as tag_id, t.name as tag_id_name, t.pid as tag_id_pid, tp.name as tag_id_pid_name
from lc_receiver_customers_tagdata td join lc_receiver_customers_tag t on td.t_id = t.id
left join lc_receiver_customers_tag tp on t.pid = tp.id
where t.tag_type = 2
and t.pid in (120)
and td.c_id in (select id from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and c.status = 0)
) tg21 on c.id = tg21.c_id
left join (
select td.c_id, td.t_id as tag_id, t.name as tag_id_name, t.pid as tag_id_pid, tp.name as tag_id_pid_name
from lc_receiver_customers_tagdata td join lc_receiver_customers_tag t on td.t_id = t.id
left join lc_receiver_customers_tag tp on t.pid = tp.id
where t.tag_type = 2
and t.pid in (121)
and td.c_id in (select id from lc_receiver_customers c where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') and c.status = 1)
) tg22 on c.id = tg22.c_id
where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date')
union all
select
1 as spid,
date(now()) as stat_date,
UNIX_TIMESTAMP() as c_time,
c.id as c_id,
c.biz_id,
b.biz_name,
b.city_id,
ct.name as city_name,
c.admin_id,
u.uname as admin_name,
c.status,
c.wxqy,
c.wxgr,
null as tag_id_1_1,
'' as tag_id_1_1_name,
null as tag_id_1_2,
'' as tag_id_1_2_name,
null as tag_id_2_1,
null as tag_id_2_1_pid,
'' as tag_id_2_1_name,
'' as tag_id_2_1_pid_name,
null as tag_id_2_2,
null as tag_id_2_2_pid,
'' as tag_id_2_2_name,
'' as tag_id_2_2_pid_name,
o.id as o_id,
o.brand_id,
brand.`name` as brand_name,
o.s_id,
s.`name` as s_name
from lc_receiver_orders_v2 o
left join lc_auto_brand brand on o.brand_id = brand.id
left join lc_auto_series s on o.s_id = s.id
left join lc_receiver_customers c on o.customer_id = c.id
left join lc_biz b on c.biz_id = b.id
left join lc_sys_city ct on b.city_id = ct.city_id
left join lc_app_licheb_users u on c.admin_id = u.id
where o.`status` in (0, 1)
and customer_id in (select id from lc_receiver_customers c where of_id = @of_id and of2_id = @of2_id and c_time >= UNIX_TIMESTAMP('@s_date'))
";
$sql = str_replace('@spid', $spid, $sql);
$sql = str_replace('@of_id', $of_id, $sql);
$sql = str_replace('@of2_id', $of2_id, $sql);
$sql = str_replace('@s_date', $s_date, $sql);
$res_log = $this->statdatalog->db->query($sql);
if ($res && $res_log){
$this->statplan->update(array('last_date'=>$stat_date), array('id'=>$spid));
echo "spid {$spid} success: {$res}";
echo "spid {$spid} success: {$res}{$res_log}";
}
else{
echo "spid {$spid} failure";
echo "spid {$spid} failure{$res}{$res_log}";
}
}
}
@@ -0,0 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Receiver_customer_stat_data_log_model extends HD_Model
{
private $table_name = 'lc_receiver_customers_stat_data_log';
public function __construct()
{
parent::__construct($this->table_name, 'default');
}
}