add-api-tag_type

This commit is contained in:
lccsw
2023-02-08 16:22:03 +08:00
parent 84acb39c09
commit 635eb315fc
+27 -1
View File
@@ -112,6 +112,8 @@ class Customers extends Wxapp
{
$id = intval($this->input_param('id'));
$type = $this->input_param('type');
$tag_type = $this->input_param('tag_type');
!strlen($tag_type) && $tag_type = 0;
$tags = $res_td = $re_cus = [];
$re_biz = $this->get_biz();
$city_id = intval($re_biz['city_id']);
@@ -138,7 +140,7 @@ class Customers extends Wxapp
}
}
} else {
$res = $this->mdCustomerTag->select(['status' => 1, 'pid' => 0, 'show<>' => 1, 'tag_type' => 0], 'sort desc,id desc', 0, 0, 'id,name,type');
$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');
@@ -370,6 +372,7 @@ class Customers extends Wxapp
$content_imgs = $this->input_param('imgs');//小记图片
$follow_channel = $this->input_param('follow_channel');//跟进渠道
$visit_time = $this->input_param('visit_time');//计划回访时间
$invalid_tag = $this->input_param('invalid_tag'); //战败标签
$row = $this->customers_model->get(['id' => $id]);
if (!$row) {
throw new Exception('数据不存在!', ERR_PARAMS_ERROR);
@@ -478,6 +481,29 @@ class Customers extends Wxapp
$result = $this->customers_entity->add_log_visit($id, $uid, $uname, $content, 0, 1, $content_imgs);
}
if ($result) {
//战败标签
if ($invalid_tag) {
$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 ($invalid_tag as $key => $val) {
foreach ($val['list'] as $key2 => $val2) {
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']]);
}
}
}
}
if ($add_tag && count($add_tag)) {
$this->mdCustomerTagdata->add_batch($add_tag);
}
}
throw new Exception('操作成功', API_CODE_SUCCESS);
} else {
throw new Exception('操失败!', ERR_PARAMS_ERROR);