101 lines
4.1 KiB
PHP
101 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace app\apis\service;
|
|
|
|
use app\apis\model\BrandModel;
|
|
use app\mzl\common\services\BaseService;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class BrandService extends BaseService
|
|
{
|
|
/**
|
|
* 定义模型
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getModel(): string
|
|
{
|
|
return BrandModel::class;
|
|
}
|
|
|
|
/**
|
|
* 多场景配置
|
|
*/
|
|
public function queryScenes(): array
|
|
{
|
|
return [
|
|
'default' => function ($params) {
|
|
return [
|
|
'filters' => $params['filters'],
|
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'],
|
|
'banners' => ['id', 'pic', 'sort',],
|
|
'banners.translation' => ['id', 'alt',],
|
|
'traits' => ['id', 'sort',],
|
|
'traits.translation' => ['id', 'title', 'content',],
|
|
],
|
|
'sorts' => [
|
|
['field' => 'id', 'direction' => 'desc']
|
|
],
|
|
'pagination' => [
|
|
'page' => $params['page'] ?? 1,
|
|
'per_page' => $params['per_page'] ?? 10,
|
|
]
|
|
];
|
|
},
|
|
'letter' => function ($params) {
|
|
return [
|
|
'filters' => $params['filters'],
|
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'],
|
|
'banners' => ['id', 'pic', 'sort',],
|
|
'banners.translation' => ['id', 'alt',],
|
|
'traits' => ['id', 'sort',],
|
|
'traits.translation' => ['id', 'title', 'content',],
|
|
],
|
|
'sorts' => [
|
|
['field' => 'id', 'direction' => 'desc']
|
|
],
|
|
];
|
|
},
|
|
'hot' => function ($params) {
|
|
return [
|
|
'filters' => $params['filters'],
|
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'],
|
|
'banners' => ['id', 'pic', 'sort',],
|
|
'banners.translation' => ['id', 'alt',],
|
|
'traits' => ['id', 'sort',],
|
|
'traits.translation' => ['id', 'title', 'content',],
|
|
],
|
|
'sorts' => [
|
|
['field' => 'id', 'direction' => 'desc']
|
|
],
|
|
];
|
|
},
|
|
'show' => function ($params) {
|
|
return [
|
|
'filters' => [
|
|
['field' => 'status', 'operator' => '=', 'value' => '1'],
|
|
['field' => 'id', 'operator' => '=', 'value' => $params['id']],
|
|
],
|
|
'fields' => ['id', 'status', 'sort', 'toppic', 'descpic', 'logo', 'letter', 'is_hot', 'created_at', 'updated_at'],
|
|
'relations' => [
|
|
'translation' => ['brand_id', 'name', 'desc','toppic_alt','descpic_alt','logo_alt'],
|
|
'banners' => ['id', 'pic', 'sort',],
|
|
'banners.translation' => ['id', 'alt',],
|
|
'traits' => ['id', 'sort',],
|
|
'traits.translation' => ['id', 'title', 'content',],
|
|
],
|
|
'sorts' => [
|
|
['field' => 'id', 'direction' => 'desc']
|
|
],
|
|
];
|
|
},
|
|
];
|
|
}
|
|
} |