80 lines
2.9 KiB
PHP
80 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace app\console\service;
|
|
|
|
use app\console\model\VehicleNewSkuAttributesModel;
|
|
use app\mzl\common\services\BaseService;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class VehicleNewSkuAttributesService extends BaseService
|
|
{
|
|
/**
|
|
* 定义模型
|
|
*
|
|
* @return string
|
|
*/
|
|
public function getModel(): string
|
|
{
|
|
return VehicleNewSkuAttributesModel::class;
|
|
}
|
|
|
|
/**
|
|
* 多场景配置
|
|
*/
|
|
public function queryScenes(): array
|
|
{
|
|
return [
|
|
'default' => function ($params) {
|
|
return [
|
|
'filters' => [
|
|
['field' => 'id', 'operator' => '=', 'value' => '7']
|
|
],
|
|
'fields' => ['id','attribute_id','value_id','img'],
|
|
'relations' => [
|
|
'attribute' => ['id', 'input_type', 'is_img', 'status'],
|
|
'attribute.translation' => ['attribute_name'],
|
|
'value' => ['id','color_code'],
|
|
'value.translation' => ['value_name'],
|
|
],
|
|
'sorts' => [
|
|
['field' => 'created_at', 'direction' => 'desc']
|
|
],
|
|
'pagination' => [
|
|
'page' => $params['page'] ?? 1,
|
|
'per_page' => $params['per_page'] ?? 10,
|
|
]
|
|
];
|
|
},
|
|
// 'default' => function ($params) {
|
|
// $keyword = $params['keyword'] ?? '';
|
|
// return [
|
|
// 'filters' => [
|
|
// ['field' => '***', 'operator' => '=', 'value' => '***']
|
|
// ],
|
|
// 'fields' => ['id'],
|
|
// 'relations' => [],
|
|
// 'custom' => function(Builder $q) use ($keyword) {
|
|
// // 示例
|
|
// if ($keyword) {
|
|
// $q->where(function($q2) use($keyword) {
|
|
// $q2->whereHas('***', function($q3) use($keyword) {
|
|
// $q3->where('***', 'like', "%{$keyword}%");
|
|
// })->orWhereHas('***', function($q4) use($keyword) {
|
|
// $q4->where('***', 'like', "%{$keyword}%");
|
|
// });
|
|
// });
|
|
// }
|
|
// },
|
|
// 'sorts' => [
|
|
// ['field' => 'created_at', 'direction' => 'desc']
|
|
// ],
|
|
// 'pagination' => [
|
|
// 'page' => $params['page'] ?? 1,
|
|
// 'per_page' => $params['per_page'] ?? 10,
|
|
// ]
|
|
// ];
|
|
// }
|
|
];
|
|
}
|
|
} |