first commit
This commit is contained in:
19
app/Rpc/v1/IndexService.php
Executable file
19
app/Rpc/v1/IndexService.php
Executable file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\FormModel\rpc\v1\RpcIndexModel;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
// #[RpcService(name: "index", server: "jsonrpc-http", protocol: "jsonrpc-http", publishTo: 'nacos')]
|
||||
class IndexService extends BaseService
|
||||
{
|
||||
public function index(): array
|
||||
{
|
||||
$model = new RpcIndexModel();
|
||||
$data = $model->index();
|
||||
$response = $this->getResponse()->setPageModule($data);
|
||||
return $response->send();
|
||||
}
|
||||
}
|
59
app/Rpc/v1/NewsService.php
Executable file
59
app/Rpc/v1/NewsService.php
Executable file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\Model\AppNews;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
#[RpcService(name: "news", server: "jsonrpc-http", protocol: "jsonrpc-http")]
|
||||
class NewsService extends BaseService
|
||||
{
|
||||
/**
|
||||
* 查看单个新闻详情
|
||||
* @url /news/view
|
||||
* @param $id
|
||||
* @return array
|
||||
*/
|
||||
public function view($id): array
|
||||
{
|
||||
$query = AppNews::find($id)->toArray();
|
||||
// 相关文章
|
||||
$query['about'] = AppNews::formatQuery(['created_at'])
|
||||
->select(['title', 'id'])
|
||||
->limit(10)
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
->toArray();
|
||||
|
||||
// 上一篇文章
|
||||
$query['prevNews'] = AppNews::find($id - 1, ['title', 'id'])?->toArray();
|
||||
// 下一篇文章
|
||||
$query['nextNews'] = AppNews::find($id + 1, ['title', 'id'])?->toArray();
|
||||
|
||||
return $this->getResponse()->setData($query)->setCode(0)->send();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看所有新闻
|
||||
* @url /news/index
|
||||
* @param int $limit
|
||||
* @param int $page
|
||||
* @return array
|
||||
*/
|
||||
public function index(int $limit = 10, int $page = 1): array
|
||||
{
|
||||
$query = AppNews::formatQuery(['created_at'])
|
||||
->select(['id'])
|
||||
->orderBy('id', 'desc');;
|
||||
$pagination = $query->paginate($limit, page: $page);
|
||||
$ids = [];
|
||||
foreach ($pagination->items() as $item) {
|
||||
$ids[] = $item->id;
|
||||
}
|
||||
|
||||
$value = AppNews::query()->whereIn('id', $ids)->orderBy('id', 'desc')->get()->toArray();
|
||||
|
||||
return $this->getResponse()->setData($value)->setCode(0)->send();
|
||||
}
|
||||
}
|
27
app/Rpc/v1/ShowsService.php
Executable file
27
app/Rpc/v1/ShowsService.php
Executable file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rpc\v1;
|
||||
|
||||
use App\FormModel\rpc\v1\RpcIndexModel;
|
||||
use App\Model\AppArticle;
|
||||
use App\Rpc\BaseService;
|
||||
use Hyperf\RpcServer\Annotation\RpcService;
|
||||
|
||||
// #[RpcService(name: "shows", server: "jsonrpc-http", protocol: "jsonrpc-http", publishTo: 'nacos')]
|
||||
class ShowsService extends BaseService
|
||||
{
|
||||
public function view($aid): array
|
||||
{
|
||||
$data = AppArticle::formatQuery(['images', 'title', 'cover', 'brand_name'])
|
||||
->select(['brand', 'aid', 'title', 'cover', 'brand as brand_name', 'images', 'description'])
|
||||
->where('aid', $aid)
|
||||
->first()
|
||||
->toArray();
|
||||
|
||||
$data['more'] = AppArticle::formatQuery(['images', 'title', 'cover', 'brand_name'])
|
||||
->where('brand', '=', $data['brand'])
|
||||
->orderBy('published_at', 'DESC')
|
||||
->limit(25);
|
||||
return $this->getResponse()->setPageModule($data)->send();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user