diff --git a/admin/controllers/app/licheb/Main.php b/admin/controllers/app/licheb/Main.php index 624b1f0a..6d551ab2 100644 --- a/admin/controllers/app/licheb/Main.php +++ b/admin/controllers/app/licheb/Main.php @@ -20,7 +20,7 @@ class Main extends HD_Controller $this->load->model('app/material/Material_biz_model', 'mdMaterialBiz'); $this->load->model('topics/topics_model', 'mdTopics'); $this->load->model('live/Live_polyv_session_model', 'mdPolyvSession'); - $this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog'); + $this->load->model('app/licheb/app_licheb_bizs_log_model', 'mdBizsLog'); $this->load->model('app/licheb/syt_live_model', 'mdSytLive'); } @@ -99,9 +99,9 @@ class Main extends HD_Controller array('name' => '查看详情', 'url' => '/live/polyv'), ), ); - $value = $this->mdUsersLog->count(); + $value = $this->mdBizsLog->count(); $list[] = array( - 'title' => '顾问日志', + 'title' => '门店日志', 'value' => $value, 'btns' => array( array('name' => '查看详情', 'url' => 'app/licheb/userslog'), diff --git a/admin/controllers/app/licheb/Userslog.php b/admin/controllers/app/licheb/Userslog.php index d18778c3..30f81a26 100644 --- a/admin/controllers/app/licheb/Userslog.php +++ b/admin/controllers/app/licheb/Userslog.php @@ -15,6 +15,7 @@ class Userslog extends HD_Controller parent::__construct(); $this->load->model('app/licheb/app_licheb_users_model', 'mdUsers'); $this->load->model('app/licheb/app_licheb_users_log_model', 'mdUsersLog'); + $this->load->model('app/licheb/app_licheb_bizs_log_model', 'mdBizsLog'); $this->load->model('receiver/receiver_customers_visit_sales_model', 'mdCustomerVisitSales'); $this->load->model('receiver/receiver_customers_model', 'mdCustomers'); $this->load->model("biz/biz_model", 'mdBiz'); @@ -27,6 +28,17 @@ class Userslog extends HD_Controller } public function lists() + { + $params = $this->input->get(); + $params['page'] = $params['page'] ? intval($params['page']) : 1; + $params['size'] = $params['size'] ? intval($params['size']) : 20; + $data = $this->dataBizSelect($params); + $data['typeAry'] = $this->mdBiz->type_ary(); + $this->data = $data; + $this->show_view('app/licheb/userslog/lists', true); + } + + public function lists_users() { $params = $this->input->get(); $params['page'] = $params['page'] ? intval($params['page']) : 1; @@ -36,21 +48,17 @@ class Userslog extends HD_Controller $view = 'app/licheb/userslog/lists_visit'; $data = $this->visitSelect($params); } else { - $view = 'app/licheb/userslog/lists'; - $data = $this->dataSelect($params); + $view = 'app/licheb/userslog/lists_users'; + $data = $this->dataUsersSelect($params); } - $data['typeAry'] = $this->mdBiz->type_ary(); $data['tabAry'] = $this->tabAry; $this->data = $data; $this->show_view($view, true); } - private function dataSelect($params) + private function dataBizSelect($params) { $lists = $where = []; - if ($params['uname']) { - $where["sale_id in(select id from lc_app_licheb_users where uname like '%{$params['uname']}%')"] = null; - } if ($params['biz_id']) { $where['biz_id'] = $params['biz_id']; } else if ($params['city_id']) { @@ -79,57 +87,168 @@ class Userslog extends HD_Controller $time[0] && $where["log_date>="] = $time[0]; $time[1] && $where["log_date<="] = $time[1]; } + $total = $this->mdBizsLog->count($where); + if ($total) { + $res = $this->mdBizsLog->select($where, "id desc", $params['page'], $params['size']); + if ($res) { + $str_ids = implode(',', array_unique(array_column($res, 'biz_id'))); + $map_biz = $this->mdBiz->map('id', 'biz_name', ["id in ({$str_ids})" => null]); + $offlineSources = $this->mdCustomers->offlineSources(); + foreach ($res as $v) { + $biz_name = $biz_type = $customer_info = $c_num_info = $order_info = ''; + $customers = $c_num = $orders = 0; + $map_biz[$v['biz_id']] && $biz_name = $params['size'] == 10000 ? $map_biz[$v['biz_id']] : " + {$map_biz[$v['biz_id']]}"; + $temp = ['biz_name' => $biz_name, 'defeats' => $v['defeats'] + , 't_num' => $v['t_num'], 'orders' => $v['orders'] + , 'bills' => $v['bills'], 'reassigns' => $v['reassigns'], 'receives' => $v['receives'] + , 'qy_adds' => $v['qy_adds'], 'log_date' => $v['log_date']]; + $customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : []; + $c_num_json = $v['customer_json'] ? json_decode($v['c_num_json'], true) : []; + $order_json = $v['customer_json'] ? json_decode($v['order_json'], true) : []; + foreach ($offlineSources as $key1 => $value1) { + $nums = intval($v['customer_' . $key1]); + $nums_c_num = intval($v['c_num_' . $key1]); + $nums_orders = intval($v['order_' . $key1]); + if ($nums) { + $customers += $nums; + if ($params['size'] != 10000) { + if ($customer_info) { + $customer_info = $customer_info . '+' . $value1['name'] . '(' . $nums . ')'; + } else { + $customer_info = $value1['name'] . '(' . $nums . ')'; + } + } + } + if ($nums_c_num) { + $c_num += $nums_c_num; + if ($params['size'] != 10000) { + if ($c_num_info) { + $c_num_info = $c_num_info . '+' . $value1['name'] . '(' . $nums_c_num . ')'; + } else { + $c_num_info = $value1['name'] . '(' . $nums_c_num . ')'; + } + } + } + if ($nums_orders) { + $orders += $nums_orders; + if ($params['size'] != 10000) { + if ($order_info) { + $order_info = $order_info . '+' . $value1['name'] . '(' . $nums_orders . ')'; + } else { + $order_info = $value1['name'] . '(' . $nums_orders . ')'; + } + } + } + if ($params['size'] == 10000) {//导出使用 + $temp['customer_' . $key1] = $nums; + $temp['c_num_' . $key1] = $nums_c_num; + $temp['order_' . $key1] = $nums_orders; + foreach ($value1['list'] as $key2 => $value2) { + $temp['customer_' . $key2] = intval($customer_json[$key1]['list'][$key2]['num']); + $temp['c_num_' . $key2] = intval($c_num_json[$key1]['list'][$key2]['num']); + $temp['order_' . $key2] = intval($order_json[$key1]['list'][$key2]['num']); + } + } + } + $customer_info && $customers = $customers . '=' . $customer_info; + $c_num_info && $c_num = $c_num . '=' . $c_num_info; + $order_info && $orders = $orders . '=' . $order_info; + $temp['customers'] = $customers; + $temp['c_num'] = $c_num; + $temp['orders'] = $orders; + $lists[] = $temp; + } + } + } + if ($params['size'] != 10000) { + $sum = $this->mdUsersLog->sum('customers', $where); + $menus[] = ['title' => "客户数", 'value' => intval($sum['customers']), 'tag' => '人']; + $sum_c = $this->mdUsersLog->sum('c_num', $where); + $menus[] = ['title' => "进店人数", 'value' => intval($sum_c['c_num']), 'tag' => '人']; + $sum = $this->mdUsersLog->sum('orders', $where); + $menus[] = ['title' => "订单数", 'value' => intval($sum['orders']), 'tag' => '个']; + $sum = $this->mdUsersLog->sum('t_num', $where); + $menus[] = ['title' => "试驾数", 'value' => intval($sum['t_num']), 'tag' => '次']; + $sum = $this->mdUsersLog->sum('defeats', $where); + $menus[] = ['title' => "战败数", 'value' => intval($sum['defeats']), 'tag' => '个']; + $sum = $this->mdUsersLog->sum('bills', $where); + $menus[] = ['title' => "开票数", 'value' => intval($sum['bills']), 'tag' => '个']; + $sum = $this->mdUsersLog->sum('qy_adds', $where); + $menus[] = ['title' => "企微数", 'value' => intval($sum['qy_adds']), 'tag' => '人']; + $sum = $this->mdUsersLog->sum('reassigns', $where); + $menus[] = ['title' => "改派数", 'value' => intval($sum['reassigns']), 'tag' => '个']; + $sum = $this->mdUsersLog->sum('receives', $where); + $menus[] = ['title' => "接收数", 'value' => intval($sum['receives']), 'tag' => '个']; + $data['menus'] = $menus; + } + $data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total); + $data['lists'] = $lists; + $data['params'] = $params; + $data['_title'] = "门店日志"; + return $data; + } + + private function dataUsersSelect($params) + { + $_title = '顾问日志'; + $lists = $where = []; + if ($params['uname']) { + $where["sale_id in(select id from lc_app_licheb_users where uname like '%{$params['uname']}%')"] = null; + } + if ($params['biz_id']) { + $where['biz_id'] = $params['biz_id']; + $re_biz = $this->mdBiz->get(['id' => $params['biz_id']]); + $re_biz && $_title = $re_biz['biz_name'] . '_顾问日志'; + } + if ($params['time']) { + $time = explode(' ~ ', $params['time']); + $time[0] && $where["log_date>="] = $time[0]; + $time[1] && $where["log_date<="] = $time[1]; + } $total = $this->mdUsersLog->count($where); if ($total) { - $res = $this->mdUsersLog->select($where, "id desc", $params['page'], $params['size']); - $sale_ids = $biz_ids = []; + $res = $this->mdUsersLog->select($where, "log_date desc,id desc", $params['page'], $params['size']); + $sale_ids = []; foreach ($res as $v) { $v['sale_id'] && !in_array($v['sale_id'], $sale_ids) && $sale_ids[] = $v['sale_id']; - $v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id']; } - $map_sale = $map_biz = $map_city = []; + $map_sale = []; if ($sale_ids) { $str_ids = implode(',', $sale_ids); $map_sale = $this->mdUsers->map('id', 'uname', ["id in ({$str_ids})" => null]); } - if ($biz_ids) { - $str_ids = implode(',', $biz_ids); - $map_biz = $this->mdBiz->map('id', 'biz_name,type', ["id in ({$str_ids})" => null]); - } $offlineSources = $this->mdCustomers->offlineSources(); - $typeAry = $this->mdBiz->type_ary(); foreach ($res as $v) { - $uname = $biz_name = $biz_type = $customers_info = ''; - $customers = 0; - $map_sale[$v['sale_id']] && $uname = $map_sale[$v['sale_id']]; - $map_biz[$v['biz_id']]['biz_name'] && $biz_name = $map_biz[$v['biz_id']]['biz_name']; - $map_biz[$v['biz_id']]['type'] && $biz_type = $typeAry[$map_biz[$v['biz_id']]['type']]; - $temp = ['uname' => $uname, 'biz_type' => $biz_type, 'biz_name' => $biz_name, 'defeats' => $v['defeats'] - , 'c_num' => $v['c_num'], 'a_num' => $v['a_num'], 't_num' => $v['t_num'], 'orders' => $v['orders'] - , 'bills' => $v['bills'], 'follows' => $v['follows'], 'reassigns' => $v['reassigns'], 'receives' => $v['receives'] + $uname = $map_sale[$v['sale_id']] ? $map_sale[$v['sale_id']] : ''; + $temp = ['uname' => $uname, 't_num' => $v['t_num'], 'defeats' => $v['defeats'], 'bills' => $v['bills'] , 'qy_adds' => $v['qy_adds'], 'qy_dels' => $v['qy_dels'], 'log_date' => $v['log_date']]; $customer_json = $v['customer_json'] ? json_decode($v['customer_json'], true) : []; + $c_num_json = $v['customer_json'] ? json_decode($v['c_num_json'], true) : []; + $order_json = $v['customer_json'] ? json_decode($v['order_json'], true) : []; + $customers = $c_num = $orders = 0; foreach ($offlineSources as $key1 => $value1) { $nums = intval($v['customer_' . $key1]); + $nums_c_num = intval($v['c_num_' . $key1]); + $nums_orders = intval($v['order_' . $key1]); + $nums && $customers += $nums; + $nums_c_num && $c_num += $nums_c_num; + $nums_orders && $orders += $nums_orders; if ($params['size'] == 10000) {//导出使用 $temp['customer_' . $key1] = $nums; + $temp['c_num_' . $key1] = $nums_c_num; + $temp['order_' . $key1] = $nums_orders; foreach ($value1['list'] as $key2 => $value2) { $temp['customer_' . $key2] = intval($customer_json[$key1]['list'][$key2]['num']); + $temp['c_num_' . $key2] = intval($c_num_json[$key1]['list'][$key2]['num']); + $temp['order_' . $key2] = intval($order_json[$key1]['list'][$key2]['num']); } } - if ($nums) { - $customers += $nums; -// if ($params['size'] != 10000) { -// if ($customers_info) { -// $customers_info = $customers_info . '+' . $value1['name'] . '(' . $nums . ')'; -// } else { -// $customers_info = $value1['name'] . '(' . $nums . ')'; -// } -// } - } } - //$customers_info && $customers = $customers . '=' . $customers_info; $temp['customers'] = $customers; + $temp['c_num'] = $c_num; + $temp['orders'] = $orders; $lists[] = $temp; } } @@ -137,22 +256,15 @@ class Userslog extends HD_Controller $sum = $this->mdUsersLog->sum('customers', $where); $menus[] = ['title' => "客户数", 'value' => intval($sum['customers']), 'tag' => '人']; $sum_c = $this->mdUsersLog->sum('c_num', $where); - $sum = $this->mdUsersLog->sum('a_num', $where); - $menus[] = ['title' => "进店人数/次数", 'value' => intval($sum_c['c_num']) . '人 / ' . intval($sum['a_num']), 'tag' => '次']; - $sum = $this->mdUsersLog->sum('t_num', $where); - $menus[] = ['title' => "试驾数", 'value' => intval($sum['t_num']), 'tag' => '次']; - $sum = $this->mdUsersLog->sum('follows', $where); - $menus[] = ['title' => "跟进数", 'value' => intval($sum['follows']), 'tag' => '个']; + $menus[] = ['title' => "进店人数", 'value' => intval($sum_c['c_num']), 'tag' => '人']; $sum = $this->mdUsersLog->sum('orders', $where); $menus[] = ['title' => "订单数", 'value' => intval($sum['orders']), 'tag' => '个']; + $sum = $this->mdUsersLog->sum('t_num', $where); + $menus[] = ['title' => "试驾数", 'value' => intval($sum['t_num']), 'tag' => '次']; $sum = $this->mdUsersLog->sum('defeats', $where); $menus[] = ['title' => "战败数", 'value' => intval($sum['defeats']), 'tag' => '个']; $sum = $this->mdUsersLog->sum('bills', $where); $menus[] = ['title' => "开票数", 'value' => intval($sum['bills']), 'tag' => '个']; - $sum = $this->mdUsersLog->sum('reassigns', $where); - $menus[] = ['title' => "改派数", 'value' => intval($sum['reassigns']), 'tag' => '个']; - $sum = $this->mdUsersLog->sum('receives', $where); - $menus[] = ['title' => "接收数", 'value' => intval($sum['receives']), 'tag' => '个']; $sum = $this->mdUsersLog->sum('qy_adds', $where); $menus[] = ['title' => "新增企微", 'value' => intval($sum['qy_adds']), 'tag' => '人']; $sum = $this->mdUsersLog->sum('qy_dels', $where); @@ -162,35 +274,21 @@ class Userslog extends HD_Controller $data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total); $data['lists'] = $lists; $data['params'] = $params; - $data['_title'] = "顾问日志"; + $data['_title'] = $_title; return $data; } public function visitSelect($params) { + $_title = '顾问日志'; $lists = $where = []; if ($params['uname']) { $where["sales_id in(select id from lc_app_licheb_users where uname like '%{$params['uname']}%')"] = null; } if ($params['biz_id']) { $where['biz_id'] = $params['biz_id']; - } else if ($params['city_id'] || $params['type']) { - $where_biz['status'] = 1; - $params['type'] && $where_biz['type'] = $params['type']; - $params['city_id'] && $where_biz['city_id'] = $params['city_id']; - $params['county_id'] && $where_biz['county_id'] = $params['county_id']; - $res_biz = $this->mdBiz->select($where_biz, 'id desc', 0, 0, 'id'); - if ($res_biz) { - $str_ids = implode(',', array_column($res_biz, 'id')); - $where["biz_id in ({$str_ids})"] = null; - } else { - $where['biz_id'] = -2; - } - } else { - $params['city_id'] = ''; - $params['county_id'] = ''; - $params['biz_id'] = ''; - $params['type'] = ''; + $re_biz = $this->mdBiz->get(['id' => $params['biz_id']]); + $re_biz && $_title = $re_biz['biz_name'] . '_顾问日志'; } if ($params['time']) { $time = explode(' ~ ', $params['time']); @@ -199,27 +297,21 @@ class Userslog extends HD_Controller } $total = $this->mdCustomerVisitSales->count($where); if ($total) { - $res = $this->mdCustomerVisitSales->select($where, "id desc", $params['page'], $params['size']); - $sales_ids = $biz_ids = []; + $res = $this->mdCustomerVisitSales->select($where, "t_day desc,id desc", $params['page'], $params['size']); + $sales_ids = []; foreach ($res as $v) { $v['sales_id'] && !in_array($v['sales_id'], $sales_ids) && $sales_ids[] = $v['sales_id']; - $v['biz_id'] && !in_array($v['biz_id'], $biz_ids) && $biz_ids[] = $v['biz_id']; } - $map_sale = $map_biz = $map_city = []; + $map_sale = []; if ($sales_ids) { $str_ids = implode(',', $sales_ids); $map_sale = $this->mdUsers->map('id', 'uname', ["id in ({$str_ids})" => null]); } - if ($biz_ids) { - $str_ids = implode(',', $biz_ids); - $map_biz = $this->mdBiz->map('id', 'biz_name,type', ["id in ({$str_ids})" => null]); - } foreach ($res as $v) { - $uname = $biz_name = ''; + $uname = ''; $map_sale[$v['sales_id']] && $uname = $map_sale[$v['sales_id']]; - $map_biz[$v['biz_id']]['biz_name'] && $biz_name = $map_biz[$v['biz_id']]['biz_name']; $follows = $v['t_follows'] + $v['h_follows'] + $v['w_follows']; - $temp = ['uname' => $uname, 'biz_name' => $biz_name, 'follows' => $follows, 't_follows' => $v['t_follows'] + $temp = ['uname' => $uname, 'follows' => $follows, 't_follows' => $v['t_follows'] , 'h_follows' => $v['h_follows'], 'w_follows' => $v['w_follows'], 't_day' => $v['t_day']]; $lists[] = $temp; } @@ -238,7 +330,7 @@ class Userslog extends HD_Controller $data['pager'] = array('count' => ceil($total / $params['size']), 'curr' => $params['page'], 'totle' => $total); $data['lists'] = $lists; $data['params'] = $params; - $data['_title'] = "顾问日志"; + $data['_title'] = $_title; return $data; } @@ -268,35 +360,76 @@ class Userslog extends HD_Controller $params = $this->input->get(); $params['page'] = 1; $params['size'] = 10000; - $data = $indexs = array(); - if ($params['tab'] == 2) { - $res = $this->visitSelect($params); - $indexs = ['biz_name' => '门店', 'uname' => '顾问', 'follows' => '计划跟进数', 'h_follows' => '已跟进数' - , 't_follows' => '今日新增未跟进数', 'w_follows' => '逾期未跟进数', 't_day' => '日期']; - } else { - $res = $this->dataSelect($params); + $data = $indexs = []; + if ($params['tab'] == 1) {//客户统计 + $res = $this->dataUsersSelect($params); $offlineSources = $this->mdCustomers->offlineSources(); - $indexs = ['biz_name' => '门店', 'uname' => '顾问', 'customers' => '客户数']; + $indexs = ['uname' => '顾问', 'customers' => '客户数︾']; foreach ($offlineSources as $key1 => $value1) { $indexs['customer_' . $key1] = '【' . $value1['name'] . '】'; foreach ($value1['list'] as $key2 => $value2) { $indexs['customer_' . $key2] = $value2; } } - $indexs['c_num'] = '进店人数'; - $indexs['a_num'] = '进店次数'; + $indexs['c_num'] = '进店人数︾'; + foreach ($offlineSources as $key1 => $value1) { + $indexs['c_num_' . $key1] = '【' . $value1['name'] . '】'; + foreach ($value1['list'] as $key2 => $value2) { + $indexs['c_num_' . $key2] = $value2; + } + } + $indexs['orders'] = '订单数︾'; + foreach ($offlineSources as $key1 => $value1) { + $indexs['order_' . $key1] = '【' . $value1['name'] . '】'; + foreach ($value1['list'] as $key2 => $value2) { + $indexs['order_' . $key2] = $value2; + } + } $indexs['t_num'] = '试驾数'; - $indexs['follows'] = '跟进数'; - $indexs['orders'] = '订单数'; $indexs['defeats'] = '战败数'; $indexs['bills'] = '开票数'; - $indexs['reassigns'] = '改派数'; - $indexs['receives'] = '接收数'; $indexs['qy_adds'] = '新增企微'; $indexs['qy_dels'] = '删除企微'; $indexs['log_date'] = '日期'; + $fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']]; + } else if ($params['tab'] == 2) {//回访统计 + $res = $this->visitSelect($params); + $indexs = ['biz_name' => '门店', 'uname' => '顾问', 'follows' => '计划跟进数', 'h_follows' => '已跟进数' + , 't_follows' => '今日新增未跟进数', 'w_follows' => '逾期未跟进数', 't_day' => '日期']; + $fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']]; + } else { + $res = $this->dataBizSelect($params); + $offlineSources = $this->mdCustomers->offlineSources(); + $indexs = ['biz_name' => '门店', 'customers' => '客户数︾']; + foreach ($offlineSources as $key1 => $value1) { + $indexs['customer_' . $key1] = '【' . $value1['name'] . '】'; + foreach ($value1['list'] as $key2 => $value2) { + $indexs['customer_' . $key2] = $value2; + } + } + $indexs['c_num'] = '进店人数︾'; + foreach ($offlineSources as $key1 => $value1) { + $indexs['c_num_' . $key1] = '【' . $value1['name'] . '】'; + foreach ($value1['list'] as $key2 => $value2) { + $indexs['c_num_' . $key2] = $value2; + } + } + $indexs['orders'] = '订单数︾'; + foreach ($offlineSources as $key1 => $value1) { + $indexs['order_' . $key1] = '【' . $value1['name'] . '】'; + foreach ($value1['list'] as $key2 => $value2) { + $indexs['order_' . $key2] = $value2; + } + } + $indexs['t_num'] = '试驾数'; + $indexs['defeats'] = '战败数'; + $indexs['bills'] = '开票数'; + $indexs['qy_adds'] = '企微数'; + $indexs['reassigns'] = '改派数'; + $indexs['receives'] = '接收数'; + $indexs['log_date'] = '日期'; + $fileName = $res['_title']; } - $fileName = $res['_title'] . '_' . $this->tabAry[$params['tab']]; foreach ($res['lists'] as $key => $value) { $data[] = $value; } diff --git a/admin/views/app/licheb/userslog/lists.php b/admin/views/app/licheb/userslog/lists.php index 0f1911d7..90775ca9 100644 --- a/admin/views/app/licheb/userslog/lists.php +++ b/admin/views/app/licheb/userslog/lists.php @@ -1,15 +1,3 @@ -