This commit is contained in:
toom1996
2025-07-11 15:18:01 +08:00
parent 993fe4ed49
commit 6e3197d585

View File

@ -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);
}