|
|
@@ -3417,23 +3417,28 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
*/
|
|
|
public function addWhiteRouter(array $data): array
|
|
|
{
|
|
|
- // 确保 website_id 是数组
|
|
|
- $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
|
|
|
- // 过滤空值并去重
|
|
|
- $websiteIds = array_filter($websiteIds);
|
|
|
- $websiteIds = array_unique($websiteIds);
|
|
|
- // 将数组中的值转换为整数
|
|
|
- $websiteIds = array_map(function ($value) {
|
|
|
- return (int)$value;
|
|
|
- }, $websiteIds);
|
|
|
- // 转换为 JSON 字符串存储
|
|
|
- $data['website_id'] = json_encode($websiteIds);
|
|
|
-
|
|
|
- $result = WhiteRouter::insertGetId($data);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("添加失败", 0);
|
|
|
+ try {
|
|
|
+ // 确保 website_id 是数组
|
|
|
+ $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
|
|
|
+ // 过滤空值并去重
|
|
|
+ $websiteIds = array_filter($websiteIds);
|
|
|
+ $websiteIds = array_unique($websiteIds);
|
|
|
+ // 将数组中的值转换为整数
|
|
|
+ $websiteIds = array_map(function ($value) {
|
|
|
+ return (int)$value;
|
|
|
+ }, $websiteIds);
|
|
|
+ // 转换为 JSON 字符串存储
|
|
|
+ $data['website_id'] = json_encode($websiteIds);
|
|
|
+
|
|
|
+ $result = WhiteRouter::insertGetId($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("添加失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }catch (\Exception $e){
|
|
|
+ return Result::error("路由已经存在", 0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* 修改网站白名单路由地址
|
|
|
@@ -3442,26 +3447,31 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
*/
|
|
|
public function upWhiteRouter(array $data): array
|
|
|
{
|
|
|
- $where = [
|
|
|
- 'id' => $data['id'],
|
|
|
- ];
|
|
|
- // 确保 website_id 是数组
|
|
|
- $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
|
|
|
- // 过滤空值并去重
|
|
|
- $websiteIds = array_filter($websiteIds);
|
|
|
- $websiteIds = array_unique($websiteIds);
|
|
|
- // 将数组中的值转换为整数
|
|
|
- $websiteIds = array_map(function ($value) {
|
|
|
- return (int)$value;
|
|
|
- }, $websiteIds);
|
|
|
- // 转换为 JSON 字符串存储
|
|
|
- $data['website_id'] = json_encode($websiteIds);
|
|
|
-
|
|
|
- $result = WhiteRouter::where($where)->update($data);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error("修改失败", 0);
|
|
|
+ try {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ // 确保 website_id 是数组
|
|
|
+ $websiteIds = is_array($data['website_id']) ? $data['website_id'] : [$data['website_id']];
|
|
|
+ // 过滤空值并去重
|
|
|
+ $websiteIds = array_filter($websiteIds);
|
|
|
+ $websiteIds = array_unique($websiteIds);
|
|
|
+ // 将数组中的值转换为整数
|
|
|
+ $websiteIds = array_map(function ($value) {
|
|
|
+ return (int)$value;
|
|
|
+ }, $websiteIds);
|
|
|
+ // 转换为 JSON 字符串存储
|
|
|
+ $data['website_id'] = json_encode($websiteIds);
|
|
|
+
|
|
|
+ $result = WhiteRouter::where($where)->update($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("修改失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }catch (\Exception $e){
|
|
|
+ return Result::error("路由已经存在", 0);
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
/**
|
|
|
* 删除网站白名单路由地址
|