update
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Model\AppNewsColumn;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
@ -28,6 +29,12 @@ class NewsService extends BaseService
|
||||
if (!$query) {
|
||||
return $this->getResponse()->setCode(404)->send();
|
||||
}
|
||||
|
||||
$query['created_at'] = date('Y-m-d', $query['created_at']);
|
||||
$columnTag = AppNewsColumn::find($query['column_tag']);
|
||||
$query['column_tag'] = $columnTag->name ?? '';
|
||||
$query['column_tag_url'] = $columnTag->url ?? '';
|
||||
|
||||
// 相关文章
|
||||
$query['about'] = AppNews::formatQuery(['created_at'])
|
||||
->where('platform', $isRelation ? current(self::RELATION[$app_id]) : $app_id)
|
||||
@ -55,7 +62,7 @@ class NewsService extends BaseService
|
||||
*/
|
||||
public function index(int $id, int $limit = 30, int $page = 1): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at'])
|
||||
$query = AppNews::formatQuery(['created_at', 'column_tag'])
|
||||
->where('is_delete', 0);
|
||||
|
||||
if (isset(self::RELATION[$id])) {
|
||||
@ -74,14 +81,22 @@ class NewsService extends BaseService
|
||||
|
||||
$value = AppNews::query()->whereIn('id', $ids)->orderBy('id', 'desc')->get()->toArray();
|
||||
|
||||
$about = AppNews::formatQuery(['created_at'])
|
||||
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 ?? '';
|
||||
}
|
||||
|
||||
$hot = AppNews::formatQuery(['created_at'])
|
||||
->where('platform', $id)
|
||||
->where('is_delete', 0)
|
||||
->select(['title', 'id', 'cover'])
|
||||
->limit(10)
|
||||
->limit(5)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->toArray();
|
||||
return $this->getResponse()->setExtra('about', $about)->setExtra('total', ceil($total / $limit))->setData($value)->setCode(0)->send();
|
||||
|
||||
return $this->getResponse()->setExtra('hot', $hot)->setExtra('total', ceil($total / $limit))->setData($value)->setCode(0)->send();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user