Files
ulthon_information/app/admin/controller/System.php
augushong 83a2bd48a2 feat(post): 新增手机图片排版与AI智能排版功能
- 新增手机图片排版功能,支持小红书/抖音尺寸输出
- 新增AI智能排版顾问,支持内容分析与优化推荐
- 新增AI供应商管理,支持多渠道配置与同步
- 新增文章输出管理页面,支持图片预览与批量下载
- 新增字体文件与排版样式配置
2026-05-01 12:23:17 +08:00

187 lines
4.7 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 数据.
*/
public function syncModelsDev()
{
$sync = new \app\common\tools\ai\ModelsDevSync();
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 ? '删除成功' : '删除失败']);
}
}