From 3e7295fec4bccf7b6b424b681f4420cce11818a1 Mon Sep 17 00:00:00 2001 From: wh <382379437@qq.com> Date: Tue, 25 Mar 2025 19:43:26 +0800 Subject: [PATCH] fixed --- .../admin/controller/Firmcustomer.php | 22 +++++++ .../admin/controller/Gechatroom.php | 13 +++- .../admin/controller/Gewechatfriends.php | 30 +++++++++- .../admin/controller/auth/Admin.php | 10 ++++ .../admin/view/firmcustomer/add.html | 32 ++++++---- .../admin/view/firmcustomer/edit.html | 30 +++++----- admin/application/api/logic/BaseLogic.php | 25 +++++++- .../application/api/logic/GechatroomLogic.php | 13 ++-- .../api/logic/GewechatFriendsLogic.php | 4 +- admin/application/api/logic/TokenLogic.php | 5 +- admin/application/config.php | 6 +- .../public/assets/js/backend/firmcustomer.js | 60 ++++++++++++++----- 12 files changed, 191 insertions(+), 59 deletions(-) diff --git a/admin/application/admin/controller/Firmcustomer.php b/admin/application/admin/controller/Firmcustomer.php index 1cfcd49..18ad263 100644 --- a/admin/application/admin/controller/Firmcustomer.php +++ b/admin/application/admin/controller/Firmcustomer.php @@ -8,6 +8,7 @@ use think\Exception; use think\exception\PDOException; use think\exception\ValidateException; use think\Request; +use wanghua\general_utility_tools_php\tool\Tools; /** * 企业客户信息 @@ -172,4 +173,25 @@ class Firmcustomer extends Backend $this->success(); } + /** + * desc:缓存ai客服配置 + * author:wh + * @return \think\response\Json + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + function setAiCustomerConfigCache(){ + $ai_config_id = input('ai_config_id'); + if(empty($ai_config_id)){ + return json(Tools::set_fail('ai_config_id不能为空')); + } + //查询ai客服配置 + $ai_config = Db::table('fa_aicustomerservice')->where('id',$ai_config_id)->find(); + if(empty($ai_config)){ + return json(Tools::set_fail('该配置不存在')); + } + //cache('cache_ai_customer_config_'.session_admin_firm_id(),$ai_config,86400); + return json(Tools::set_ok('设置成功')); + } } diff --git a/admin/application/admin/controller/Gechatroom.php b/admin/application/admin/controller/Gechatroom.php index 95226d0..91970c2 100644 --- a/admin/application/admin/controller/Gechatroom.php +++ b/admin/application/admin/controller/Gechatroom.php @@ -33,7 +33,12 @@ class Gechatroom extends Controller //自带id,name return json(['list' => $data, 'total' => count($data)]); } - $data = (new GechatroomLogic())->getChatroomList(); + $ai_config_id = input('ai_config_id'); + if(empty($ai_config_id)){ + throw new \Exception('ai_config_id不能为空'); + } + $logic = new GechatroomLogic(); + $data = $logic->getChatroomList($ai_config_id); //dump($data);die; //缓存群成员列表 cache('cache_getChatroomList_data'.session_admin_firm_id(),$data,86400); @@ -56,7 +61,11 @@ class Gechatroom extends Controller $memberList = $cache_data[$chatroom_id]['memberList']; return json(['list' => $memberList, 'total' => count($memberList)]); } - $data = (new GechatroomLogic())->getChatroomList(); + $ai_config_id = input('ai_config_id'); + if(empty($ai_config_id)){ + throw new \Exception('ai_config_id不能为空'); + } + $data = (new GechatroomLogic())->getChatroomList($ai_config_id); //缓存群成员列表 cache('cache_getChatroomList_data'.session_admin_firm_id(),$data['memberList'],86400); $memberList = $data[$chatroom_id]['memberList']; diff --git a/admin/application/admin/controller/Gewechatfriends.php b/admin/application/admin/controller/Gewechatfriends.php index ddd36ad..005537a 100644 --- a/admin/application/admin/controller/Gewechatfriends.php +++ b/admin/application/admin/controller/Gewechatfriends.php @@ -25,11 +25,39 @@ class Gewechatfriends extends Controller */ function getFriendList() { + //获取AI客服配置 + //$ai_customer_id = input('ai_customer_id'); + if(cache('cache_getFriendDetailList_data'.session_admin_firm_id())){ $data = cache('cache_getFriendDetailList_data'.session_admin_firm_id()); return json(['list' => $data, 'total' => count($data)]); } - $res = (new GewechatFriendsLogic())->getFriendDetailList(); + $obj_logic = new GewechatFriendsLogic(); + $ai_config_id = input('ai_config_id'); + if(empty($ai_config_id)){ + throw new \Exception('请先配置AI客服'); + } + $obj_logic->setBaseUrl($ai_config_id); + $res = $obj_logic->getFriendDetailList(); + $data = $res['data']; + foreach ($data as $k => &$v){ + $v['id'] = $v['userName'] ?? '无'; + $v['name'] = $v['nickName'] ?? '无'; + } + cache('cache_getFriendDetailList_data'.session_admin_firm_id(),$data,86400); + return json(['list' => $data, 'total' => count($data)]); + } + + function getFriendsByAiConfigId() + { + if(cache('cache_getFriendDetailList_data'.session_admin_firm_id())){ + $data = cache('cache_getFriendDetailList_data'.session_admin_firm_id()); + return json(['list' => $data, 'total' => count($data)]); + } + $obj_logic = new GewechatFriendsLogic(); + $ai_config_id = input('ai_config_id'); + $obj_logic->setBaseUrl($ai_config_id); + $res = $obj_logic->getFriendDetailList(); $data = $res['data']; foreach ($data as $k => &$v){ $v['id'] = $v['userName'] ?? '无'; diff --git a/admin/application/admin/controller/auth/Admin.php b/admin/application/admin/controller/auth/Admin.php index 54a1c42..fd63ea7 100644 --- a/admin/application/admin/controller/auth/Admin.php +++ b/admin/application/admin/controller/auth/Admin.php @@ -302,4 +302,14 @@ class Admin extends Backend return json(['data'=>$friends,'total'=>count($friends)]); } + //查询责任人 + function getAdminList(){ + $adminList = Db::table('fa_admin') + ->where('firm_id',session_admin_firm_id()) + ->where('role','firm') + ->select(); + return json(['list'=>$adminList,'total'=>count($adminList)]); + } + + } diff --git a/admin/application/admin/view/firmcustomer/add.html b/admin/application/admin/view/firmcustomer/add.html index fa380a6..ac90557 100644 --- a/admin/application/admin/view/firmcustomer/add.html +++ b/admin/application/admin/view/firmcustomer/add.html @@ -1,5 +1,12 @@
+
+ +
+ +
+
@@ -18,18 +25,14 @@
-
- -
- -
-
- + + +
@@ -38,8 +41,11 @@
- + + +
@@ -83,7 +89,7 @@
-
@@ -92,7 +98,7 @@
diff --git a/admin/application/admin/view/firmcustomer/edit.html b/admin/application/admin/view/firmcustomer/edit.html index 7ae56c1..fbf659e 100644 --- a/admin/application/admin/view/firmcustomer/edit.html +++ b/admin/application/admin/view/firmcustomer/edit.html @@ -1,5 +1,12 @@ +
+ +
+ +
+
@@ -18,13 +25,6 @@
-
- -
- -
-
@@ -74,7 +74,7 @@
@@ -82,7 +82,7 @@
- @@ -94,12 +94,12 @@
-
- -
- -
-
+ + + + + +
diff --git a/admin/application/api/logic/BaseLogic.php b/admin/application/api/logic/BaseLogic.php index 821c095..a266634 100644 --- a/admin/application/api/logic/BaseLogic.php +++ b/admin/application/api/logic/BaseLogic.php @@ -9,13 +9,34 @@ namespace app\api\logic; +use think\Db; + class BaseLogic { + public $base_url = ''; - static function curl_post_json(string $url, array $postdata, $header=[]) { + function setBaseUrl($ai_config_id){ + //$ai_config_id = input('ai_config_id'); + $conf = Db::table('fa_aicustomerservice') + ->where('id',$ai_config_id) + ->find(); + if(empty($conf)){ + throw new \Exception('ai客服配置不存在'); + } + if(empty($conf['server_url'])){ + throw new \Exception('ai客服配置的server_url不能为空'); + } + $this->base_url = $conf['server_url']; + return $conf['server_url']; + } + + function curl_post_json($url, array $postdata, $header=[]) { + if(empty($this->base_url)){ + throw new \Exception('请先设置ai客服配置'); + } $tokenArr = (new TokenLogic())->getToken(); $postdata['appId'] = $tokenArr['appId']; - $domain = config('gewechat.base_url'); + $domain = $this->base_url; $timeout = 4; $connect_timeout = 1; $set_time_limit = 5; diff --git a/admin/application/api/logic/GechatroomLogic.php b/admin/application/api/logic/GechatroomLogic.php index 5221281..b35ba57 100644 --- a/admin/application/api/logic/GechatroomLogic.php +++ b/admin/application/api/logic/GechatroomLogic.php @@ -21,18 +21,21 @@ class GechatroomLogic extends BaseLogic * * */ - function getChatroomList() + function getChatroomList($ai_config_id) { //$this->getChatroomMemberList();die; + //$base_url = config('gewechat.base_url'); //去查询群名称 - $wxids_arr = (new GewechatFriendsLogic())->getFriendWxIdsList(); + $logic = new GewechatFriendsLogic(); + $logic->setBaseUrl($ai_config_id); + $wxids_arr = $logic->getFriendWxIdsList(); $chatrooms = $wxids_arr['data']['chatrooms']; $url = '/group/getChatroomInfo'; Tools::log_to_write_txt(['获取群列表[带群名称],包含了群成员列表,入参:$chatrooms'=>$chatrooms]); $arr = []; foreach ($chatrooms as $v){ $post_data = ['chatroomId'=>$v]; - $res = self::curl_post_json($url, $post_data); + $res = $logic->curl_post_json($url, $post_data); //群号=>群信息[含群成员列表] $arr[] = array_merge($res['data'],[ 'id'=>$v, @@ -54,7 +57,7 @@ class GechatroomLogic extends BaseLogic $arr = []; foreach ($chatrooms as $v){ $post_data = ['chatroomId'=>$v]; - $res = self::curl_post_json($url, $post_data); + $res = $this->curl_post_json($url, $post_data); dump($res);die; //群号=>群信息[含群成员列表] $arr[$v] = array_merge($res['data'],[ @@ -80,7 +83,7 @@ class GechatroomLogic extends BaseLogic $arr = []; foreach ($chatrooms as $v){ $post_data = ['chatroomId'=>$v]; - $res = self::curl_post_json($url, $post_data); + $res = $this->curl_post_json($url, $post_data); dump($res);die; //群号=>群信息[含群成员列表] $arr[$v] = array_merge($res['data'],[ diff --git a/admin/application/api/logic/GewechatFriendsLogic.php b/admin/application/api/logic/GewechatFriendsLogic.php index c48f32f..6b26b28 100644 --- a/admin/application/api/logic/GewechatFriendsLogic.php +++ b/admin/application/api/logic/GewechatFriendsLogic.php @@ -56,7 +56,7 @@ class GewechatFriendsLogic extends BaseLogic $url = '/contacts/fetchContactsList'; $post_data = []; Tools::log_to_write_txt(['查询微信好友列表[不带昵称],入参:$post_data'=>$post_data]); - $res = self::curl_post_json($url, $post_data); + $res = $this->curl_post_json($url, $post_data); Tools::log_to_write_txt(['查询微信好友列表[不带昵称],出参:$res'=>$res]); return $res; } @@ -73,7 +73,7 @@ class GewechatFriendsLogic extends BaseLogic $url = '/contacts/getDetailInfo'; $post_data = ['wxids'=>$wxids]; Tools::log_to_write_txt(['查询微信好友列表[带昵称],入参:$post_data'=>$post_data]); - $res = self::curl_post_json($url, $post_data); + $res = $this->curl_post_json($url, $post_data); Tools::log_to_write_txt(['查询微信好友列表[带昵称],出参:$res'=>$res]); return $res; } diff --git a/admin/application/api/logic/TokenLogic.php b/admin/application/api/logic/TokenLogic.php index e73dee6..40ca4cc 100644 --- a/admin/application/api/logic/TokenLogic.php +++ b/admin/application/api/logic/TokenLogic.php @@ -9,6 +9,9 @@ namespace app\api\logic; class TokenLogic extends BaseLogic { + public function __construct() + { + } /** * desc: @@ -22,7 +25,7 @@ class TokenLogic extends BaseLogic * @return string * @throws \Exception */ - static function getToken() + function getToken() { $url = 'https://wechat-api-test.excn.vip/vip_groups/auth_info'; $res = \wanghua\general_utility_tools_php\http\Curl::curl_post($url, []); diff --git a/admin/application/config.php b/admin/application/config.php index ce691ce..d2aefc5 100644 --- a/admin/application/config.php +++ b/admin/application/config.php @@ -337,9 +337,9 @@ return [ //API接口地址 'api_url' => 'https://api.fastadmin.net', ], - 'gewechat'=>[ - 'base_url'=>'https://wechat-api-test.excn.vip/v2/api' - ], + //'gewechat'=>[ + // 'base_url'=>'https://wechat-api-test.excn.vip/v2/api' + //], 'ai_config'=>[ //AI话术/话术示例 'talk_skill'=>[ diff --git a/admin/public/assets/js/backend/firmcustomer.js b/admin/public/assets/js/backend/firmcustomer.js index 9f8e7fd..716c265 100644 --- a/admin/public/assets/js/backend/firmcustomer.js +++ b/admin/public/assets/js/backend/firmcustomer.js @@ -120,11 +120,13 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // $("#money").text(data.extend.money); // $("#price").text(data.extend.price); - // - let load_index = layer.load(1); - $.post('Gewechatfriends/getFriendList',{},function (res) { - layer.close(load_index); - },'json'); + //查询并缓存 + // let load_index = layer.load(1); + // $.post('Gewechatfriends/getFriendList',{},function (res) { + // layer.close(load_index); + // },'json'); + + // $("#c-rel_wx").data("eSelect", function(data){ // //后续操作 // console.log(data); @@ -145,22 +147,35 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // $("#c-category").data("format-item", function(row){ // return row.title + " - " + row.author; // }); - //设置下拉框后的值 + //关联微信下拉改变 $(document).on("change", "#c-rel_wx", function(data){ + // console.log('关联微信下拉改变',$('#c-rel_wx').val()); //变更后的回调事件 - // console.log(data.currentTarget.defaultValue); - $('#c-rel_wx').attr('data-wx_id',data.currentTarget.defaultValue); - }); - $(document).on("change", "#c-firmfollowuptemplate_id", function(data){ - //变更后的回调事件 - console.log(data.currentTarget.defaultValue); - let tmp_id = data.currentTarget.defaultValue; - // $('#c-rel_wx').attr('data-wx_id',data.currentTarget.defaultValue); - $.get('firmfollowuptemplatetimelist/index',{firmfollowuptemplate_id:tmp_id},function (res) { + $('#c-rel_wx').attr('data-wx_id',$('#c-rel_wx').val()); + + + //同时查询关联群 + let ai_config_id = $('#c-aicustomerservice_ids').val(); + $.get('Gechatroom/getChatroomList',{ai_config_id:ai_config_id},function (res) { + //动态添加数据 + let list = res.list; + for(let i=0;i'+list[i].name+''; + $('#c-rel_group').append(option); + } },'json'); }); + // $(document).on("change", "#c-firmfollowuptemplate_id", function(data){ + // //变更后的回调事件 + // // console.log(data.currentTarget.defaultValue); + // let tmp_id = data.currentTarget.defaultValue; + // $.get('firmfollowuptemplatetimelist/index',{firmfollowuptemplate_id:tmp_id},function (res) { + // + // },'json'); + // }); + //点击同步按钮 $('.firmcustomer-sync-info').on('click',function (e){ //读取下拉框的值 let wx_id = $('#c-rel_wx').attr('data-wx_id'); @@ -172,6 +187,21 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin //回显 $('#c-headimage').val(res.data.smallHeadImgUrl); },'json'); + + }); + //选择AI客服时,获取该客服的微信好友列表并渲染在“关联微信”字段下拉框中 + $(document).on("change", "#c-aicustomerservice_ids", function(data){ + //变更后的回调事件 + // console.log('AI客服:',data.currentTarget.defaultValue); + let ai_config_id = data.currentTarget.defaultValue; + $.get('Gewechatfriends/getFriendsByAiConfigId',{ai_config_id:ai_config_id},function (res) { + //动态添加数据 + let list = res.list; + for(let i=0;i'+list[i].name+''; + $('#c-rel_wx').append(option); + } + },'json'); }); // $(document).on("click", ".tag_add_url", function(data){