Browse Source
feat(proxy): 新增全局代理IP配置功能
feat(proxy): 新增全局代理IP配置功能
- 创建GlobalProxy模型,关联geo_global_proxy表 - 实现GlobalProxyController控制器,包含save和read方法 - 添加GlobalProxyDao数据访问对象,继承UserBaseDao - 开发GlobalProxyService服务类,处理代理信息的保存与读取逻辑 - 在路由文件中注册代理相关接口,包括保存和获取详情 - 接口权限控制,设置proxySave和proxyRead权限点master
5 changed files with 149 additions and 0 deletions
-
24app/controller/GlobalProxyController.php
-
15app/dao/GlobalProxyDao.php
-
33app/model/GlobalProxy.php
-
9app/route/route.php
-
68app/service/GlobalProxyService.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()); |
|||
} |
|||
|
|||
} |
|||
@ -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; |
|||
} |
|||
|
|||
} |
|||
@ -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; |
|||
|
|||
} |
|||
@ -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(); |
|||
} |
|||
|
|||
|
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue