From c617a99ffb94f1f55e3101e88ecd131c4163920f Mon Sep 17 00:00:00 2001 From: dengbw Date: Tue, 15 Mar 2022 17:52:00 +0800 Subject: [PATCH] customer_tag_315_3 --- admin/controllers/receiver/Customer.php | 73 ++++++++++++++++++- admin/controllers/receiver/Tag.php | 17 ++++- admin/views/receiver/customer/get.php | 56 +++++++++++++- admin/views/receiver/tag/edit.php | 11 +++ admin/views/receiver/tag/lists.php | 16 +++- api/controllers/wxapp/licheb/Customers.php | 4 +- .../receiver/Receiver_customer_tag_model.php | 11 +++ .../receiver/Receiver_customers_model.php | 3 +- 8 files changed, 181 insertions(+), 10 deletions(-) diff --git a/admin/controllers/receiver/Customer.php b/admin/controllers/receiver/Customer.php index dfcc48cc..f964fd9c 100644 --- a/admin/controllers/receiver/Customer.php +++ b/admin/controllers/receiver/Customer.php @@ -20,6 +20,8 @@ class Customer extends HD_Controller 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_xz_model'); @@ -291,6 +293,7 @@ class Customer extends HD_Controller $of_title = $of_ary['name']; $row['of2_id'] && $of_title .= '-' . $of_ary['list'][$row['of2_id']]; } + $info = array( 'id' => $row['id'], 'name' => $row['name'], @@ -301,6 +304,7 @@ class Customer extends HD_Controller 'cf_user' => $cf_user, 'c_time' => date('Y-m-d H:i:s', $row['c_time']), 'status' => $row['status'], + 'tag' => $this->get_tag($row['id']), ); //到店信息 @@ -460,8 +464,46 @@ class Customer extends HD_Controller $msg = '修改用户信息成功'; $this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => $log)); } + } else if ($info['editType'] == 3) { + $id = $info['id']; + //客户标签 + if (!$info['tag']) { + 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')) : ''; + foreach ($info['tag'] 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); + } + $this->addLog(array('customer_id' => $info['id'], 'type' => 0, 'log' => '修改用户画像')); } - return $this->show_json($code, $msg); } @@ -540,5 +582,34 @@ class Customer extends HD_Controller return $id; } + private function get_tag($id) + { + $show = $res_td = []; + $res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0], 'sort desc,id desc', 0, 0, 'id,name,type'); + if ($res) { + $id && $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')) : ''; + foreach ($res as $key => $val) { + $list = []; + $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; + } else { + if ($tag_data && in_array($val2['id'], $tag_data)) { + $value = $val2['id']; + } + } + $list[] = $setValue; + } + $show[] = ['id' => $val['id'], 'name' => $val['name'], 'type' => $val['type'], 'value' => $value, 'list' => $list]; + } + } + return $show; + } + } diff --git a/admin/controllers/receiver/Tag.php b/admin/controllers/receiver/Tag.php index 713bcec4..f316295c 100644 --- a/admin/controllers/receiver/Tag.php +++ b/admin/controllers/receiver/Tag.php @@ -24,11 +24,15 @@ class Tag extends HD_Controller $params['page'] = $params['page'] ? intval($params['page']) : 1; $params['size'] = $params['size'] ? intval($params['size']) : 20; $statusAry = $this->mdCustomerTag->statusAry(); + $typeAry = $this->mdCustomerTag->typeAry(); $lists = array(); $where = ["status<>-1" => null, 'pid' => 0]; if (strlen($params['status'])) { $where['status'] = $params['status']; } + if ($params['type']) { + $where['type'] = $params['type']; + } $count = $this->mdCustomerTag->count($where); if ($count) { $res = $this->mdCustomerTag->select($where, "sort desc,id desc", $params['page'], $params['size']); @@ -37,6 +41,7 @@ class Tag extends HD_Controller $setValue['id'] = $value['id']; $setValue['name'] = $value['name']; $setValue['sort'] = $value['sort']; + $setValue['type_name'] = $typeAry[$value['type']]; $setValue['status'] = $value['status']; $setValue['status_name'] = $statusAry[$value['status']]; $options = ''; @@ -48,7 +53,7 @@ class Tag extends HD_Controller } $this->data['lists'] = $lists; $this->data['params'] = $params; - $this->data['showInfo'] = ['statusAry' => $statusAry]; + $this->data['showInfo'] = ['statusAry' => $statusAry, 'typeAry' => $typeAry]; $this->data['_title'] = '客户标签列表'; $this->data['pager'] = array('count' => ceil($count / $params['size']), 'curr' => $params['page'], 'totle' => $count); return $this->show_view('/receiver/tag/lists', true); @@ -77,12 +82,15 @@ class Tag extends HD_Controller } $name = $re['name']; $sort = $re['sort']; + $type = $re['type']; } else { $url = "/receiver/tag/add"; $name = ''; $sort = 0; + $type = 'checkbox'; } - $this->data['showInfo'] = ['id' => $id, 'name' => $name, 'sort' => $sort, 'url' => $url]; + $this->data['showInfo'] = ['id' => $id, 'name' => $name, 'sort' => $sort, 'type' => $type, + 'typeAry' => $this->mdCustomerTag->typeAry(), 'url' => $url]; return $this->show_view('/receiver/tag/edit'); } @@ -97,7 +105,7 @@ class Tag extends HD_Controller if ($re) { return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); } - $this->mdCustomerTag->add(['name' => $params['name'], 'sort' => $params['sort']]); + $this->mdCustomerTag->add(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } @@ -115,7 +123,8 @@ class Tag extends HD_Controller if ($re && $re['id'] != $params['id']) { return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); } - $this->mdCustomerTag->update(['name' => $params['name'], 'sort' => $params['sort']], ['id' => $params['id']]); + $this->mdCustomerTag->update(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']] + , ['id' => $params['id']]); return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } diff --git a/admin/views/receiver/customer/get.php b/admin/views/receiver/customer/get.php index 000516e4..f65772d8 100644 --- a/admin/views/receiver/customer/get.php +++ b/admin/views/receiver/customer/get.php @@ -130,6 +130,61 @@ +
+
+
+ + 用户画像 + + + + +
+
+ + + + + +
+
+ +
+
+
+
+
@@ -231,7 +286,6 @@ methods: { editType: function (index) { var vm = this; - if (vm.edit_index == index) { vm.edit_index = 0; } else { diff --git a/admin/views/receiver/tag/edit.php b/admin/views/receiver/tag/edit.php index e0b3b28a..c73770c5 100644 --- a/admin/views/receiver/tag/edit.php +++ b/admin/views/receiver/tag/edit.php @@ -7,6 +7,17 @@
+
+ +
+ +
+
diff --git a/admin/views/receiver/tag/lists.php b/admin/views/receiver/tag/lists.php index b9374b16..fcb800e5 100644 --- a/admin/views/receiver/tag/lists.php +++ b/admin/views/receiver/tag/lists.php @@ -2,6 +2,18 @@