From d8ee773cfe7077bdc87740922fef50198076c27b Mon Sep 17 00:00:00 2001 From: dengbw Date: Sun, 3 Apr 2022 15:34:09 +0800 Subject: [PATCH] inventory_403 --- admin/controllers/receiver/Tag.php | 41 ++++++++++++++++--- common/libraries/Wx_qyapi.php | 20 ++++++--- common/models/items/Items_inventory_model.php | 13 +++--- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/admin/controllers/receiver/Tag.php b/admin/controllers/receiver/Tag.php index f316295c..38a7bd07 100644 --- a/admin/controllers/receiver/Tag.php +++ b/admin/controllers/receiver/Tag.php @@ -105,7 +105,10 @@ class Tag extends HD_Controller if ($re) { return $this->show_json(SYS_CODE_FAIL, '标签名称已存在了!'); } - $this->mdCustomerTag->add(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]); + $id = $this->mdCustomerTag->add(['name' => $params['name'], 'sort' => $params['sort'], 'type' => $params['type']]); + if (!$id) { + return $this->show_json(SYS_CODE_FAIL, '保存失败'); + } return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } @@ -131,22 +134,48 @@ class Tag extends HD_Controller //修改标签选项 function edit_options() { - $id = $this->input->post('id'); + $pid = $this->input->post('id'); $options = $this->input->post('options'); - if (!$id || !$options) { - return $this->show_json(SYS_CODE_FAIL, '参数错误'); + if (!$pid || !$options) { + return $this->show_json(SYS_CODE_FAIL, '参数错误!'); } + $re = $this->mdCustomerTag->get(['id' => $pid]); + if (!$re) { + return $this->show_json(SYS_CODE_FAIL, '客户标签不存在!'); + } + $add_tag = $remove_tag = []; foreach ($options as $key => $value) { - $data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => intval($value['sort'])]; + $sort = intval($value['sort']); + $data = ['name' => $value['name'], 'status' => $value['status'], 'sort' => $sort]; + if ($value['status'] == -1) {//删除标签 + $remove_tag = []; + } if ($value['name']) { if ($value['id']) {//修改 $this->mdCustomerTag->update($data, ['id' => $value['id']]); } else {//新增 - $data['pid'] = $id; + $add_tag[] = ['name' => $value['name'], 'order' => $sort]; + $data['pid'] = $pid; $this->mdCustomerTag->add($data); } } } +// $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']) {//已加标签组 +// +// } return $this->show_json(SYS_CODE_SUCCESS, '保存成功'); } diff --git a/common/libraries/Wx_qyapi.php b/common/libraries/Wx_qyapi.php index ef28fee3..19fdb3e0 100644 --- a/common/libraries/Wx_qyapi.php +++ b/common/libraries/Wx_qyapi.php @@ -126,7 +126,7 @@ class Wx_qyapi if (!$access_token) return ['code' => 0, 'msg' => '获取access_token失败']; $res = array(); if ($param['url'] == 'get_follow_user_list') {//获取配置了客户联系功能的成员列表 - $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list?access_token={$access_token}"; + $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_follow_user_list?access_token={$access_token}";//&debug=1 $res = $this->ci->mycurl->httpGet($url); } else if ($param['url'] == 'user_get') {//读取成员 https://developer.work.weixin.qq.com/document/path/90196 $url = "https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={$access_token}&userid={$param['userid']}"; @@ -144,12 +144,22 @@ class Wx_qyapi } else if ($param['url'] == 'get_corp_tag_list') {//获取企业标签库 https://work.weixin.qq.com/api/doc/90001/90143/92696#获取企业标签库 $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/get_corp_tag_list?access_token={$access_token}"; $res = $this->ci->mycurl->httpPost($url, array('group_id' => $param['group_id']), 'is_json'); - } else if ($param['url'] == 'add_corp_tag') {//添加企业客户标签 https://developer.work.weixin.qq.com/document/path/92117# + } else if ($param['url'] == 'add_corp_tag') {//添加企业客户标签 https://developer.work.weixin.qq.com/document/path/92117 $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_corp_tag?access_token={$access_token}"; - $res = $this->ci->mycurl->httpPost($url, array('group_id' => $param['group_id'], 'group_name' => $param['group_name'], 'order' => $param['order'], - 'tag' => $param['tag']), 'is_json'); + $params = ['group_id' => $param['group_id'], 'group_name' => $param['group_name'], 'order' => $param['order']]; + $param['tag'] && $params['tag'] = $param['tag']; + $res = $this->ci->mycurl->httpPost($url, $params, 'is_json'); + } else if ($param['url'] == 'edit_corp_tag') {//编辑企业客户标签 https://developer.work.weixin.qq.com/document/path/92117 + $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/edit_corp_tag?access_token={$access_token}"; + $res = $this->ci->mycurl->httpPost($url, ['id' => $param['id'], 'name' => $param['name'], 'order' => $param['order']], 'is_json'); + } else if ($param['url'] == 'del_corp_tag') {//删除企业客户标签 https://developer.work.weixin.qq.com/document/path/92117 + $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/del_corp_tag?access_token={$access_token}"; + $params = []; + $param['tag_id'] && $params['tag_id'] = $param['tag_id']; + $param['group_id'] && $params['group_id'] = $param['group_id']; + $res = $this->ci->mycurl->httpPost($url, $params, 'is_json'); } else if ($param['url'] == 'mark_tag') {//编辑客户企业标签 https://developer.work.weixin.qq.com/document/path/92118 - $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={$access_token}&debug=1"; + $url = "https://qyapi.weixin.qq.com/cgi-bin/externalcontact/mark_tag?access_token={$access_token}"; $params = ['userid' => $param['userid'], 'external_userid' => $param['external_userid']]; $param['add_tag'] && $params['add_tag'] = $param['add_tag']; $param['remove_tag'] && $params['remove_tag'] = $param['remove_tag']; diff --git a/common/models/items/Items_inventory_model.php b/common/models/items/Items_inventory_model.php index 60335815..179c3388 100644 --- a/common/models/items/Items_inventory_model.php +++ b/common/models/items/Items_inventory_model.php @@ -24,12 +24,13 @@ class Items_inventory_model extends HD_Model */ public function addrManage($uid = 0) { - $ary = [491 => '129', 492 => '130']; - $key = ''; - if ($uid) { - $key = $ary[$uid] ? $ary[$uid] : ''; - } - return $key; + return ''; +// $ary = [491 => '129', 492 => '130']; +// $key = ''; +// if ($uid) { +// $key = $ary[$uid] ? $ary[$uid] : ''; +// } +// return $key; } } \ No newline at end of file