update
This commit is contained in:
59
app/Rpc/v1/ColumnService.php
Normal file
59
app/Rpc/v1/ColumnService.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Model\AppNewsSecondColumn;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
#[RpcService(name: "column", server: "jsonrpc-http", protocol: "jsonrpc-http")]
|
||||
class ColumnService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 获取栏目
|
||||
* @url /column/index
|
||||
* @param int $app_id
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $app_id = 0): array
|
||||
{
|
||||
$resp = $this->getResponse();
|
||||
if ($app_id) {
|
||||
$firstColumn = AppNewsColumn::query()->where('website', $app_id)->get()->toArray();
|
||||
$res = [];
|
||||
foreach ($firstColumn as $index => &$column) {
|
||||
$filter = [];
|
||||
$filter[] = ['column_tag', $column['id']];
|
||||
$res[] = [
|
||||
'filter' => $filter,
|
||||
'desc' => $column['desc'],
|
||||
'item' => [['title' => $column['name'], 'link' => $column['url']]],
|
||||
'path' => $column['url'],
|
||||
];
|
||||
$second = AppNewsSecondColumn::query()->where('rid', $column['id'])->get()->toArray();
|
||||
if ($second) {
|
||||
foreach ($second as $secondCol) {
|
||||
$appendArr = [];
|
||||
$appendArr[] = ['title' => $column['name'], 'link' => $column['url']];
|
||||
$appendArr[] = ['title' => $secondCol['name'], 'link' => $column['url'] . $secondCol['url']];
|
||||
$filter = [
|
||||
['column_tag', $column['id']],
|
||||
['second_column', $secondCol['id']]
|
||||
];
|
||||
$res[] = [
|
||||
'filter' => $filter,
|
||||
'path' => "{$column['url']}{$secondCol['url']}",
|
||||
'desc' => $secondCol['desc'],
|
||||
'item' => $appendArr,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $resp->setCode(200)->setData($res)->send();
|
||||
}
|
||||
|
||||
return $resp->setCode(200)->send();
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Model\AppNewsSecondColumn;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
@ -60,11 +61,16 @@ class NewsService extends BaseService
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $id, int $limit = 30, int $page = 1): array
|
||||
public function index(int $id, int $limit = 30, int $page = 1, array $filter = []): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at', 'column_tag'])
|
||||
->where('is_delete', 0);
|
||||
|
||||
if ($filter) {
|
||||
foreach ($filter as $item) {
|
||||
$query->where(...$item);
|
||||
}
|
||||
}
|
||||
if (isset(self::RELATION[$id])) {
|
||||
$query->whereIn('platform', self::RELATION[$id]);
|
||||
} else {
|
||||
@ -83,15 +89,24 @@ class NewsService extends BaseService
|
||||
|
||||
foreach ($value as &$item) {
|
||||
$item['created_at'] = date('Y-m-d', $item['created_at']);
|
||||
$columnTag = AppNewsColumn::find($item['column_tag']);
|
||||
$item['column_tag'] = $columnTag->name ?? '';
|
||||
$item['column_tag_url'] = $columnTag->url ?? '';
|
||||
|
||||
if ($item['column_tag']) {
|
||||
$columnTag = AppNewsColumn::find($item['column_tag']);
|
||||
$item['column_tag'] = $columnTag->name ?? '';
|
||||
$item['column_tag_url'] = $columnTag->url ?? '';
|
||||
|
||||
if ($item['second_column']) {
|
||||
$secondColumnTag = AppNewsSecondColumn::find($item['second_column']);
|
||||
$item['second_column_tag'] = $secondColumnTag->name ?? '';
|
||||
$item['second_column_tag_url'] = $columnTag->url . $secondColumnTag->url ?? '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$hot = AppNews::formatQuery(['created_at'])
|
||||
->where('platform', $id)
|
||||
->where('is_delete', 0)
|
||||
->select(['title', 'id', 'cover'])
|
||||
->select(['title', 'id', 'cover', 'created_at'])
|
||||
->limit(5)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
|
Reference in New Issue
Block a user