Browse Source

feat(proxy): 新增全局代理IP配置功能

- 创建GlobalProxy模型,关联geo_global_proxy表
- 实现GlobalProxyController控制器,包含save和read方法
- 添加GlobalProxyDao数据访问对象,继承UserBaseDao
- 开发GlobalProxyService服务类,处理代理信息的保存与读取逻辑
- 在路由文件中注册代理相关接口,包括保存和获取详情
- 接口权限控制,设置proxySave和proxyRead权限点
master
zhangf@suq.cn 6 days ago
parent
commit
9378d41db3
  1. 24
      app/controller/GlobalProxyController.php
  2. 15
      app/dao/GlobalProxyDao.php
  3. 33
      app/model/GlobalProxy.php
  4. 9
      app/route/route.php
  5. 68
      app/service/GlobalProxyService.php

24
app/controller/GlobalProxyController.php

@ -0,0 +1,24 @@
<?php
namespace app\controller;
use app\service\GlobalProxyService;
use support\Response;
class GlobalProxyController
{
public function save(GlobalProxyService $service): Response
{
$params = requestOnly([
'agent_ip' => '',
'agent_pass' => ''
]);
return success($service->save($params));
}
public function read(GlobalProxyService $service): Response
{
return success($service->readData());
}
}

15
app/dao/GlobalProxyDao.php

@ -0,0 +1,15 @@
<?php
namespace app\dao;
use app\model\GlobalProxy;
use plugin\piadmin\app\base\UserBaseDao;
class GlobalProxyDao extends UserBaseDao
{
protected function setModel(): string
{
return GlobalProxy::class;
}
}

33
app/model/GlobalProxy.php

@ -0,0 +1,33 @@
<?php
namespace app\model;
use plugin\piadmin\app\base\BaseModel;
/**
* AI创作指令模型
*/
class GlobalProxy extends BaseModel
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'geo_global_proxy';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
}

9
app/route/route.php

@ -7,6 +7,7 @@ use app\controller\CreationTaskController;
use app\controller\DistillationQuestionsController;
use app\controller\EnterprisePortraitCategoryController;
use app\controller\EnterprisePortraitLibraryController;
use app\controller\GlobalProxyController;
use app\controller\KnowledgeLibraryController;
use app\controller\DistillationWordController;
use plugin\piadmin\app\middleware\UserAuthorizationMiddleware;
@ -140,6 +141,14 @@ Route::group('/service/v1', function () {
Route::post('/delete', [CreationArticleController::class, 'delete'])->setParams(['perm' => ['articleDelete']]);
});
});
//全局代理IP
Route::group('/proxy', function () {
//新增
Route::post('/save', [GlobalProxyController::class, 'save'])->setParams(['perm' => ['proxySave']]);
//详情
Route::get('/read', [GlobalProxyController::class, 'read'])->setParams(['perm' => ['proxyRead']]);
});
})->middleware([
UserAuthorizationMiddleware::class,
// AdminAuthorizationMiddleware::class,

68
app/service/GlobalProxyService.php

@ -0,0 +1,68 @@
<?php
namespace app\service;
use app\dao\GlobalProxyDao;
use plugin\piadmin\app\base\BaseService;
use plugin\piadmin\app\exception\ApiException;
use plugin\piadmin\app\utils\RequestUtils;
use support\think\Db;
class GlobalProxyService extends BaseService
{
protected $dao;
public function __construct(GlobalProxyDao $dao)
{
$this->dao = $dao;
}
/**
* 保存信息
* @param array $params
* @return array
*/
public function save(array $params): array
{
// 落库
Db::startTrans();
try {
$userInfo = RequestUtils::getUserInfo();
$proxy = $this->dao->getOne(['uid' => $userInfo['id']]);
if ($proxy) {
$this->dao->update(['id' => $proxy['id']], $params);
} else {
$params['uid'] = $userInfo['id'];
$this->dao->save($params);
}
Db::commit();
} catch (\Exception $exception) {
Db::rollback();
throw new ApiException($exception->getMessage());
}
return $params;
}
/**
* 获取信息
* @param mixed $id
* @return array
*/
public function readData(): array
{
$userInfo = RequestUtils::getUserInfo();
$proxy = $this->dao->getOne(['uid' => $userInfo['id']]);
if (empty($proxy)) {
return [
'uid' => $userInfo['id'],
'agent_ip' => '',
'agent_pass' => ''
];
}
return $proxy->toArray();
}
}
Loading…
Cancel
Save