64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace app\apis\service;
|
|
|
|
use app\apis\model\ArticleModel;
|
|
use app\mzl\common\services\BaseService;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ArticleService extends BaseService
|
|
{
|
|
/**
|
|
* 定义模型
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getModel(): string
|
|
{
|
|
return ArticleModel::class;
|
|
}
|
|
|
|
/**
|
|
* 多场景配置
|
|
*/
|
|
public function queryScenes(): array
|
|
{
|
|
return [
|
|
'default' => function ($params) {
|
|
return [
|
|
'filters' => $params['filters'],
|
|
'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'creater' => ['id', 'nickname',],
|
|
'comment' => ['id', 'article_id', 'content', 'avatar', 'name',],
|
|
// 'translation' => ['model_id', 'name'],
|
|
// 'brand.translation' => ['brand_id', 'name']
|
|
],
|
|
'sorts' => [
|
|
['field' => 'is_top', 'direction' => 'desc'],
|
|
['field' => 'sort', 'direction' => 'desc'],
|
|
['field' => 'publish_time', 'direction' => 'desc'],
|
|
],
|
|
'pagination' => [
|
|
'page' => $params['page'] ?? 1,
|
|
'per_page' => $params['per_page'] ?? 10,
|
|
]
|
|
];
|
|
},
|
|
'show' => function ($params) {
|
|
return [
|
|
'filters' => [
|
|
['field' => 'status', 'operator' => '=', 'value' => '1'],
|
|
['field' => 'id', 'operator' => '=', 'value' => $params['id']]
|
|
],
|
|
'fields' => ['id', 'locale', 'title', 'subtitle', 'cover', 'content', 'user_id', 'is_top', 'sort', 'status', 'publish_time', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'comment' => ['id', 'article_id', 'content', 'avatar', 'name',],
|
|
// 'translation' => ['model_id', 'name']
|
|
],
|
|
];
|
|
}
|
|
];
|
|
}
|
|
} |