update
This commit is contained in:
@ -9,6 +9,11 @@ use Hyperf\RpcServer\Annotation\RpcService;
|
|||||||
#[RpcService(name: "news", server: "jsonrpc-http", protocol: "jsonrpc-http")]
|
#[RpcService(name: "news", server: "jsonrpc-http", protocol: "jsonrpc-http")]
|
||||||
class NewsService extends BaseService
|
class NewsService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public const RELATION = [
|
||||||
|
'11' => [1, 11],
|
||||||
|
'10' => [9, 10],
|
||||||
|
];
|
||||||
/**
|
/**
|
||||||
* 查看单个新闻详情
|
* 查看单个新闻详情
|
||||||
* @url /news/view
|
* @url /news/view
|
||||||
@ -17,7 +22,8 @@ class NewsService extends BaseService
|
|||||||
*/
|
*/
|
||||||
public function view($id, $app_id): array
|
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) {
|
if (!$query) {
|
||||||
return $this->getResponse()->setCode(404)->send();
|
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
|
public function index(int $id, int $limit = 30, int $page = 1): array
|
||||||
{
|
{
|
||||||
$relationId = [
|
|
||||||
'11' => [1, 11],
|
|
||||||
'10' => [9, 10],
|
|
||||||
];
|
|
||||||
|
|
||||||
$query = AppNews::formatQuery(['created_at'])
|
$query = AppNews::formatQuery(['created_at'])
|
||||||
->where('is_delete', 0);
|
->where('is_delete', 0);
|
||||||
var_dump($relationId[$id]);
|
|
||||||
if (isset($relationId[$id])) {
|
if (isset(self::RELATION[$id])) {
|
||||||
$query->whereIn('platform', $relationId[$id]);
|
$query->whereIn('platform', self::RELATION[$id]);
|
||||||
} else {
|
} else {
|
||||||
$query->where('platform', $id);
|
$query->where('platform', $id);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user