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