diff --git a/api/controllers/plan/Customer.php b/api/controllers/plan/Customer.php new file mode 100644 index 00000000..ec8f2cd7 --- /dev/null +++ b/api/controllers/plan/Customer.php @@ -0,0 +1,124 @@ +log_file = 'customer.log'; + } + + /** + * Notes:生成客户来源日志 + * Created by: qianhy + * https://liche-api-dev.xiaoyu.com/plan/customer/statplan?sd=1 + * https://api.liche.cn/plan/items/customer/statplan + */ + public function statplan() + { + $params = $this->input->get(); + $hour = date('H.i'); + if (($hour >= 23.50 && $hour <= 23.59) || $params['sd']) { + if ($params['sd']) { + echo "开始执行生成客户来源日志[{$hour}]"; + } + } else { + echo '[23:50]后才会开始生成客户来源日志[' . $hour . ']'; + return; + } + $this->load->model('receiver/Receiver_customer_stat_plan_model', 'statplan'); + $this->load->model('receiver/Receiver_customer_stat_data_model', 'statdata'); + + $where = array('s_date <= DATE(now()) and DATE(now()) <= e_date and last_date < DATE(now())'=> null); + $plans = $this->statplan->select($where, '', 0, 0); + if (!$plans){ + echo 'no stat plan '. date('Y-m-d H:i:s'); + return; + } + + foreach ($plans as $plan){ + $spid = $plan['id']; + $of_id = $plan['of_id']; + $of2_id = $plan['of2_id']; + $s_date = $plan['s_date']; + $stat_date = date('Y-m-d'); + $c_time = time(); + $sql = " + select * from ( + select 1 as group_id, '总数' 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') + union all + select 3 as group_id, concat(ct.name) as k, count(*) as v 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 where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') group by k + union all + select c.biz_id * 10 as group_id, concat('',b.biz_name,'') k, count(*) as v from lc_receiver_customers c left join lc_biz b on c.biz_id = b.id where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') group by group_id, k + union all + select (c.biz_id * 10 + 1) as group_id, concat(' - ',b.biz_name,'-', u.uname) as k, count(*) as v from lc_receiver_customers c left join lc_biz b on c.biz_id = b.id left join lc_app_licheb_users u on c.admin_id = u.id where c.of_id = @of_id and c.of2_id = @of2_id and c.c_time >= UNIX_TIMESTAMP('@s_date') group by group_id,k + union all + select 10007 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 group by k + union all + select 10008 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 (103, 107))) group by k + union all + select 10009 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 (103))) group by k + union all + select 10009 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 (107))) group by k + union all + select 10020 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 (100, 110, 111))) group by k + 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 (100))) group by k + 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 (110))) group by k + 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, '加V(扣除 战败-无购车意向)' 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 in (select c_id from lc_receiver_customers_tagdata where t_id not 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, '未见客户的见面意向' 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 + select 10041 as group_id, concat(' - 未见客户的见面意向','-', t.name) 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 + select 10050 as group_id, '到店客户的购车意向' 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 (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) group by k + union all + select 10051 as group_id, concat(' - 到店客户的购车意向','-', t.name) 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 (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) group by k + union all + select 10060 as group_id, '订单数' as k, count(*) as v from lc_receiver_orders_v2 o 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')) + union all + select 10061 as group_id, concat(' - 订单数','-',b.`name`,' ', s.`name`) as k, count(*) as v from lc_receiver_orders_v2 o left join lc_auto_brand b on o.brand_id = b.id left join lc_auto_series s on o.s_id = s.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')) group by k + union all + select 10090 as group_id, '加企微' 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') and wxqy = 1 + ) t + order by group_id, k + "; + + $sql = str_replace('@of_id', $of_id, $sql); + $sql = str_replace('@of2_id', $of2_id, $sql); + $sql = str_replace('@s_date', $s_date, $sql); + $rows = $this->statplan->db->query($sql)->result_array(); + if (!$rows){ + echo "spid {$spid} no data"; + continue; + } + + $data = []; + foreach ($rows as $row){ + $row['spid'] = $spid; + $row['stat_date'] = $stat_date; + $row['c_time'] = $c_time; + $data[] = $row; + } + $res = $this->statdata->add_batch($data); + if ($res){ + $this->statplan->update(array('last_date'=>$stat_date), array('id'=>$spid)); + echo "spid {$spid} success: {$res}"; + } + else{ + echo "spid {$spid} failure"; + } + } + } + +} \ No newline at end of file diff --git a/api/controllers/plan/Plan.php b/api/controllers/plan/Plan.php index 4398dfe5..5d9dbdf6 100644 --- a/api/controllers/plan/Plan.php +++ b/api/controllers/plan/Plan.php @@ -44,6 +44,8 @@ class Plan extends CI_Controller $plan[] = array('url' => base_url(array('plan', 'items', 'stock_log')), 'interval' => 5);//库存车辆日志 + $plan[] = array('url' => base_url(array('plan', 'customer', 'statplan')), 'interval' => 5);//生成客户来源日志 + $plan[] = array('url' => base_url(array('plan', 'polyv', 'view_log')), 'interval' => 5);//直播观看详情数据 $plan[] = array('url' => base_url(array('plan', 'biz', 'settle')), 'interval' => 1); diff --git a/common/models/receiver/Receiver_customer_stat_data_model.php b/common/models/receiver/Receiver_customer_stat_data_model.php new file mode 100644 index 00000000..c10dfd9b --- /dev/null +++ b/common/models/receiver/Receiver_customer_stat_data_model.php @@ -0,0 +1,14 @@ +table_name, 'default'); + } + +} diff --git a/common/models/receiver/Receiver_customer_stat_plan_model.php b/common/models/receiver/Receiver_customer_stat_plan_model.php new file mode 100644 index 00000000..7823ef42 --- /dev/null +++ b/common/models/receiver/Receiver_customer_stat_plan_model.php @@ -0,0 +1,14 @@ +table_name, 'default'); + } + +}