1259 lines
58 KiB
PHP
1259 lines
58 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: xuxb
|
|
* Date: 2021/7/26
|
|
* Time: 11:20
|
|
*/
|
|
class Customer extends HD_Controller
|
|
{
|
|
private $searchTpAry = array('mobile' => '客户手机号', 'cid' => '客户编号');
|
|
private $searchTimeAry = array('p_time' => '派单/建档时间', 'cont_time' => '最后联系时间', 'dt_time' => '首次到店时间', 'order_time' => '下定时间', 'def_time' => '战败时间', 'c_time' => '创建时间',);
|
|
|
|
protected $log_dir;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
|
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
|
|
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
|
|
$this->load->model('receiver/receiver_customer_tagdata_model', 'mdCustomerTagdata');
|
|
$this->load->model('receiver/receiver_clues_model', 'clues_model');
|
|
$this->load->model('receiver/receiver_clues_cfrom_model', 'clues_cfrom_model');
|
|
$this->load->model('receiver/receiver_yx_model');
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->load->model('app/licheb/app_licheb_users_model');
|
|
$this->load->model("biz/biz_model");
|
|
$this->load->model('area_model');
|
|
$this->load->model('auto/auto_brand_model');
|
|
$this->load->model('auto/auto_series_model');
|
|
$this->load->model('app/paic/app_paic_users_model');
|
|
|
|
$this->log_dir = 'receiver_' . get_class($this);
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
return $this->lists();
|
|
}
|
|
|
|
public function lists()
|
|
{
|
|
$status_arr = $this->customers_model->get_status();
|
|
unset($status_arr['-1']);
|
|
|
|
$params = $this->input->get();
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
|
|
$where = $this->get_where($params);
|
|
$count = $this->customers_model->count($where);
|
|
$lists = [];
|
|
|
|
//$wxqyAry = $this->customers_model->wxqyAry();
|
|
$wxgrAry = $this->customers_model->wxgrAry();
|
|
if ($count) {
|
|
$fileds = 'id,cid,name,mobile,cf_title,p_time,cont_time,admin_id,status,biz_id,level,of_id,of2_id,wxgr,c_time,county_id,brand_id,series_id';
|
|
$rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds);
|
|
//获取车管家
|
|
$admin_id_arr = array_unique(array_column($rows, 'admin_id'));
|
|
$admin_id_arr && $admin_rows = $this->app_licheb_users_model->get_map_by_ids($admin_id_arr, 'id,uname');
|
|
//获取门店
|
|
$biz_id_arr = array_unique(array_column($rows, 'biz_id'));
|
|
$biz_id_arr && $biz_rows = $this->biz_model->get_map_by_ids($biz_id_arr, 'id,biz_name,county_id');
|
|
//车型
|
|
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id'));
|
|
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id'));
|
|
|
|
foreach ($biz_rows as $v) {
|
|
$county_id_arr[] = $v[0]['county_id'];
|
|
}
|
|
|
|
if ($county_id_arr) {
|
|
$str_ids = implode(',', $county_id_arr);
|
|
$map_area = $this->area_model->map('county_id', '', ["county_id in ({$str_ids})" => null], '', 0, $size, 'county_id,province_name,city_name,county_name');
|
|
}
|
|
|
|
//获取来源
|
|
$cf_id_arr = array_unique(array_column($rows, 'of2_id'));
|
|
if ($cf_id_arr) {
|
|
$cf_id_str = implode(',', $cf_id_arr);
|
|
$res_cfrom = $this->clues_cfrom_model->select(["id in({$cf_id_str})" => null], 'id desc', 0, 0, 'id,title,pid');
|
|
$cf_pid_arr = array_unique(array_column($res_cfrom, 'pid'));
|
|
if ($cf_pid_arr) {
|
|
$cf_pid_str = implode(',', $cf_pid_arr);
|
|
$map_cf_pid = $this->clues_cfrom_model->map('id', 'title', ["id in({$cf_pid_str})" => null]);
|
|
}
|
|
foreach ($res_cfrom as $key => $val) {
|
|
$title = $val['title'];
|
|
if ($val['pid']) {//一级分类
|
|
$map_cf_pid[$val['pid']] && $title = $map_cf_pid[$val['pid']] . '-' . $title;
|
|
}
|
|
$cf_title_arr[$val['id']] = $title;
|
|
}
|
|
}
|
|
|
|
foreach ($rows as $key => $val) {
|
|
$mobile_sub = $val['mobile'];
|
|
$of_title = $cf_title_arr[$val['of2_id']] ? $cf_title_arr[$val['of2_id']] : $cf_title_arr[$val['of_id']];
|
|
$area = $map_area[$biz_rows[$val['biz_id']][0]['county_id']][0];
|
|
$brand_detail = '';
|
|
if ($brands[$val['brand_id']]) {
|
|
$brand_detail = $brands[$val['brand_id']][0]['name'];
|
|
}
|
|
if ($brands[$val['brand_id']]) {
|
|
$brand_detail .= '-' . $series[$val['series_id']][0]['name'];
|
|
}
|
|
|
|
$lists[] = array(
|
|
'id' => $val['id'],
|
|
'cid' => $val['cid'],
|
|
'name' => $val['name'],
|
|
'mobile' => $val['mobile'],
|
|
'mobile_sub' => $this->get_mobile(['of_id' => $val['of_id'], 'mobile' => $mobile_sub]),
|
|
'level' => $val['level'],
|
|
'of_title' => $of_title,
|
|
'of_id' => $val['of_id'],
|
|
'of2_id' => $val['of2_id'],
|
|
'status_name' => $status_arr[$val['status']],
|
|
'wxgr_name' => $wxgrAry[$val['wxgr']],
|
|
'brand_detail' => $brand_detail,
|
|
'admin_name' => isset($admin_rows[$val['admin_id']]) ? $admin_rows[$val['admin_id']][0]['uname'] : '',
|
|
'biz_poi' => $area ? "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}" : '',
|
|
'biz_name' => isset($biz_rows[$val['biz_id']]) ? $biz_rows[$val['biz_id']][0]['biz_name'] : '',
|
|
'c_time' => $val['c_time'] != '0' ? date('Y-m-d H:i:s', $val['c_time']) : '',
|
|
'p_time' => $val['p_time'],
|
|
'cont_time' => $val['cont_time'] != '0000-00-00 00:00:00' ? $val['cont_time'] : '',
|
|
);
|
|
}
|
|
}
|
|
|
|
$tag_data = $params['tags'] ? explode(',', $params['tags']) : '';
|
|
$show_info['tags'] = $this->get_tag(0, 0, $tag_data);
|
|
$tag_data = $params['tagsIntention'] ? explode(',', $params['tagsIntention']) : '';
|
|
$show_info['tagsIntention'] = $this->get_tag(0, 2, $tag_data);
|
|
$tag_data = $params['tagsDefeat'] ? explode(',', $params['tagsDefeat']) : '';
|
|
$show_info['tagsDefeat'] = $this->get_tag(0, 1, $tag_data);
|
|
//客户成功经理
|
|
$qdjl_lists = $this->app_licheb_users_model->select(array('group_id' => 4, 'status' => 1, 'biz_id<>' => '0'), 'id desc', 0, 0, 'id,uname as name');
|
|
$show_info['levelAry'] = $this->customers_model->get_sdata('level');
|
|
$show_info['cfroms'] = $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => 0), '', 0, 0, 'id, title');
|
|
$show_info['cfroms2'] = $params['of_id'] ? $this->clues_cfrom_model->map('id', 'title', array('status' => 1, 'pid' => $params['of_id']), '', 0, 0, 'id, title') : [];
|
|
$show_info['wxgrAry'] = $wxgrAry;
|
|
$this->data['show_info'] = $show_info;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
$this->data['searchTpAry'] = $this->searchTpAry;
|
|
$this->data['searchTimeAry'] = $this->searchTimeAry;
|
|
$this->data['params'] = $params;
|
|
$this->data['status_arr'] = $status_arr;
|
|
$this->data['qdjl_lists'] = $qdjl_lists;
|
|
$this->data['provinces'] = $this->province_ary();
|
|
//$this->data['export_button'] = SUPER_ADMIN == $this->role ? 1 : 0;
|
|
$this->data['export_button'] = 1;
|
|
$this->data['_title'] = '客户列表';
|
|
return $this->show_view('receiver/customer/lists', true);
|
|
}
|
|
|
|
public function lists_statplan()
|
|
{
|
|
$params = $this->input->get();
|
|
$page = $params['page'] = $params['page'] ? intval($params['page']) : 1;
|
|
$size = $params['size'] = $params['size'] ? intval($params['size']) : 20;
|
|
!$params['of_id'] && $params['of_id'] = '';
|
|
!$params['of2_id'] && $params['of2_id'] = '';
|
|
!$params['sp_name'] && $params['sp_name'] = '';
|
|
$where = array();
|
|
if ($params['of_id']) {
|
|
$where['of_id'] = $params['of_id'];
|
|
}
|
|
if ($params['of2_id']) {
|
|
$where['of2_id'] = $params['of2_id'];
|
|
}
|
|
if ($params['sp_name']) {
|
|
$where["sp_name like '%{$params['sp_name']}%'"] = null;
|
|
}
|
|
|
|
$count = $this->statplan->count($where);
|
|
$lists = [];
|
|
$offlineSources = $this->customers_model->offlineSources();
|
|
if ($count) {
|
|
$rows = $this->statplan->select($where, 'id desc', $page, $size, '*');
|
|
foreach ($rows as $key => $val) {
|
|
$of_title = '';
|
|
if ($val['of_id']) {
|
|
$of_ary = $offlineSources[$val['of_id']];
|
|
$of_title = $of_ary['name'];
|
|
$val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']];
|
|
}
|
|
$lists[] = array(
|
|
'id' => $val['id'],
|
|
'sp_name' => $val['sp_name'],
|
|
'mobile' => $val['mobile'],
|
|
'of_title' => $of_title,
|
|
's_date' => $val['s_date'],
|
|
'e_date' => $val['e_date'],
|
|
'last_date' => $val['last_date'],
|
|
'c_time' => date('Y-m-d H:i:s', $val['c_time']),
|
|
'u_time' => $val['u_time'],
|
|
);
|
|
}
|
|
}
|
|
|
|
$show_info['offlineSourcesAry'] = $this->customers_model->offlineSources_search();
|
|
$this->data['show_info'] = $show_info;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['pager'] = array('count' => ceil($count / $size), 'curr' => $page, 'totle' => $count);
|
|
$this->data['params'] = $params;
|
|
$this->data['_title'] = '客户统计计划列表';
|
|
return $this->show_view('receiver/customer/lists_statplan', true);
|
|
}
|
|
|
|
public function lists_statdata()
|
|
{
|
|
$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_statdata($id);
|
|
$indexs = $stat_data['indexs'];
|
|
$lists = $stat_data['lists'];
|
|
|
|
$this->data['indexs'] = $indexs;
|
|
$this->data['lists'] = $lists;
|
|
$this->data['params'] = $params;
|
|
$this->data['_title'] = $re['sp_name'] . '_统计数据';
|
|
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();
|
|
}
|
|
|
|
$lists = array();
|
|
$where = ['spid' => $id];
|
|
$rows_group_id_k = $this->statdata->select_groupby('group_id,k', $where, 'group_id,k', 0, 0, 'group_id,k');
|
|
$rows_stat_date = $this->statdata->select_groupby('stat_date', $where, 'stat_date', 0, 0, 'stat_date');
|
|
$key_v = $this->statdata->map($map_key = 'k', $map_value = 'v', $where, $order = '', $page = 0, $page_size = 0, $select = "concat(group_id, '-', k, '-', stat_date) as k, v");
|
|
$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('</b>', '', str_replace('<b>', '', $k)) : $k;
|
|
foreach ($rows_stat_date as $key_date => $val_date) {
|
|
$stat_date = $val_date['stat_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_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, '<b>总数</b>' 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('<b>',biz_name,'</b>'),'<b>未分配门店</b>') 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, '<b>战败</b>' 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, '<b>战败-无购车意向</b>' 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, '<b>战败-有购车意向</b>' 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, '<b>加V(扣除 战败-无购车意向)</b>' 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, '<b>未见客户的见面意向</b>' 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, '<b>到店客户的购车意向</b>' 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, '<b>订单数</b>' 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, '<b>加企微</b>' 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('</b>', '', str_replace('<b>', '', $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'] = '';
|
|
!$params['cf_title'] && $params['cf_title'] = '';
|
|
!$params['qdjl_id'] && $params['qdjl_id'] = '';
|
|
!$params['level'] && $params['level'] = '';
|
|
!is_numeric($params['c_brand']) && $params['c_brand'] = '';
|
|
!$params['of_id'] && $params['of_id'] = '';
|
|
!$params['of2_id'] && $params['of2_id'] = '';
|
|
!$params['province_id'] && $params['province_id'] = '';
|
|
!$params['city_id'] && $params['city_id'] = '';
|
|
!$params['county_id'] && $params['county_id'] = '';
|
|
!$params['biz_type'] && $params['biz_type'] = '';
|
|
!$params['tags'] && $params['tags'] = '';
|
|
!$params['tagsIntention'] && $params['tagsIntention'] = '';
|
|
!$params['tagsDefeat'] && $params['tagsDefeat'] = '';
|
|
!$params['brand_id'] && $params['brand_id'] = 0;
|
|
!$params['series_id'] && $params['series_id'] = 0;
|
|
|
|
$where = array('status>=0' => null);
|
|
if ($_SESSION['admin_info']['biz_id']) {
|
|
$biz_ids = implode(',', $_SESSION['admin_info']['biz_id']);
|
|
if ($params['biz_type']) {
|
|
$where["biz_id in(select id from lc_biz where type={$params['biz_type']} and id in({$biz_ids}))"] = null;
|
|
} else {
|
|
$where["biz_id in ($biz_ids)"] = null;
|
|
}
|
|
} else if ($params['biz_type']) {
|
|
$where["biz_id in(select id from lc_biz where type={$params['biz_type']})"] = null;
|
|
}
|
|
if ($params['cid']) {
|
|
$where["{$params['search_tp']} like '%{$params['cid']}%'"] = null;
|
|
}
|
|
if ($params['level']) {
|
|
$where['level'] = $params['level'];
|
|
}
|
|
if ($params['brand_id']) {
|
|
$where['brand_id'] = $params['brand_id'];
|
|
}
|
|
if ($params['series_id']) {
|
|
$where['series_id'] = $params['series_id'];
|
|
}
|
|
if ($params['of_id']) {
|
|
$where['of_id'] = $params['of_id'];
|
|
}
|
|
if ($params['of2_id']) {
|
|
$where['of2_id'] = $params['of2_id'];
|
|
}
|
|
if ($params['province_id']) {
|
|
$where['province_id'] = $params['province_id'];
|
|
}
|
|
if ($params['city_id']) {
|
|
$where['city_id'] = $params['city_id'];
|
|
}
|
|
if ($params['county_id']) {
|
|
$where['county_id'] = $params['county_id'];
|
|
}
|
|
if (strlen($params['wxqy'])) {
|
|
$where["wxqy"] = $params['wxqy'];
|
|
} else {
|
|
$params['wxqy'] = '';
|
|
}
|
|
if (strlen($params['wxgr'])) {
|
|
$where["wxgr"] = $params['wxgr'];
|
|
} else {
|
|
$params['wxgr'] = '';
|
|
}
|
|
!$params['search_tp'] && $params['search_tp'] = 'mobile';
|
|
strlen($params['status']) && $where["status"] = $params['status'];
|
|
!strlen($params['status']) && $params['status'] = '';
|
|
if ($params['qdjl_id']) {
|
|
$where["biz_id in(select biz_id from lc_app_licheb_channel_biz where uid={$params['qdjl_id']})"] = null;
|
|
}
|
|
//销售员筛选
|
|
if ($params['admin_id']) {
|
|
$where['admin_id'] = $params['admin_id'];
|
|
} else if ($params['biz_id_admin']) {
|
|
$where['biz_id'] = $params['biz_id_admin'];
|
|
} else if ($params['county_id_admin']) {
|
|
$where["biz_id in(select id from lc_biz where county_id={$params['county_id_admin']})"] = null;
|
|
} else if ($params['city_id_admin']) {
|
|
$where["biz_id in(select id from lc_biz where city_id={$params['city_id_admin']})"] = null;
|
|
} else if ($params['province_id_admin']) {
|
|
$where["biz_id in(select id from lc_biz where province_id={$params['province_id_admin']})"] = null;
|
|
}
|
|
|
|
$where[$this->customers_model->csbizidWhere($params['cs_biz_id'])] = null;
|
|
!$params['province_id_admin'] && $params['province_id_admin'] = '';
|
|
!$params['city_id_admin'] && $params['city_id_admin'] = '';
|
|
!$params['county_id_admin'] && $params['county_id_admin'] = '';
|
|
!$params['biz_id_admin'] && $params['biz_id_admin'] = '';
|
|
!$params['admin_id'] && $params['admin_id'] = '';
|
|
if ($params['c_time']) {
|
|
$c_time = explode(' ~ ', $params['c_time']);
|
|
$c_time[0] && $where["c_time >="] = strtotime($c_time[0] . ' 00:00:00');
|
|
$c_time[1] && $where["c_time <="] = strtotime($c_time[1] . ' 23:59:59');
|
|
}
|
|
if ($params['p_time']) {
|
|
$p_time = explode(' ~ ', $params['p_time']);
|
|
$p_time[0] && $where["p_time >="] = $p_time[0] . ' 00:00:00';
|
|
$p_time[1] && $where["p_time <="] = $p_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['cont_time']) {
|
|
$cont_time = explode(' ~ ', $params['cont_time']);
|
|
$cont_time[0] && $where["cont_time >="] = $cont_time[0] . ' 00:00:00';
|
|
$cont_time[1] && $where["cont_time <="] = $cont_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['u_time']) {
|
|
$u_time = explode(' ~ ', $params['u_time']);
|
|
$u_time[0] && $where["u_time >="] = $u_time[0] . ' 00:00:00';
|
|
$u_time[1] && $where["u_time <="] = $u_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['dt_time']) {
|
|
$dt_time = explode(' ~ ', $params['dt_time']);
|
|
$dt_time[0] && $where["dt_time >="] = $dt_time[0] . ' 00:00:00';
|
|
$dt_time[1] && $where["dt_time <="] = $dt_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['order_time']) {
|
|
$order_time = explode(' ~ ', $params['order_time']);
|
|
$order_time[0] && $where["order_time >="] = $order_time[0] . ' 00:00:00';
|
|
$order_time[1] && $where["order_time <="] = $order_time[1] . ' 23:59:59';
|
|
}
|
|
if ($params['def_time']) {
|
|
$order_time = explode(' ~ ', $params['def_time']);
|
|
$order_time[0] && $where["def_time >="] = $order_time[0] . ' 00:00:00';
|
|
$order_time[1] && $where["def_time <="] = $order_time[1] . ' 23:59:59';
|
|
}
|
|
|
|
if ($params['tags']) {
|
|
$where = $this->tagWhere($where, $params['tags']);
|
|
} else if ($params['tagsIntention']) {
|
|
$where = $this->tagWhere($where, $params['tagsIntention']);
|
|
} else if ($params['tagsDefeat']) {
|
|
$where['status'] = 3;
|
|
$where = $this->tagWhere($where, $params['tagsDefeat']);
|
|
}
|
|
// 指定顾问的回访客户,通过 vsid + vdststus 时间
|
|
if ($vsid = $params['vsid']) {
|
|
$vdststus = $params['vdststus'] ? intval($params['vdststus']) : 0;
|
|
$vdststus_parm = $vdststus ? " and lc_vd.status = {$vdststus}" : "";
|
|
$where["id in(select lc_vd.c_id from lc_receiver_customer_visit_data lc_vd join lc_receiver_customer_visit_sales lc_vs on lc_vd.biz_id = lc_vs.biz_id and lc_vd.sales_id = lc_vs.sales_id and lc_vd.t_day = lc_vs.t_day and lc_vs.id = {$vsid} {$vdststus_parm})"] = null;
|
|
}
|
|
if ($this->admin_biz_str) {
|
|
$where["biz_id in ($this->admin_biz_str)"] = null;
|
|
}else{
|
|
$this->belong && $where["biz_id in(select id from lc_biz where province_id=".$this->limit_province_id.")"] = null;
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
public function get()
|
|
{
|
|
$id = $this->input->get('id');
|
|
$this->load->model('auto/auto_series_model');
|
|
$select = '*, (select city_name from lc_area where city_id = lc_receiver_customers.city_id limit 1) as city_name, (select county_name from lc_area where county_id = lc_receiver_customers.county_id limit 1) as county_name';
|
|
$row = $this->customers_model->get(array('id' => $id), $select);
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
|
|
}
|
|
$if_driver = 1 == $row['if_driver'] ? '是' : '否';
|
|
$is_top = 1 == $row['is_top'] ? '是' : '否';
|
|
|
|
$row_biz = $this->biz_model->get(array('id' => $row['biz_id']));
|
|
//获取销售员
|
|
$row_admin = $this->app_licheb_users_model->get(array('id' => $row['admin_id']), 'id,uname');
|
|
//操作日志
|
|
$rows_log = $this->customer_oplogs_model->select(array('customer_id' => $id), 'id desc', 0, 0);
|
|
//用户信息
|
|
$mobile_sub = $row['mobile'];
|
|
|
|
$of_title = '';
|
|
if ($row['of_id']) {
|
|
$of = $this->clues_cfrom_model->get(array('id' => $row['of_id']));
|
|
$of_title = $of['title'];
|
|
if ($row['of2_id']) {
|
|
$of = $this->clues_cfrom_model->get(array('id' => $row['of2_id']));
|
|
$of_title .= '-' . $of['title'];
|
|
}
|
|
}
|
|
|
|
$tag_defeat = $tag_intention = '';
|
|
$tag = $this->get_tag($row['id']);
|
|
if ($row['status'] == 3) {
|
|
$tag_defeat = $this->get_tag($row['id'], 1, '', 1);
|
|
}
|
|
$tag_intention = $this->get_tag($row['id'], 2, '', 1);
|
|
|
|
if ($row['county_id']) {
|
|
$area = $this->area_model->get(array('county_id' => $row['county_id']));
|
|
$poi = "{$area['province_name']}-{$area['city_name']}-{$area['county_name']}";
|
|
} elseif ($row['city_id']) {
|
|
$area = $this->area_model->get(array('city_id' => $row['city_id']));
|
|
$poi = "{$area['province_name']}-{$area['city_name']}";
|
|
} elseif ($row['province_id']) {
|
|
$area = $this->area_model->get(array('province_id' => $row['province_id']));
|
|
$poi = "{$area['province_name']}";
|
|
}
|
|
$brand_detail = '';
|
|
if ($row['brand_id']) {
|
|
$brand = $this->auto_brand_model->get(['id' => $row['brand_id']]);
|
|
$brand && $brand_detail = $brand['name'];
|
|
}
|
|
if ($row['series_id']) {
|
|
$series = $this->auto_series_model->get(['id' => $row['series_id']]);
|
|
$series && $brand_detail .= '-' . $series['name'];
|
|
}
|
|
$paic_user = '';
|
|
if ($row['cf_pid']) {
|
|
$paic_user = $this->app_paic_users_model->get(['id' => $row['cf_pid']]);
|
|
}
|
|
$info = array(
|
|
'id' => $row['id'],
|
|
'name' => $row['name'],
|
|
'level' => $row['level'],
|
|
'mobile' => $this->get_mobile(['of_id' => $row['of_id'], 'mobile' => $mobile_sub]),
|
|
'of_title' => $of_title,
|
|
'wx_name' => $this->customers_model->wxgrAry($row['wxgr']),
|
|
'c_time' => date('Y-m-d H:i:s', $row['c_time']),
|
|
'p_time' => $row['p_time'],
|
|
'status' => $row['status'],
|
|
'tag' => $tag,
|
|
'tag_defeat' => $tag_defeat,
|
|
'tag_intention' => $tag_intention,
|
|
'poi' => $poi,
|
|
'biz' => $row_biz['biz_name'],
|
|
'time_name' => $row['clue_id'] ? '派单时间' : '建档时间',
|
|
'brand_detail' => $brand_detail,
|
|
'role' => $this->role,
|
|
'cf_name' => $paic_user ? $paic_user['name'] : ''
|
|
);
|
|
|
|
//到店信息
|
|
$toshop = array(
|
|
array(
|
|
array('title' => '签到时间', 'value' => $row['dt_time'] != '0000-00-00 00:00:00' ? $row['dt_time'] : ''),
|
|
array('title' => '到店次数', 'value' => $row['a_num']),
|
|
array('title' => '试驾次数', 'value' => $row['t_num']),
|
|
),
|
|
array(
|
|
array('title' => '车管家', 'value' => $row_admin['uname']),
|
|
array('title' => '最后联系时间', 'value' => $row['cont_time'] != '0000-00-00 00:00:00' ? $row['cont_time'] : ''),
|
|
array('title' => '重点关注', 'value' => $is_top),
|
|
),
|
|
);
|
|
|
|
//操作日志
|
|
$logs = array();
|
|
foreach ($rows_log as $key => $value) {
|
|
$rec_text = $rec_url = '';
|
|
if ($value['type'] == 2) {
|
|
$record = '';
|
|
if ($value['sub_type'] == Receiver_customer_oplogs_model::SUB_TYPE_XZ) {
|
|
$rec_row = $this->receiver_xz_model->get(['id' => $value['log']], 'rec_url,duration');
|
|
$rec_row['rec_url'] && $record = $rec_row['rec_url'];
|
|
} else {
|
|
$rec_row = $this->receiver_yx_model->get(['id' => $value['log']], 'rec_url,duration');
|
|
$rec_row['rec_url'] && $record = get_yx_video($rec_row['rec_url']);
|
|
}
|
|
if ($rec_row['duration']) {
|
|
$record && $rec_url = $record;
|
|
!$rec_row['rec_url'] && $rec_text = '录音暂未生成';
|
|
} else {
|
|
$rec_text = '未接通';
|
|
}
|
|
}
|
|
$imgs = [];
|
|
if ($value['imgs']) {
|
|
$json_imgs = json_decode($value['imgs'], true);
|
|
foreach ($json_imgs as $key1 => $value1) {
|
|
$imgs[] = build_qiniu_image_url($value1);
|
|
}
|
|
}
|
|
$logs[] = array(
|
|
'uname' => $value['uname'],
|
|
'log' => $value['log'],
|
|
'imgs' => $imgs,
|
|
'rec_url' => $rec_url,
|
|
'rec_text' => $rec_text,
|
|
'type_name' => $this->customer_oplogs_model->typeAry()[$value['type']],
|
|
'c_time' => date('Y-m-d H:i', $value['c_time'])
|
|
);
|
|
}
|
|
|
|
//状态值,-1不显示
|
|
$statusAry = $this->customers_model->get_status();
|
|
unset($statusAry['-1']);
|
|
|
|
$this->data['statusAry'] = $statusAry;
|
|
$this->data['info'] = $info;
|
|
$this->data['toshop'] = $toshop;
|
|
$this->data['logs'] = $logs;
|
|
$this->data['_title'] = '客户详情';
|
|
return $this->show_view('receiver/customer/get', true);
|
|
}
|
|
|
|
public function get_statplan()
|
|
{
|
|
$id = intval($this->input->get('id'));
|
|
if ($id) {
|
|
$url = "/receiver/customer/edit_statplan";
|
|
$re = $this->statplan->get(['id' => $id]);
|
|
if (!$re) {
|
|
return $this->show_json(SYS_CODE_FAIL, '计划不存在!');
|
|
}
|
|
$sp_name = $re['sp_name'];
|
|
$of_id = $re['of_id'];
|
|
$of2_id = $re['of2_id'];
|
|
$s_date = $re['s_date'];
|
|
$e_date = $re['e_date'];
|
|
$s_e_date = $s_date . ' ~ ' . $e_date;
|
|
} else {
|
|
$url = "/receiver/customer/edit_statplan";
|
|
$sp_name = '';
|
|
$of_id = '';
|
|
$of2_id = '';
|
|
$s_e_date = '';
|
|
}
|
|
$this->data['info'] = ['id' => $id, 'sp_name' => $sp_name, 'of_id' => $of_id, 'of2_id' => $of2_id, 's_e_date' => $s_e_date, 'url' => $url];
|
|
$this->data['show_info'] = ['offlineSourcesAry' => $this->customers_model->offlineSources()];
|
|
return $this->show_view('/receiver/customer/edit_statplan');
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
// TODO: Implement add() method.
|
|
}
|
|
|
|
/**
|
|
* 新增日志
|
|
* @return bool
|
|
*/
|
|
function add_log()
|
|
{
|
|
$params = $this->input->post();
|
|
if (!$params['id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
|
|
}
|
|
if (!$params['log']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '请输入内容!');
|
|
}
|
|
$addData = array(
|
|
'customer_id' => $params['id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($params['type']),
|
|
'log' => $params['log'],
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->customer_oplogs_model->add($addData);
|
|
if ($id) {
|
|
return $this->show_json(SYS_CODE_SUCCESS, '添加成功');
|
|
} else {
|
|
debug_log("[error]" . $this->customer_oplogs_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
return $this->show_json(SYS_CODE_FAIL, '添加失败');
|
|
}
|
|
}
|
|
|
|
public function edit_statplan()
|
|
{
|
|
$params = $this->input->post()['info'];
|
|
$id = intval($params['id']);
|
|
if (!$params['sp_name']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '计划名不能为空!');
|
|
}
|
|
if (!$params['of_id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '来源1不能为空!');
|
|
}
|
|
if (!$params['of2_id']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '来源2不能为空!');
|
|
}
|
|
if (!$params['s_e_date']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '起止日期不能为空!');
|
|
}
|
|
|
|
$s_e_date = explode(' ~ ', $params['s_e_date']);
|
|
$s_date = $s_e_date[0];
|
|
$e_date = $s_e_date[1];
|
|
if (!$s_date) {
|
|
return $this->show_json(SYS_CODE_FAIL, '开始日期不能为空!');
|
|
}
|
|
if (!$e_date) {
|
|
return $this->show_json(SYS_CODE_FAIL, '结束日期不能为空!');
|
|
}
|
|
|
|
$data = [
|
|
'sp_name' => $params['sp_name'],
|
|
'of_id' => $params['of_id'],
|
|
'of2_id' => $params['of2_id'],
|
|
's_date' => $s_date,
|
|
'e_date' => $e_date,
|
|
];
|
|
|
|
if (!$id) {
|
|
$data['c_time'] = time();
|
|
$res = $this->statplan->add($data);
|
|
} else {
|
|
$res = $this->statplan->update($data, array('id' => $id));
|
|
}
|
|
if (!$res) {
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑
|
|
* @return bool
|
|
*/
|
|
public function edit()
|
|
{
|
|
$info = $this->input->post('info');
|
|
if (!$info) {
|
|
return $this->show_json(SYS_CODE_FAIL, '非法参数!');
|
|
}
|
|
|
|
$row = $this->customers_model->get(array('id' => $info['id']));
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户信息不存在!');
|
|
}
|
|
|
|
$msg = '修改成功';
|
|
$code = SYS_CODE_SUCCESS;
|
|
if ($info['editType'] == 1) {
|
|
//更新状态
|
|
$statuAry = $this->customers_model->get_status();
|
|
$status_name = $statuAry[$row['status']];
|
|
$status_name_up = $statuAry[$info['status']];
|
|
$log = '更新状态(' . $status_name . ')为(' . $status_name_up . ')';
|
|
$up_data['status'] = $info['status'];
|
|
if ($info['status'] == 1 && $row['dt_time'] == '0000-00-00 00:00:00') {//修改首次到店时间
|
|
$up_data['dt_time'] = date('Y-m-d H:i:s');
|
|
}
|
|
$ret = $this->customers_model->update($up_data, array('id' => $info['id']));
|
|
if (!$ret) {
|
|
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
$code = SYS_CODE_FAIL;
|
|
$msg = '修改状态失败';
|
|
} else {
|
|
$msg = '修改状态成功';
|
|
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
|
|
}
|
|
} else if ($info['editType'] == 2) {
|
|
//更新客户信息
|
|
if ($info['name'] == $row['name']) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户姓名未修改!');
|
|
}
|
|
$log = '更新客户姓名(' . $row['name'] . ')为(' . $info['name'] . ')';
|
|
$ret = $this->customers_model->update(array('name' => $info['name']), array('id' => $info['id']));
|
|
if (!$ret) {
|
|
debug_log("[error]" . $this->customers_model->db->last_query(), __FUNCTION__, $this->log_dir);
|
|
$code = SYS_CODE_FAIL;
|
|
$msg = '修改用户信息失败';
|
|
} else {
|
|
$msg = '修改用户信息成功';
|
|
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log));
|
|
}
|
|
} else if ($info['editType'] == 3 || $info['editType'] == 4) {
|
|
$id = $info['id'];
|
|
//客户标签
|
|
if (!$info['tag'] && $info['editType'] == 3) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户画像不存在!');
|
|
}
|
|
$add_tag = [];
|
|
//查找已加入标签
|
|
$res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');
|
|
$tag_data = $res_td ? array_unique(array_column($res_td, 't_id')) : '';
|
|
$tag_lists = $info['editType'] == 3 ? $info['tag'] : $info['invalid_user_tag'];
|
|
foreach ($tag_lists as $key => $val) {
|
|
foreach ($val['list'] as $key2 => $val2) {
|
|
if ($val['type'] == 'checkbox') {
|
|
if ($val2['checked'] == 'true') {
|
|
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
|
|
$add_tag[] = ['c_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
|
|
}
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
|
|
$this->mdCustomerTagdata->delete(['c_id' => $id, 't_id' => $val2['id']]);
|
|
}
|
|
}
|
|
} else {
|
|
if ($val['value'] == $val2['id']) {
|
|
if (!$tag_data || !in_array($val2['id'], $tag_data)) {//未加标签,新增
|
|
$add_tag[] = ['c_id' => $id, 't_id' => $val2['id'], 'c_time' => time()];
|
|
}
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {//删除标签
|
|
$this->mdCustomerTagdata->delete(['c_id' => $id, 't_id' => $val2['id']]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($add_tag && count($add_tag)) {
|
|
$this->mdCustomerTagdata->add_batch($add_tag);
|
|
}
|
|
$log_msg = $info['editType'] == 3 ? '修改用户画像' : '修改战败标签';
|
|
$this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log_msg));
|
|
}
|
|
return $this->show_json($code, $msg);
|
|
}
|
|
|
|
public function del()
|
|
{
|
|
$id = $this->input->post('id');
|
|
$row = $this->customers_model->get(['id' => $id, 'cf_title' => '平台分配']);
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
|
|
}
|
|
$res = $this->customers_model->update(['status' => -1], ['id' => $id]);
|
|
if ($res) {
|
|
return $this->show_json(SYS_CODE_SUCCESS, '删除成功');
|
|
} else {
|
|
return $this->show_json(SYS_CODE_FAIL, '删除失败');
|
|
}
|
|
}
|
|
|
|
public function batch()
|
|
{
|
|
// TODO: Implement batch() method.
|
|
}
|
|
|
|
public function export()
|
|
{
|
|
$params = $this->input->get();
|
|
$where = $this->get_where($params);
|
|
#$where["cs_biz_id >= 0"] = null;
|
|
$page = 1;
|
|
$size = 10000;
|
|
//$params['export_tag'] && $size = 500;
|
|
|
|
$indexs = [
|
|
'id' => 'ID',
|
|
'name' => '客户姓名',
|
|
'mobile' => '手机',
|
|
'level' => '客户等级',
|
|
'status_name' => '客户状态',
|
|
'city_name' => '所在城市',
|
|
'county_name' => '所在地区',
|
|
'to_send' => '是否改派',
|
|
'c_time' => '建档时间',
|
|
"p_time" => "派单时间",
|
|
"dt_time" => "到店时间",
|
|
"order_time" => "下单时间",
|
|
"cont_time" => "最后联系时间",
|
|
"of_title_1" => "来源1",
|
|
"of_title_2" => "来源2",
|
|
"biz_name" => "归属门店",
|
|
"admin_name" => "归属顾问",
|
|
"wxgr_name" => "加个微",
|
|
'brand_detail' => '关注品牌',
|
|
'series_detail' => '关注车型'
|
|
];
|
|
$count = $this->customers_model->count($where);
|
|
$data = [];
|
|
|
|
$offlineSources = $this->customers_model->offlineSources();
|
|
$status_arr = $this->customers_model->get_status();
|
|
unset($status_arr['-1']);
|
|
if ($count) {
|
|
$fileds = "id, name, mobile, level, status, cs_biz_id,brand_id,series_id, FROM_UNIXTIME(c_time) as c_time, if(dt_time>0, dt_time,'') as dt_time, p_time, if(order_time>0, order_time,'') as order_time, if(cont_time>0, cont_time,'') as cont_time, c_brand, cf_id, of_id, of2_id, (SELECT biz_name FROM `lc_biz` where id = `lc_receiver_customers`.biz_id) as biz_name, (SELECT uname FROM `lc_app_licheb_users` where id = `lc_receiver_customers`.admin_id) as admin_name, biz_id, admin_id, wxqy, wxgr, (select city_name from lc_area where city_id = lc_receiver_customers.city_id limit 1) as city_name, (select county_name from lc_area where county_id = lc_receiver_customers.county_id limit 1) as county_name";
|
|
$rows = $this->customers_model->select($where, 'id desc', $page, $size, $fileds);
|
|
$brands = $this->auto_brand_model->get_map_by_ids(array_column($rows, 'brand_id'));
|
|
$series = $this->auto_series_model->get_map_by_ids(array_column($rows, 'series_id'));
|
|
foreach ($rows as $key => $val) {
|
|
$brand_detail = $series_detail = $of_title = '';
|
|
$of_title_1 = $of_title_2 = '';
|
|
if ($val['of_id']) {
|
|
$of_ary = $offlineSources[$val['of_id']];
|
|
$of_title = $of_ary['name'];
|
|
$of_ary['name'] && $of_title_1 = $of_ary['name'];
|
|
$val['of2_id'] && $of_title .= '-' . $of_ary['list'][$val['of2_id']];
|
|
$val['of2_id'] && $of_ary['list'][$val['of2_id']] && $of_title_2 = $of_ary['list'][$val['of2_id']];
|
|
}
|
|
if ($brands[$val['brand_id']]) {
|
|
$brand_detail = $brands[$val['brand_id']][0]['name'];
|
|
$series_detail = $series[$val['series_id']][0]['name'];
|
|
}
|
|
|
|
$id = $val['id'];
|
|
$row = array(
|
|
'id' => $id,
|
|
'name' => $val['name'],
|
|
'mobile' => $this->get_mobile(['of_id' => $val['of_id'], 'mobile' => $val['mobile']]),
|
|
'level' => $val['level'],
|
|
'status_name' => $status_arr[$val['status']],
|
|
'city_name' => $val['city_name'],
|
|
'county_name' => $val['county_name'],
|
|
'to_send' => $this->customers_model->csbizidAry($val['cs_biz_id'] ? $val['cs_biz_id'] : 0),
|
|
'c_time' => $val['c_time'],
|
|
'dt_time' => $val['dt_time'],
|
|
'p_time' => $val['p_time'],
|
|
'order_time' => $val['order_time'],
|
|
'cont_time' => $val['cont_time'],
|
|
'of_title_1' => $of_title_1,
|
|
'of_title_2' => $of_title_2,
|
|
'biz_name' => $val['biz_name'],
|
|
'admin_name' => $val['admin_name'],
|
|
'wxgr_name' => $this->customers_model->wxgrAry($val['wxgr']),
|
|
'brand_detail' => $brand_detail,
|
|
'series_detail' => $series_detail,
|
|
);
|
|
|
|
if ($params['export_tag']) {
|
|
$tag = $this->get_tag($id);
|
|
foreach ($tag as $key => $val) {
|
|
$tag_key = 'tag__' . $val['id'];
|
|
$row[$tag_key] = $val['value_str'];
|
|
if (!in_array($tag_key, array_keys($indexs))) {
|
|
$indexs[$tag_key] = $val['name'];
|
|
}
|
|
}
|
|
|
|
$tag_intention = $this->get_tag($id, 2);
|
|
foreach ($tag_intention as $key => $val) {
|
|
$tag_key = 'tag__' . $val['id'];
|
|
$row[$tag_key] = $val['value_str'];
|
|
if (!in_array($tag_key, array_keys($indexs))) {
|
|
$indexs[$tag_key] = '意向-' . $val['name'];
|
|
}
|
|
}
|
|
|
|
$tag_defeat = $this->get_tag($id, 1);
|
|
foreach ($tag_defeat as $key => $val) {
|
|
$tag_key = 'tag__' . $val['id'];
|
|
$row[$tag_key] = $val['value_str'];
|
|
if (!in_array($tag_key, array_keys($indexs))) {
|
|
$indexs[$tag_key] = '战败-' . $val['name'];
|
|
}
|
|
}
|
|
}
|
|
|
|
$data[] = $row;
|
|
}
|
|
}
|
|
|
|
$fileName = '客户列表';
|
|
array_unshift($data, $indexs);
|
|
$this->load->library('excel');
|
|
$this->excel->out_csv($data, $indexs, $fileName . "_" . date('YmdHis'));
|
|
}
|
|
|
|
public function export_statdata()
|
|
{
|
|
$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_statdata($id, $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 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()
|
|
{
|
|
$id = $this->input->get_post('id');
|
|
$biz_id = $this->input->post('biz_id');
|
|
$row = $this->customers_model->get(['id' => $id, 'cf_title' => '平台分配']);
|
|
if (!$row) {
|
|
return $this->show_json(SYS_CODE_FAIL, '客户不存在!');
|
|
}
|
|
if ($this->input->post()) {
|
|
if (!$biz_id) return $this->show_json(SYS_CODE_FAIL, '请选择门店');
|
|
if ($biz_id == $row['biz_id']) return $this->show_json(SYS_CODE_FAIL, '请选择不同门店');
|
|
$res = $this->customers_model->update(['biz_id' => $biz_id, 'admin_id' => 0], ['id' => $id]);
|
|
if ($res) {
|
|
$log = "改派订单";
|
|
$this->addLog(['customer_id' => $row['id'], 'log' => $log, 'type' => 0]);
|
|
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
|
|
} else {
|
|
return $this->show_json(SYS_CODE_FAIL, '保存失败');
|
|
}
|
|
}
|
|
$this->data['id'] = $id;
|
|
return $this->show_view('receiver/customer/get_adviser');
|
|
}
|
|
|
|
/**
|
|
* Notes:增加日志
|
|
* Created on: 2021/7/23 10:48
|
|
* Created by: dengbw
|
|
* @param array $ary
|
|
* @return mixed
|
|
*/
|
|
private function addLog($ary = array())
|
|
{
|
|
$id = 0;
|
|
if ($ary['log']) {
|
|
$addData = array(
|
|
'customer_id' => $ary['customer_id'],
|
|
'uid' => $this->uid,
|
|
'uname' => $this->username,
|
|
'type' => intval($ary['type']),
|
|
'log' => $ary['log'],
|
|
'cf_platform' => 'admin',
|
|
'c_time' => time()
|
|
);
|
|
$id = $this->customer_oplogs_model->add($addData);
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
private function tagWhere($where, $tags)
|
|
{
|
|
$pidAry = [];
|
|
$res_tag = $this->mdCustomerTag->select(["id in ({$tags})" => null], 'id desc', 0, 0, 'pid,id');
|
|
foreach ($res_tag as $v) {
|
|
$v['pid'] && $pidAry[$v['pid']][] = $v['id'];
|
|
}
|
|
$str_c_ids = $res_tag_data = '';
|
|
foreach ($pidAry as $v) {
|
|
if ($v) {
|
|
$where_tag = [];
|
|
$str_ids = implode(',', $v);
|
|
$where_tag["t_id in({$str_ids})"] = null;
|
|
if ($str_c_ids) {
|
|
$where_tag["c_id in({$str_c_ids})"] = null;
|
|
}
|
|
$res_tag_data = $this->mdCustomerTagdata->select_groupby('c_id', $where_tag, "id desc", 0, 0, "c_id");
|
|
if (!$res_tag_data) {
|
|
break;
|
|
}
|
|
if ($res_tag_data) {
|
|
$str_c_ids = implode(',', array_column($res_tag_data, 'c_id'));
|
|
}
|
|
}
|
|
}
|
|
if ($res_tag_data) {
|
|
$str_cids = implode(',', array_column($res_tag_data, 'c_id'));
|
|
$where["id in({$str_cids})"] = null;
|
|
} else {
|
|
$where["id"] = -1;
|
|
}
|
|
return $where;
|
|
}
|
|
|
|
private function get_tag($id, $tag_type = 0, $tag_data = '', $check_show = 0)
|
|
{
|
|
$show = $res_td = [];
|
|
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1, 'tag_type' => $tag_type], 'sort desc,id desc', 0, 0, 'id,name,type');
|
|
if ($res) {
|
|
if ($id) {
|
|
$res_td = $this->mdCustomerTagdata->select(['c_id' => $id], 'id desc', 0, 0, 't_id');//查找用户选择
|
|
$res_td && $tag_data = array_unique(array_column($res_td, 't_id'));
|
|
}
|
|
foreach ($res as $key => $val) {
|
|
$list = $value_arr = [];
|
|
$value = '';
|
|
$res2 = $this->mdCustomerTag->select(['status' => 1, 'pid' => $val['id']], 'sort desc,id desc', 0, 0, 'id,name');
|
|
foreach ($res2 as $key2 => $val2) {
|
|
//检查是否选中标签
|
|
$setValue = ['id' => $val2['id'], 'name' => $val2['name']];
|
|
if ($val['type'] == 'checkbox') {
|
|
$setValue['checked'] = $tag_data && in_array($val2['id'], $tag_data) ? true : false;
|
|
if ($setValue['checked']) {
|
|
$value_arr[] = $val2['name'];
|
|
$check_show && $check_show = 0;
|
|
}
|
|
} else {
|
|
if ($tag_data && in_array($val2['id'], $tag_data)) {
|
|
$value = $val2['id'];
|
|
$value_arr[] = $val2['name'];
|
|
$check_show && $check_show = 0;
|
|
}
|
|
}
|
|
$list[] = $setValue;
|
|
}
|
|
$value_str = $value_arr ? implode(', ', $value_arr) : '';
|
|
$show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'value' => $value, 'value_str' => $value_str, 'list' => $list];
|
|
}
|
|
}
|
|
$check_show && $show = '';
|
|
return $show;
|
|
}
|
|
|
|
private function get_mobile($params)
|
|
{
|
|
$mobile = $params['mobile'];
|
|
if (!$mobile) {
|
|
return '';
|
|
} elseif (in_array($params['of_id'], [1, 2]) && $this->role != 1) {
|
|
return mobile_asterisk($mobile);
|
|
} else {
|
|
return $mobile;
|
|
}
|
|
}
|
|
}
|