From 670489a89bc5bcedd768cb2ccb4dc6bfb2eb003a Mon Sep 17 00:00:00 2001 From: dengbw Date: Wed, 15 Mar 2023 16:51:52 +0800 Subject: [PATCH] admin_customer_315 --- admin/controllers/receiver/Customer.php | 140 ++++++++++------- admin/views/receiver/customer/get.php | 71 +++++---- admin/views/receiver/customer/lists.php | 196 +++++++++++++++++++++++- 3 files changed, 311 insertions(+), 96 deletions(-) diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index f9eb9398..fe7dfea0 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -11,7 +11,7 @@ class Customer extends HD_Controller { private $searchTpAry = array('mobile' => '客户手机号', 'name' => '客户姓名'); private $searchTimeAry = array('c_time' => '创建时间', 'p_time' => '分配时间', 'cont_time' => '最后联系时间', 'u_time' => '最后操作时间' - , 'dt_time' => '首次到店时间', 'order_time' => '下单时间', 'def_time'=>'战败时间'); + , 'dt_time' => '首次到店时间', 'order_time' => '下单时间', 'def_time' => '战败时间'); protected $log_dir; @@ -92,6 +92,10 @@ class Customer extends HD_Controller } $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'); @@ -113,7 +117,8 @@ class Customer extends HD_Controller return $this->show_view('receiver/customer/lists', true); } - private function get_where(&$params){ + private function get_where(&$params) + { !$params['biz_id'] && $params['biz_id'] = ''; !strlen($params['cs_biz_id']) && $params['cs_biz_id'] = ''; !$params['cf_title'] && $params['cf_title'] = ''; @@ -123,6 +128,8 @@ class Customer extends HD_Controller !$params['of2_id'] && $params['of2_id'] = ''; !$params['biz_type'] && $params['biz_type'] = ''; !$params['tags'] && $params['tags'] = ''; + !$params['tagsIntention'] && $params['tagsIntention'] = ''; + !$params['tagsDefeat'] && $params['tagsDefeat'] = ''; $where = array('status>=0' => null); if ($_SESSION['admin_info']['biz_id']) { $biz_ids = implode(',', $_SESSION['admin_info']['biz_id']); @@ -232,39 +239,15 @@ class Customer extends HD_Controller } } if ($params['tags']) { - $pidAry = []; - $res_tag = $this->mdCustomerTag->select(["id in ({$params['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; - } + $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']){ + 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; @@ -323,15 +306,18 @@ class Customer extends HD_Controller $row['of2_id'] && $of_title .= '-' . $of_ary['list'][$row['of2_id']]; } $tag = $tag_group = []; + $tag_defeat = $tag_intention = ''; $biz_type = intval($row_biz['type']); if ($biz_type == 5) { $jsondata = $row['jsondata'] ? json_decode($row['jsondata'], true) : []; $jsondata['tag_group'] && $tag_group = $jsondata['tag_group']; } else { $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); } - $invalid_user_tag = []; - $row['status']==3 && $invalid_user_tag = $this->get_tag($row['id'],1); /*$to_send = ''; if ($row['cs_biz_id'] == -1) { $to_send = '已改派'; @@ -347,13 +333,14 @@ class Customer extends HD_Controller 'of_title' => $of_title, 'wxqy_name' => $this->customers_model->wxqyAry($row['wxqy']), 'wxgr_name' => $this->customers_model->wxgrAry($row['wxgr']), - 'wx_name' => '企微:'.$this->customers_model->wxqyAry($row['wxqy']).'; 个微:'.$this->customers_model->wxgrAry($row['wxgr']), + 'wx_name' => '企微:' . $this->customers_model->wxqyAry($row['wxqy']) . '; 个微:' . $this->customers_model->wxgrAry($row['wxgr']), 'cf_user' => $cf_user, 'to_send' => $to_send, 'c_time' => date('Y-m-d H:i:s', $row['c_time']), 'status' => $row['status'], 'tag' => $tag, - 'invalid_user_tag' => $invalid_user_tag, + 'tag_defeat' => $tag_defeat, + 'tag_intention' => $tag_intention, 'tag_group' => $tag_group, 'biz_type' => $biz_type, ); @@ -518,14 +505,14 @@ class Customer extends HD_Controller } else if ($info['editType'] == 3 || $info['editType'] == 4) { $id = $info['id']; //客户标签 - if (!$info['tag'] && $info['editType']==3) { + 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']; + $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') { @@ -554,7 +541,7 @@ class Customer extends HD_Controller if ($add_tag && count($add_tag)) { $this->mdCustomerTagdata->add_batch($add_tag); } - $log_msg = $info['editType']==3 ? '修改用户画像' : '修改战败标签'; + $log_msg = $info['editType'] == 3 ? '修改用户画像' : '修改战败标签'; $this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log_msg)); } return $this->show_json($code, $msg); @@ -582,7 +569,7 @@ class Customer extends HD_Controller public function export() { - if ($this->uid != 1){ + if ($this->uid != 1) { return $this->show_json(SYS_CODE_FAIL, '无权限导出'); } @@ -652,20 +639,29 @@ class Customer extends HD_Controller ); $tag = $this->get_tag($id); - foreach ($tag as $key => $val){ - $tag_key = 'tag__'.$val['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))){ + 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']; + $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']; + 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']; } } @@ -729,7 +725,41 @@ class Customer extends HD_Controller return $id; } - private function get_tag($id, $tag_type = 0, $tag_data = '') + 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'); @@ -739,20 +769,23 @@ class Customer extends HD_Controller $res_td && $tag_data = array_unique(array_column($res_td, 't_id')); } foreach ($res as $key => $val) { - $list = []; + $list = $value_arr = []; $value = ''; - $value_arr = array(); $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; - $setValue['checked'] && $value_arr[] = $val2['name']; + 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; @@ -761,6 +794,7 @@ class Customer extends HD_Controller $show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'value' => $value, 'value_str' => $value_str, 'list' => $list]; } } + $check_show && $show = ''; return $show; } diff --git a/admin/views/receiver/customer/get.php b/admin/views/receiver/customer/get.php index 6cfa7033..155175ed 100644 --- a/admin/views/receiver/customer/get.php +++ b/admin/views/receiver/customer/get.php @@ -36,7 +36,7 @@
- 用户信息 + 客户信息 @@ -124,7 +124,7 @@
- 用户画像 + 客户画像 @@ -187,57 +187,56 @@
-
+
- 战败标签 - - - + 客户意向
- + + + + +