|
@@ -45,6 +45,7 @@ use PhpParser\Node\Stmt\Return_;
|
|
|
use function PHPUnit\Framework\isNull;
|
|
|
use Overtrue\Pinyin\Pinyin;
|
|
|
use App\Tools\buildTree;
|
|
|
+use App\Model\WhiteRouter;
|
|
|
#[RpcService(name: "WebsiteService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
@@ -1096,8 +1097,14 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
'website_id' => $data['website_id'],
|
|
|
];
|
|
|
$result = WebsiteCategory::where($where)->orderBy('sort', 'asc')->get();
|
|
|
+ $list = [];
|
|
|
if ($result) {
|
|
|
- return Result::success($result);
|
|
|
+ foreach ($result->toArray() as $val) {
|
|
|
+ array_push($list, json_decode($val['category_arr_id']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($list);
|
|
|
} else {
|
|
|
return Result::error("查询失败", 0);
|
|
|
}
|
|
@@ -2687,4 +2694,142 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
// --自助建站-----------20250522fr----------------------end
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取网站白名单路由地址
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWhiteRouterList(array $data): array
|
|
|
+ {
|
|
|
+ // 构建基础查询
|
|
|
+ $baseQuery = WhiteRouter::query();
|
|
|
+
|
|
|
+ // 功能名称模糊查询
|
|
|
+ if (!empty($data['function_name'])) {
|
|
|
+ $baseQuery->where('function_name', 'like', '%' . $data['function_name'] . '%');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 网站ID查询 - 使用 JSON_CONTAINS 检查数组中是否包含指定的 website_id
|
|
|
+ if (!empty($data['website_id'])) {
|
|
|
+ $baseQuery->whereRaw('JSON_CONTAINS(website_id, ?)', [json_encode((int)$data['website_id'])]);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取总数
|
|
|
+ $count = $baseQuery->count();
|
|
|
+
|
|
|
+ // 分页查询
|
|
|
+ $result = $baseQuery->orderBy('updated_at', 'desc')
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("暂无数据", 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理结果,将 website_id 转换为数组并获取对应的网站名称
|
|
|
+ $result->transform(function ($item) {
|
|
|
+ $websiteIds = json_decode($item->website_id, true);
|
|
|
+ $websiteNames = Website::whereIn('id', $websiteIds)
|
|
|
+ ->pluck('website_name')
|
|
|
+ ->toArray();
|
|
|
+ $item->website_names = $websiteNames;
|
|
|
+ $item->website_id = $websiteIds; // 将 website_id 转换为数组
|
|
|
+ return $item;
|
|
|
+ });
|
|
|
+
|
|
|
+ return Result::success([
|
|
|
+ 'rows' => $result->toArray(),
|
|
|
+ 'count' => $count
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 添加网站白名单路由地址
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 修改网站白名单路由地址
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除网站白名单路由地址
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function delWhiteRouter(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ $result = WhiteRouter::where($where)->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
+
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 获取网站白名单路由地址详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getWhiteRouterInfo(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ $result = WhiteRouter::where($where)->first();
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("没有查找到相关数据", 0);
|
|
|
+ }
|
|
|
+ // 将 website_id 从 JSON 字符串转换为数组
|
|
|
+ $result->website_id = json_decode($result->website_id, true);
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
}
|