chore(addon/aikefu): 获取简单的配置信息,包括:enabled,status
This commit is contained in:
@@ -8,6 +8,9 @@ return [
|
||||
],
|
||||
|
||||
'listen' => [
|
||||
'KefuGetConfig' => [
|
||||
'addon\aikefu\event\KefuGetConfig'
|
||||
],
|
||||
'KefuChat' => [
|
||||
'addon\aikefu\event\KefuChat'
|
||||
],
|
||||
|
||||
53
src/addon/aikefu/event/KefuGetConfig.php
Normal file
53
src/addon/aikefu/event/KefuGetConfig.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user