chore(addon/aikefu): 获取简单的配置信息,包括:enabled,status

This commit is contained in:
2025-12-08 09:13:57 +08:00
parent cfd791f148
commit 7eadf2df56
3 changed files with 57 additions and 1 deletions

View File

@@ -8,6 +8,9 @@ return [
],
'listen' => [
'KefuGetConfig' => [
'addon\aikefu\event\KefuGetConfig'
],
'KefuChat' => [
'addon\aikefu\event\KefuChat'
],

View File

@@ -0,0 +1,53 @@
<?php
namespace addon\aikefu\event;
use addon\aikefu\model\Config as KefuConfigModel;
/**
* 获取智能客服配置信息
*/
class KefuGetConfig
{
/**
* 处理获取配置信息事件
* @param array $data 事件数据
* @return array
*/
public function handle($data)
{
$site_id = $data['site_id'] ?? 0;
$response_data = [
'enabled' => false,
'status' => 'disabled'
];
try {
// 获取智能客服配置
$kefu_config_model = new KefuConfigModel();
$config_info = $kefu_config_model->getConfig($site_id);
$response_data = [
'enabled' => false,
'status' => 'disabled'
];
// 处理配置信息
if (!empty($config_info['data']['value'])) {
$config = $config_info['data']['value'];
// 服务状态
$response_data['enabled'] = $config['status'] == 1;
$response_data['status'] = $config['status'] == 1 ? 'enabled' : 'disabled';
}
return $response_data;
} catch (\Exception $e) {
$response_data['status'] = 'error';
$response_data['error'] = $e->getMessage();
return $response_data;
}
}
}