Files
ulthon_information/app/admin/controller/System.php
augushong 34fe255829 feat(phone-image): 增加翻页预览与无封面图排版样式
- 为手机截图生成器添加翻页功能,支持在生成前预览各页内容
- 增加无封面图时的排版样式,使用装饰线条和居中布局
- 改进图片处理逻辑,清除内联样式并展平嵌套包装元素
- 修复 models.dev 同步接口,支持 GET 请求获取缓存数据
- 优化网络请求,添加直连失败后的本地代理重试机制
2026-05-01 16:31:26 +08:00

199 lines
5.0 KiB
PHP

<?php
namespace app\admin\controller;
use think\Request;
use think\facade\View;
use app\model\SystemConfig;
use think\facade\Cache;
use EasyWeChat\Factory;
use think\facade\Config;
use app\model\WxPublicAccount;
use app\UploadFiles as AppUploadFiles;
class System extends Common
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
return View::fetch();
}
public function others()
{
return View::fetch();
}
public function agreement()
{
return View::fetch();
}
public function theme()
{
return View::fetch();
}
public function easyBlue()
{
return View::fetch();
}
public function blog()
{
return View::fetch();
}
public function update()
{
$upload_files_config = [
'site_logo'
];
$post_data = $this->request->post();
$list = SystemConfig::column('value','name');
foreach ($post_data as $key => $value) {
if(!is_string($value)){
$value = serialize($value);
}
if(\in_array($key,$upload_files_config)){
$old_save_name = get_system_config($key);
AppUploadFiles::use($value);
if($old_save_name != $value){
AppUploadFiles::delete($old_save_name);
}
}
if(isset($list[$key])){
SystemConfig::where('name',$key)->update(['value'=>$value]);
}else{
$model_sysconfig = new SystemConfig();
$model_sysconfig->name = $key;
$model_sysconfig->value = $value;
$model_sysconfig->save();
}
$list[$key] = $value;
}
Cache::set('system_config',$list);
return $this->success();
}
public function clearCache()
{
Cache::clear();
return $this->success('清楚成功');
}
/**
* AI 设置页面.
*/
public function ai()
{
return View::fetch();
}
/**
* 同步 models.dev 数据.
*
* GET: 返回缓存的供应商列表(不触发远程同步)
* POST: 强制从 models.dev 远程同步
*/
public function syncModelsDev()
{
$sync = new \app\common\tools\ai\ModelsDevSync();
if ($this->request->isGet()) {
$result = [
'providers' => $sync->getProviders(),
'models' => [],
];
return json(['code' => 0, 'msg' => 'ok', 'data' => $result]);
}
try {
$result = $sync->syncProviders();
$count = count($result['providers'] ?? []);
return json(['code' => 0, 'msg' => "同步成功, 共{$count}个供应商", 'data' => $result]);
} catch (\Exception $e) {
return json(['code' => 500, 'msg' => '同步失败: ' . $e->getMessage()]);
}
}
/**
* 测试AI渠道连接.
*/
public function testAiChannel()
{
$providerId = $this->request->param('provider_id', '');
if (empty($providerId)) {
return json(['code' => 500, 'msg' => '缺少供应商ID']);
}
$manager = new \app\common\tools\ai\AiChannelManager();
$provider = $manager->getProvider($providerId);
if (!$provider) {
return json(['code' => 500, 'msg' => '供应商未配置或缺少API Key']);
}
$ok = $provider->testConnection();
return json(['code' => $ok ? 0 : 500, 'msg' => $ok ? '连接成功' : '连接失败,请检查配置']);
}
/**
* 获取指定供应商的模型列表.
*/
public function getModelsByProvider()
{
$providerId = $this->request->param('provider_id', '');
$sync = new \app\common\tools\ai\ModelsDevSync();
$models = $sync->getModelsByProvider($providerId);
return json(['code' => 0, 'data' => $models]);
}
/**
* 获取 models.dev 缓存状态.
*/
public function getAiCacheStatus()
{
$sync = new \app\common\tools\ai\ModelsDevSync();
$status = $sync->getCacheStatus();
return json(['code' => 0, 'data' => $status]);
}
/**
* 保存AI渠道配置.
*/
public function saveAiChannel()
{
$data = $this->request->post();
$manager = new \app\common\tools\ai\AiChannelManager();
$ok = $manager->saveChannelConfig($data);
return json(['code' => $ok ? 0 : 500, 'msg' => $ok ? '保存成功' : '保存失败']);
}
/**
* 删除AI渠道配置.
*/
public function deleteAiChannel()
{
$providerId = $this->request->param('provider_id', '');
if (empty($providerId)) {
return json(['code' => 500, 'msg' => '缺少供应商ID']);
}
$manager = new \app\common\tools\ai\AiChannelManager();
$ok = $manager->deleteChannelConfig($providerId);
return json(['code' => $ok ? 0 : 500, 'msg' => $ok ? '删除成功' : '删除失败']);
}
}