This commit is contained in:
dengbw
2022-04-06 17:48:27 +08:00
parent 29e7520c89
commit 9d9c9c27d8
3 changed files with 139 additions and 35 deletions
+65 -32
View File
@@ -65,7 +65,7 @@ class Tag extends HD_Controller
if (!$id) {
return $this->show_json(SYS_CODE_FAIL, '参数错误!');
}
$res_tag = $this->mdCustomerTag->select(["status" => 1, 'pid' => $id], "sort desc,id desc", 0, 0, 'id,name,sort,status');
$res_tag = $this->mdCustomerTag->select(["status" => 1, 'pid' => $id], "sort desc,id desc", 0, 0, 'id,name,sort,status,qy_id');
$this->data['lists'] = $res_tag;
return $this->show_json(SYS_CODE_SUCCESS);
}
@@ -122,15 +122,40 @@ class Tag extends HD_Controller
if (!$params['name']) {
return $this->show_json(SYS_CODE_FAIL, '请输入标签名称');
}
$re = $this->mdCustomerTag->get(array('name' => $params['name']));
$re = $this->mdCustomerTag->get(array('name' => $params['name'], 'status' => 1));
if ($re && $re['id'] != $params['id']) {
return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!');
}
$re = $this->mdCustomerTag->get(['id' => $params['id']]);
if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn') && $re['qy_id']) {//正试才能修改企业标签
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$this->wx_qyapi->get_external_contact(['url' => 'edit_corp_tag', 'id' => $re['qy_id']
, 'name' => $params['name'], 'order' => $params['sort']]);
}
$this->mdCustomerTag->update(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]
, ['id' => $params['id']]);
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
//删除单条数据
public function del()
{
$id = $this->input->post('id');
if (!$id) {
$this->show_json(SYS_CODE_FAIL, '参数错误');
}
$re = $this->mdCustomerTag->get(['id' => $id]);
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '标签不存在!');
}
$this->mdCustomerTag->update(['status' => '-1'], ['id' => $id]);
if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn') && $re['qy_id']) {//正试才能修改企业标签
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$this->wx_qyapi->get_external_contact(['url' => 'del_corp_tag', 'group_id' => $re['qy_id']]);
}
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
//修改标签选项
function edit_options()
{
@@ -143,15 +168,18 @@ class Tag extends HD_Controller
if (!$re) {
return $this->show_json(SYS_CODE_FAIL, '客户标签不存在!');
}
$add_tag = $remove_tag = [];
$add_tag = $del_tag = $edit_tag = [];
foreach ($options as $key => $value) {
$sort = intval($value['sort']);
$data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => $sort];
if ($value['status'] == -1) {//删除标签
$remove_tag = [];
if ($value['status'] == -1 && $value['qy_id']) {//删除标签
$del_tag[] = $value['qy_id'];
}
if ($value['name']) {
if ($value['id']) {//修改
if ($value['status'] == 1 && $value['qy_id']) {
$edit_tag[] = ['id' => $value['qy_id'], 'name' => $value['name'], 'order' => $sort];
}
$this->mdCustomerTag->update($data, ['id' => $value['id']]);
} else {//新增
$add_tag[] = ['name' => $value['name'], 'order' => $sort];
@@ -160,22 +188,38 @@ class Tag extends HD_Controller
}
}
}
// $this->load->library('wx_qyapi', ['app' => 'lichene']);
// if (!$re['qy_id'] && $add_tag) {//未加标签组
// $add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => '', 'group_name' => $re['name']
// , 'order' => $re['sort'], 'tag' => $add_tag];
// $re_yq = $this->wx_qyapi->get_external_contact($add_corp_tag);
// if ($re_yq['errcode'] == 0 && $re_yq['tag_group']['group_id']) {//更新企微id
// $this->mdCustomerTag->update(['qy_id' => $re_yq['tag_group']['group_id']], ['id' => $pid]);
// foreach ($re_yq['tag_group']['tag'] as $key3 => $value3) {
// if ($value3['id']) {//更新企微id
// $this->mdCustomerTag->update(['qy_id' => $value3['id']], ['pid' => $pid, 'name' => $value3['name']]);
// }
// }
// }
// } else if ($re['qy_id']) {//已加标签组
//
// }
if (false !== strpos($_SERVER['HTTP_HOST'], 'admin.liche.cn')) {//正试才能修改企业标签
$this->load->library('wx_qyapi', ['app' => 'lichene']);
if (count($add_tag)) {//新增标签
if (!$re['qy_id']) {
$add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => '', 'group_name' => $re['name']
, 'order' => $re['sort'], 'tag' => $add_tag];
} else {
$add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => $re['qy_id'], 'tag' => $add_tag];
}
$re_yq = $this->wx_qyapi->get_external_contact($add_corp_tag);
if ($re_yq['errcode'] == 0) {
if (!$re['qy_id'] && $re_yq['tag_group']['group_id']) {//更新企微标签组id
$this->mdCustomerTag->update(['qy_id' => $re_yq['tag_group']['group_id']], ['id' => $pid]);
}
foreach ($re_yq['tag_group']['tag'] as $key => $value) {
if ($value['id']) {//更新企微标签id
$this->mdCustomerTag->update(['qy_id' => $value['id']], ['pid' => $pid, 'name' => $value['name']]);
}
}
}
} else if (count($edit_tag)) {//编辑标签
foreach ($edit_tag as $key => $value) {
$this->wx_qyapi->get_external_contact(['url' => 'edit_corp_tag', 'id' => $value['id']
, 'name' => $value['name'], 'order' => $value['order']]);
}
} else if (count($del_tag)) {//删除标签
foreach ($del_tag as $key => $value) {
$this->wx_qyapi->get_external_contact(['url' => 'del_corp_tag', 'tag_id' => $value]);
}
}
//$this->data = ['options' => $options, 'add_tag' => $add_tag, 'edit_tag' => $edit_tag, 'del_tag' => $del_tag];
}
return $this->show_json(SYS_CODE_SUCCESS, '保存成功');
}
@@ -190,17 +234,6 @@ class Tag extends HD_Controller
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
//删除单条数据
public function del()
{
$id = $this->input->post('id');
if (!$id) {
$this->show_json(SYS_CODE_FAIL, '参数错误');
}
$this->mdCustomerTag->update(['status' => '-1'], ['id' => $id]);
return $this->show_json(SYS_CODE_SUCCESS, '操作成功');
}
//批量操作(默认修改状态)
public function batch()
{
+1 -1
View File
@@ -200,7 +200,7 @@
},
addOptions: function () {
var that = this;
that.optionsList.push({id: 0, name: '', status: 1, sort: 50});
that.optionsList.push({id: 0, name: '', status: 1, qy_id: '', sort: 50});
},
delOptions: function (index) {
var that = this;
+73 -2
View File
@@ -256,14 +256,85 @@ Class Lichene extends HD_Controller
}
}
/**
* Notes:添加企业客户标签
* Notes:显示客户标签
* Created on: 2022/3/24 15:01
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/wechat/lichene/add_corp_tag
* https://liche-api-dev.xiaoyu.com/wechat/lichene/show_corp_tag
* https://api.liche.cn/wechat/lichene/show_corp_tag
*/
public function show_corp_tag()
{
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
$list = [];
$res = $this->mdCustomerTag->select(["status" => 1, 'pid' => 0], "sort desc,id desc", 0, 0, 'id,name,qy_id,sort');
foreach ($res as $key => $value) {
$res_tag = $this->mdCustomerTag->select(["status" => 1, 'pid' => $value['id']], "sort desc,id desc", 0, 0, 'id,name,qy_id,sort');
$value['options'] = $res_tag;
$list[] = $value;
}
echo json_encode($list, JSON_UNESCAPED_UNICODE);
}
/**
* Notes:添加客户标签
* Created on: 2022/4/06 15:01
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/wechat/lichene/add_corp_tag?pid=49&name=旅游爱好者&order=50
* https://api.liche.cn/wechat/lichene/add_corp_tag
*/
public function add_corp_tag()
{
if (false == strpos($_SERVER['HTTP_HOST'], 'api.liche.cn')) {
echo '正试【api.liche.cn】才能修改企业标签';
exit;
}
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
$this->load->library('wx_qyapi', ['app' => 'lichene']);
$param = $this->input->get();
if (!$param['pid']) {
echo '无pid';
exit;
}
if (!$param['name']) {
echo '无name';
exit;
}
$re = $this->mdCustomerTag->get(['id' => $param['pid']]);
if (!$re) {
echo '客户标签不存在';
exit;
}
$add_tag[] = ['name' => $param['name'], 'order' => intval($param['order'])];
if (!$re['qy_id']) {
$add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => '', 'group_name' => $re['name']
, 'order' => $re['sort'], 'tag' => $add_tag];
} else {
$add_corp_tag = ['url' => 'add_corp_tag', 'group_id' => $re['qy_id'], 'tag' => $add_tag];
}
$re_yq = $this->wx_qyapi->get_external_contact($add_corp_tag);
if ($re_yq['errcode'] == 0) {
if (!$re['qy_id'] && $re_yq['tag_group']['group_id']) {//更新企微标签组id
$this->mdCustomerTag->update(['qy_id' => $re_yq['tag_group']['group_id']], ['id' => $param['pid']]);
}
foreach ($re_yq['tag_group']['tag'] as $key => $value) {
if ($value['id']) {//更新企微标签id
$this->mdCustomerTag->update(['qy_id' => $value['id']], ['pid' => $param['pid'], 'name' => $value['name']]);
}
}
}
echo json_encode($re_yq, JSON_UNESCAPED_UNICODE);
}
/**
* Notes:批量添加企业客户标签
* Created on: 2022/3/24 15:01
* Created by: dengbw
* https://liche-api-dev.xiaoyu.com/wechat/lichene/add_corp_tags
* https://api.liche.cn/wechat/lichene/add_corp_tags
*/
public function add_corp_tags()
{
$this->load->model('receiver/receiver_customer_tag_model', 'mdCustomerTag');
$this->load->library('wx_qyapi', ['app' => 'lichene']);