update
This commit is contained in:
@ -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