diff --git a/app/Rpc/v1/NewsService.php b/app/Rpc/v1/NewsService.php index fd54226..c9107ae 100755 --- a/app/Rpc/v1/NewsService.php +++ b/app/Rpc/v1/NewsService.php @@ -9,6 +9,11 @@ use Hyperf\RpcServer\Annotation\RpcService; #[RpcService(name: "news", server: "jsonrpc-http", protocol: "jsonrpc-http")] class NewsService extends BaseService { + + public const RELATION = [ + '11' => [1, 11], + '10' => [9, 10], + ]; /** * 查看单个新闻详情 * @url /news/view @@ -17,7 +22,8 @@ class NewsService extends BaseService */ public function view($id, $app_id): array { - $query = AppNews::query()->where('id', $id)->where('platform', $app_id)->where('is_delete', 0)->first()?->toArray(); + $isRelation = isset(self::RELATION[$app_id]); + $query = AppNews::query()->where('id', $id)->where('platform', $isRelation ? current(self::RELATION[$app_id]) : $app_id)->where('is_delete', 0)->first()?->toArray(); if (!$query) { return $this->getResponse()->setCode(404)->send(); @@ -48,16 +54,11 @@ class NewsService extends BaseService */ public function index(int $id, int $limit = 30, int $page = 1): array { - $relationId = [ - '11' => [1, 11], - '10' => [9, 10], - ]; - $query = AppNews::formatQuery(['created_at']) ->where('is_delete', 0); -var_dump($relationId[$id]); - if (isset($relationId[$id])) { - $query->whereIn('platform', $relationId[$id]); + + if (isset(self::RELATION[$id])) { + $query->whereIn('platform', self::RELATION[$id]); } else { $query->where('platform', $id); }