Files
shop-platform/src/addon/aikefu/model/Config.php

68 lines
1.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* 智能客服配置模型
* 用于存储和管理智能客服的配置信息
* 版本1.0.0
*/
namespace addon\aikefu\model;
use app\model\system\Config as ConfigModel;
use app\model\BaseModel;
/**
* 智能客服配置
*/
class Config extends BaseModel
{
/**
* 设置智能客服配置
* @param array $data
* @param int $site_id
* @param string $app_module
* @return array
*/
public function setConfig($data, $site_id = 0, $app_module = 'shop')
{
$config = new ConfigModel();
// 获取原始配置
$original_config = $this->getConfig($site_id, $app_module)['data']['value'] ?? [];
// 如果 API Key 为空或保持不变,则使用原始值
if (isset($data['api_key']) && empty($data['api_key'])) {
$data['api_key'] = $original_config['api_key'] ?? '';
}
$res = $config->setConfig($data, '智能客服配置', 1, [['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'AIKEFU_CONFIG']]);
return $res;
}
/**
* 获取智能客服配置
* @param int $site_id
* @param string $app_module
* @return array
*/
public function getConfig($site_id = 0, $app_module = 'shop')
{
$config = new ConfigModel();
$res = $config->getConfig([['site_id', '=', $site_id], ['app_module', '=', $app_module], ['config_key', '=', 'AIKEFU_CONFIG']]);
return $res;
}
/**
* 获取智能客服配置信息
* @param array $condition
* @param string $field
* @return array
*/
public function getConfigInfo($condition = [], $field = '*')
{
// 兼容旧的调用方式
$site_id = $condition[0][1] ?? 0;
$res = $this->getConfig($site_id);
return $res;
}
}