This commit is contained in:
2025-03-25 19:43:26 +08:00
parent 517709254a
commit 3e7295fec4
12 changed files with 191 additions and 59 deletions

View File

@@ -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客服配置
* authorwh
* @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('设置成功'));
}
}

View File

@@ -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'];

View File

@@ -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'] ?? '无';

View File

@@ -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)]);
}
}

View File

@@ -1,5 +1,12 @@
<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('AI客服')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-aicustomerservice_ids" data-source="firm/getAiService"
class="form-control selectpage" name="row[aicustomerservice_ids]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8">
@@ -18,18 +25,14 @@
<input id="c-phone" class="form-control" name="row[phone]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('AI客服')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-aicustomerservice_ids" data-source="firm/getAiService"
class="form-control selectpage" name="row[aicustomerservice_ids]" type="text" value="">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Rel_wx')}:</label>
<div class="col-xs-12 col-sm-6">
<input id="c-rel_wx" data-source="Gewechatfriends/getFriendList" data-wx_id=""
class="form-control selectpage" name="row[rel_wx]" type="text" value="">
<!-- <input data-source=''-->
<!-- name="row[rel_wx]" type="text" value="">-->
<select name="row[rel_wx]" id="c-rel_wx" class="form-control " data-wx_id="">
<option value="">请选择</option>
</select>
</div>
<div class="col-xs-12 col-sm-2">
<input class="form-control firmcustomer-sync-info" type="button" value="同步信息">
@@ -38,8 +41,11 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Rel_group')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-rel_group" data-source="Gechatroom/getChatroomList"
class="form-control selectpage" name="row[rel_group]" type="text" value="">
<!-- <input id="c-rel_group" data-source="Gechatroom/getChatroomList"-->
<!-- class="form-control selectpage" name="row[rel_group]" type="text" value="">-->
<select name="row[rel_group]" id="c-rel_group" class="form-control " >
<option value="">请选择</option>
</select>
</div>
</div>
<div class="form-group">
@@ -83,7 +89,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">责任人:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-firmemployee_id" data-rule="required" data-source="auth/admin/index"
<input id="c-firmemployee_id" data-rule="required" data-source="auth/admin/getAdminList"
data-field="nickname"
class="form-control selectpage" name="row[admin_id]" type="text" value="">
</div>
@@ -92,7 +98,7 @@
<label class="control-label col-xs-12 col-sm-2">{:__('Responsible_pm')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-responsible_pm" data-rule="required"
data-source="auth/admin/index" class="form-control selectpage"
data-source="auth/admin/getAdminList" class="form-control selectpage"
data-field="nickname"
name="row[responsible_pm]" type="text" value="">
</div>

View File

@@ -1,5 +1,12 @@
<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('AI客服')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-aicustomerservice_ids" data-source="firm/getAiService"
class="form-control selectpage" name="row[aicustomerservice_ids]" type="text" value="{$row.aicustomerservice_ids|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Customer_name')}:</label>
<div class="col-xs-12 col-sm-8">
@@ -18,13 +25,6 @@
<input id="c-phone" class="form-control" name="row[phone]" type="text" value="{$row.phone|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('AI客服')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-aicustomerservice_ids" data-source="firm/getAiService"
class="form-control selectpage" name="row[aicustomerservice_ids]" type="text" value="{$row.aicustomerservice_ids|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Rel_wx')}:</label>
<div class="col-xs-12 col-sm-8">
@@ -74,7 +74,7 @@
<label class="control-label col-xs-12 col-sm-2">责任人:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-firmemployee_id" data-rule="required"
data-source="auth/admin/index" class="form-control selectpage"
data-source="auth/admin/getAdminList" class="form-control selectpage"
data-field="nickname"
name="row[admin_id]" type="text" value="{$row.admin_id|htmlentities}">
</div>
@@ -82,7 +82,7 @@
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Responsible_pm')}:</label>
<div class="col-xs-12 col-sm-8">
<input id="c-responsible_pm" data-rule="required" data-source="auth/admin/index"
<input id="c-responsible_pm" data-rule="required" data-source="auth/admin/getAdminList"
data-field="nickname"
class="form-control selectpage" name="row[responsible_pm]" type="text"
value="{$row.responsible_pm|htmlentities}">
@@ -94,12 +94,12 @@
<input id="c-firmcustomerorigin_id" min="0" data-rule="required" data-source="firmcustomerorigin/index" class="form-control selectpage" name="row[firmcustomerorigin_id]" type="text" value="{$row.firmcustomerorigin_id|htmlentities}">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Return_visit_content')}:</label>
<div class="col-xs-12 col-sm-8">
<textarea id="c-return_visit_content" data-rule="required" class="form-control editor" rows="5" name="row[return_visit_content]" cols="50">{$row.return_visit_content|htmlentities}</textarea>
</div>
</div>
<!-- <div class="form-group">-->
<!-- <label class="control-label col-xs-12 col-sm-2">{:__('Return_visit_content')}:</label>-->
<!-- <div class="col-xs-12 col-sm-8">-->
<!-- <textarea id="c-return_visit_content" data-rule="required" class="form-control editor" rows="5" name="row[return_visit_content]" cols="50">{$row.return_visit_content|htmlentities}</textarea>-->
<!-- </div>-->
<!-- </div>-->
<div class="form-group">
<label class="control-label col-xs-12 col-sm-2">{:__('Status')}:</label>
<div class="col-xs-12 col-sm-8">

View File

@@ -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;

View File

@@ -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'],[

View File

@@ -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;
}

View File

@@ -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, []);

View File

@@ -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'=>[

View File

@@ -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.length;i++){
let option = '<option value="'+list[i].id+'">'+list[i].name+'</option>';
$('#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.length;i++){
let option = '<option value="'+list[i].id+'">'+list[i].name+'</option>';
$('#c-rel_wx').append(option);
}
},'json');
});
// $(document).on("click", ".tag_add_url", function(data){