diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php
index ec869269..0824c230 100644
--- a/admin/controllers/receiver/Customer.php
+++ b/admin/controllers/receiver/Customer.php
@@ -27,6 +27,7 @@ class Customer extends HD_Controller
$this->load->model('receiver/receiver_xz_model');
$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');
$this->load->model('app/licheb/app_licheb_users_model');
$this->load->model("biz/biz_model");
@@ -195,6 +196,45 @@ class Customer extends HD_Controller
return $this->show_view('receiver/customer/lists_statdata', true);
}
+ public function lists_statdatalog(){
+ $params = $this->input->get();
+ $id = intval($params['id']);
+ if (!$id) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误!');
+ }
+ $where = ['id' => $id];
+ $re = $this->statplan->get($where);
+ if (!$re) {
+ return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
+ }
+
+ !$params['city_id'] && $params['city_id'] = '';
+ !$params['biz_id'] && $params['biz_id'] = '';
+
+ $where = array('spid'=>$id);
+ $rows_city = $this->statdatalog->select_groupby('city_id', $where, 'city_id', 0, 0, 'city_id, city_name');
+ $maps_city = $this->statdatalog->map($map_key = 'city_id', $map_value = '', $where, $order = 'city_id, biz_id', $page = 0, $page_size = 0, $select = "distinct city_id, biz_id, biz_name");
+ $city_biz_ary = array();
+ foreach ($rows_city as $item){
+ $list = array();
+ foreach ($maps_city[$item['city_id']] as $k => $v){
+ $list[$v['biz_id']] = $v['biz_name'];
+ }
+ $city_biz_ary[$item['city_id']] = array('name'=>$item['city_name'], 'list' => $list);
+ }
+
+ $stat_data = $this->get_statdatalog($params);
+ $indexs = $stat_data['indexs'];
+ $lists = $stat_data['lists'];
+
+ $this->data['indexs'] = $indexs;
+ $this->data['lists'] = $lists;
+ $this->data['city_biz_ary'] = $city_biz_ary;
+ $this->data['params'] = $params;
+ $this->data['_title'] = $re['sp_name'].'_统计数据';
+ return $this->show_view('receiver/customer/lists_statdatalog', true);
+ }
+
private function get_statdata($id, $export=false){
if (!$id){
return array();
@@ -229,6 +269,122 @@ class Customer extends HD_Controller
return array('indexs' => $indexs, 'lists' => $lists);
}
+ private function get_statdatalog($params, $export=false){
+ $id = $params['id'];
+ if (!$id){
+ return array();
+ }
+
+ $where = ['spid' => $id];
+ $where_s = "spid = {$id} ";
+
+ $city_id = $params['city_id'];
+ $city_id && $where_s .= " and city_id = {$city_id} ";
+
+ $biz_id = $params['biz_id'];
+ $biz_id && $where_s .= " and biz_id = {$biz_id} ";
+
+ if ($params['stat_date']) {
+ $stat_date = explode(' ~ ', $params['stat_date']);
+ if ($stat_date[0]) {
+ $where_s .= " and stat_date >= '{$stat_date[0]}' ";
+ }
+ if ($stat_date[1]) {
+ $where_s .= " and stat_date <= '{$stat_date[1]}' ";
+ }
+ }
+
+ $sql = "
+ select * from (
+ select 1 as group_id, stat_date, '总数' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date
+ union all
+ select 3 as group_id, stat_date, city_name as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
+ union all
+ select biz_id * 10 as group_id, stat_date, if(biz_id,concat('',biz_name,''),'未分配门店') as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
+ union all
+ select (biz_id * 10 + 1) as group_id, stat_date, if(admin_id,concat(' - ',biz_name,'-', admin_name), ' - 未分配') as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null group by stat_date, k
+ union all
+ select 10007 as group_id, stat_date, '战败' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 group by stat_date
+ union all
+ select 10008 as group_id, stat_date, '战败-无购车意向' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_1 is not null group by stat_date
+ union all
+ select 10009 as group_id, stat_date, concat(' - 战败-无购车意向-', tag_id_1_1_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_1 is not null group by stat_date, k
+ union all
+ select 10020 as group_id, stat_date, '战败-有购车意向' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_2 is not null group by stat_date
+ union all
+ select 10021 as group_id, stat_date, concat(' - 战败-有购车意向-', tag_id_1_2_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 3 and tag_id_1_2 is not null group by stat_date, k
+ union all
+ select 10030 as group_id, stat_date, '加V(扣除 战败-无购车意向)' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and (tag_id_1_1 is null or tag_id_1_1 is not null and status <> 3) and wxgr = 1 group by stat_date
+ union all
+ select 10040 as group_id, stat_date, '未见客户的见面意向' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 0 and tag_id_2_1 is not null group by stat_date
+ union all
+ select 10041 as group_id, stat_date, concat(' - 未见客户的见面意向','-', tag_id_2_1_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 0 and tag_id_2_1 is not null group by stat_date, k
+ union all
+ select 10050 as group_id, stat_date, '到店客户的购车意向' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 1 and tag_id_2_2 is not null group by stat_date
+ union all
+ select 10051 as group_id, stat_date, concat(' - 到店客户的购车意向','-', tag_id_2_2_name) as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and status = 1 and tag_id_2_2 is not null group by stat_date, k
+ union all
+ select 10060 as group_id, stat_date, '订单数' as k, count(*) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is not null group by stat_date
+ union all
+ select 10061 as group_id, stat_date, concat(' - 订单数','-',brand_name,' ', s_name) as k, count(*) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is not null group by stat_date, k
+ union all
+ select 10090 as group_id, stat_date, '加企微' as k, count(distinct c_id) as v from lc_receiver_customers_stat_data_log where spid = 1 and o_id is null and wxqy = 1 group by stat_date
+ ) t
+ order by group_id, stat_date, k
+ ";
+ $sql = str_replace('spid = 1', $where_s, $sql);
+ $rows = $this->statdatalog->db->query($sql)->result_array();
+ if (!$rows){
+ return array();
+ }
+
+ $rows_gk = array();
+ $rows_group_id_k = array();
+ $rows_stat_date = array();
+ $key_v = array();
+
+ foreach ($rows as $row){
+ $group_id = $row['group_id'];
+ $k = $row['k'];
+ $stat_date = $row['stat_date'];
+ $v = $row['v'];
+ $group_id_k = $group_id . '-' . $k;
+ if (!in_array($group_id_k, $rows_gk)){
+ $rows_gk[] = $group_id_k;
+ $rows_group_id_k[] = array('group_id' => $group_id, 'k' => $k );
+ }
+ if (!in_array($stat_date, $rows_stat_date)){
+ $rows_stat_date[] = $stat_date;
+ }
+ $key_ = $group_id . '-' . $k . '-' . $stat_date;
+ $key_v[$key_] = $v;
+ }
+
+ $lists = array();
+ $indexs = ['序号', '栏目'];
+ $i = 1;
+ foreach ($rows_group_id_k as $key => $val){
+ $group_id = $val['group_id'];
+ $k = $val['k'];
+ $list['序号'] = $i;
+ $list['栏目'] = $export ? str_replace('', '', str_replace('', '', $k)) : $k;
+ foreach ($rows_stat_date as $key_date => $val_date){
+ $stat_date = $val_date;
+ #$index = str_replace('-', '', substr($stat_date, 5));
+ $index = substr($stat_date, 5);
+ if (!in_array($index, $indexs)){
+ $indexs[] = $index;
+ }
+ $key_ = $group_id . '-' . $k . '-' . $stat_date;
+ $list[$index] = $key_v[$key_] ? $key_v[$key_] : 0;
+ }
+ $lists[] = $list;
+ $i += 1;
+ }
+
+ return array('indexs' => $indexs, 'lists' => $lists);
+ }
+
private function get_where(&$params)
{
!$params['biz_id'] && $params['biz_id'] = '';
@@ -901,6 +1057,31 @@ class Customer extends HD_Controller
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
}
+ public function export_statdatalog(){
+ $params = $this->input->get();
+ $id = intval($params['id']);
+ if (!$id) {
+ return $this->show_json(SYS_CODE_FAIL, '参数错误!');
+ }
+ $where = ['id' => $id];
+ $re = $this->statplan->get($where);
+ if (!$re) {
+ return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
+ }
+
+ $stat_data = $this->get_statdatalog($params, $export=true);
+ $indexs = array();
+ foreach ($stat_data['indexs'] as $index){
+ $indexs[$index] = $index;
+ }
+ $data = $stat_data['lists'];
+
+ $fileName = $re['sp_name'].'_统计数据';
+ array_unshift($data, $indexs);
+ $this->load->library('excel');
+ $this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
+ }
+
//改派
public function edit_adviser()
{
diff --git a/admin/views/receiver/customer/lists_statdatalog.php b/admin/views/receiver/customer/lists_statdatalog.php
new file mode 100644
index 00000000..e37ab248
--- /dev/null
+++ b/admin/views/receiver/customer/lists_statdatalog.php
@@ -0,0 +1,147 @@
+
+