From 9378d41db3716840b259aa656ead4f574dd82526 Mon Sep 17 00:00:00 2001 From: "zhangf@suq.cn" Date: Thu, 11 Dec 2025 13:21:46 +0800 Subject: [PATCH] =?UTF-8?q?feat(proxy):=20=E6=96=B0=E5=A2=9E=E5=85=A8?= =?UTF-8?q?=E5=B1=80=E4=BB=A3=E7=90=86IP=E9=85=8D=E7=BD=AE=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建GlobalProxy模型,关联geo_global_proxy表 - 实现GlobalProxyController控制器,包含save和read方法 - 添加GlobalProxyDao数据访问对象,继承UserBaseDao - 开发GlobalProxyService服务类,处理代理信息的保存与读取逻辑 - 在路由文件中注册代理相关接口,包括保存和获取详情 - 接口权限控制,设置proxySave和proxyRead权限点 --- app/controller/GlobalProxyController.php | 24 +++++++++++ app/dao/GlobalProxyDao.php | 15 +++++++ app/model/GlobalProxy.php | 33 ++++++++++++++++ app/route/route.php | 9 +++++ app/service/GlobalProxyService.php | 68 ++++++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 app/controller/GlobalProxyController.php create mode 100644 app/dao/GlobalProxyDao.php create mode 100644 app/model/GlobalProxy.php create mode 100644 app/service/GlobalProxyService.php diff --git a/app/controller/GlobalProxyController.php b/app/controller/GlobalProxyController.php new file mode 100644 index 0000000..a708f63 --- /dev/null +++ b/app/controller/GlobalProxyController.php @@ -0,0 +1,24 @@ + '', + 'agent_pass' => '' + ]); + return success($service->save($params)); + } + + + public function read(GlobalProxyService $service): Response + { + return success($service->readData()); + } + +} \ No newline at end of file diff --git a/app/dao/GlobalProxyDao.php b/app/dao/GlobalProxyDao.php new file mode 100644 index 0000000..b0bb241 --- /dev/null +++ b/app/dao/GlobalProxyDao.php @@ -0,0 +1,15 @@ +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, diff --git a/app/service/GlobalProxyService.php b/app/service/GlobalProxyService.php new file mode 100644 index 0000000..5efca9b --- /dev/null +++ b/app/service/GlobalProxyService.php @@ -0,0 +1,68 @@ +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(); + } + + +} \ No newline at end of file