调整service
parent
1a1550ad56
commit
854f53e1d2
|
|
@ -8,6 +8,7 @@ use Slowlyo\OwlAdmin\Renderers\TableColumn;
|
||||||
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
use Slowlyo\OwlAdmin\Renderers\TextControl;
|
||||||
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
use Slowlyo\OwlAdmin\Controllers\AdminController;
|
||||||
use App\Services\Admin\RegionService;
|
use App\Services\Admin\RegionService;
|
||||||
|
use Slowlyo\OwlAdmin\Renderers\Button;
|
||||||
use App\Admin\Components;
|
use App\Admin\Components;
|
||||||
|
|
||||||
class RegionController extends AdminController
|
class RegionController extends AdminController
|
||||||
|
|
@ -24,6 +25,15 @@ class RegionController extends AdminController
|
||||||
$this->createButton(true, 'lg'),
|
$this->createButton(true, 'lg'),
|
||||||
...$this->baseHeaderToolBar(),
|
...$this->baseHeaderToolBar(),
|
||||||
])
|
])
|
||||||
|
->filter(
|
||||||
|
$this->baseFilter()->body([
|
||||||
|
amisMake()->TextControl()->make('name')->label('名称')->name('name'),
|
||||||
|
Components::make()->parentControl(admin_url('api/region-categories/tree-list'), 'category_id', '分类')->size('sm'),
|
||||||
|
|
||||||
|
Button::make()->label(__('admin.reset'))->actionType('clear-and-submit'),
|
||||||
|
amis('submit')->label(__('admin.search'))->level('primary'),
|
||||||
|
])->actions([])
|
||||||
|
)
|
||||||
->columns([
|
->columns([
|
||||||
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
TableColumn::make()->name('id')->label('ID')->sortable(true),
|
||||||
TableColumn::make()->name('name')->label('名称'),
|
TableColumn::make()->name('name')->label('名称'),
|
||||||
|
|
@ -43,7 +53,7 @@ class RegionController extends AdminController
|
||||||
{
|
{
|
||||||
return $this->baseForm()->body([
|
return $this->baseForm()->body([
|
||||||
TextControl::make()->name('name')->label('名称')->required(true),
|
TextControl::make()->name('name')->label('名称')->required(true),
|
||||||
Components::make()->parentControl('', 'category_id', '分类'),
|
Components::make()->parentControl(admin_url('api/region-categories/tree-list'), 'category_id', '分类'),
|
||||||
Components::make()->fuEditorControl('description', '介绍'),
|
Components::make()->fuEditorControl('description', '介绍'),
|
||||||
Components::make()->decimalControl('area', '面积m²'),
|
Components::make()->decimalControl('area', '面积m²'),
|
||||||
Components::make()->sortControl(),
|
Components::make()->sortControl(),
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filters\Admin;
|
||||||
|
|
||||||
|
use EloquentFilter\ModelFilter;
|
||||||
|
|
||||||
|
class RegionFilter extends ModelFilter
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 名称
|
||||||
|
*/
|
||||||
|
public function name($name){
|
||||||
|
return $this->where('name', 'like', '%'.$name.'%');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 父级分类
|
||||||
|
*/
|
||||||
|
public function category($categoryId){
|
||||||
|
return $this->where('category_id', $categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否开启
|
||||||
|
*/
|
||||||
|
public function isEnable($isEnable){
|
||||||
|
return $this->where('is_enbale', $isEnable);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,15 @@ namespace App\Models;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
|
||||||
class Region extends Model
|
class Region extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
use Filterable;
|
||||||
|
|
||||||
|
protected function serializeDate(\DateTimeInterface $date){
|
||||||
|
return $date->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
|
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @method Region getModel()
|
||||||
|
* @method Region|\Illuminate\Database\Query\Builder query()
|
||||||
|
*/
|
||||||
|
class BaseService extends AdminService
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getTree()
|
||||||
|
{
|
||||||
|
$list = $this->query()->orderByDesc('sort')->get()->toArray();
|
||||||
|
return array2tree($list);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getModelFilter()
|
||||||
|
{
|
||||||
|
return $this->modelFilterName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listQuery()
|
||||||
|
{
|
||||||
|
$model = $this->getModel();
|
||||||
|
$filter = $this->getModelFilter();
|
||||||
|
|
||||||
|
return $this->query()
|
||||||
|
->filter(request()->input(), $filter)
|
||||||
|
->orderByDesc($model->getUpdatedAtColumn() ?? $model->getKeyName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,16 +10,10 @@ use Slowlyo\OwlAdmin\Services\AdminService;
|
||||||
* @method Keyword getModel()
|
* @method Keyword getModel()
|
||||||
* @method Keyword|\Illuminate\Database\Query\Builder query()
|
* @method Keyword|\Illuminate\Database\Query\Builder query()
|
||||||
*/
|
*/
|
||||||
class KeywordService extends AdminService
|
class KeywordService extends BaseService
|
||||||
{
|
{
|
||||||
protected string $modelName = Keyword::class;
|
protected string $modelName = Keyword::class;
|
||||||
|
|
||||||
public function getTree()
|
|
||||||
{
|
|
||||||
$list = $this->query()->orderByDesc('sort')->get()->toArray();
|
|
||||||
return array2tree($list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function parentIsChild($id, $parent_id): bool
|
public function parentIsChild($id, $parent_id): bool
|
||||||
{
|
{
|
||||||
$parent = $this->query()->find($parent_id);
|
$parent = $this->query()->find($parent_id);
|
||||||
|
|
|
||||||
|
|
@ -4,30 +4,15 @@ namespace App\Services\Admin;
|
||||||
|
|
||||||
use App\Models\RegionCategory;
|
use App\Models\RegionCategory;
|
||||||
use App\Filters\Admin\RegionCategoryFilter;
|
use App\Filters\Admin\RegionCategoryFilter;
|
||||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method RegionCategory getModel()
|
* @method RegionCategory getModel()
|
||||||
* @method RegionCategory|\Illuminate\Database\Query\Builder query()
|
* @method RegionCategory|\Illuminate\Database\Query\Builder query()
|
||||||
*/
|
*/
|
||||||
class RegionCategoryService extends AdminService
|
class RegionCategoryService extends BaseService
|
||||||
{
|
{
|
||||||
protected string $modelName = RegionCategory::class;
|
protected string $modelName = RegionCategory::class;
|
||||||
|
|
||||||
public function getTree()
|
protected string $modelFilterName = RegionCategoryFilter::class;
|
||||||
{
|
|
||||||
$list = $this->query()->orderByDesc('sort')->get()->toArray();
|
|
||||||
|
|
||||||
return array2tree($list);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function listQuery()
|
|
||||||
{
|
|
||||||
$model = $this->getModel();
|
|
||||||
|
|
||||||
return $this->query()
|
|
||||||
->with('parent')
|
|
||||||
->filter(request()->input(), RegionCategoryFilter::class)
|
|
||||||
->orderByDesc($model->getUpdatedAtColumn() ?? $model->getKeyName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,16 @@
|
||||||
namespace App\Services\Admin;
|
namespace App\Services\Admin;
|
||||||
|
|
||||||
use App\Models\Region;
|
use App\Models\Region;
|
||||||
|
use App\Filters\Admin\RegionFilter;
|
||||||
use Slowlyo\OwlAdmin\Services\AdminService;
|
use Slowlyo\OwlAdmin\Services\AdminService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method Region getModel()
|
* @method Region getModel()
|
||||||
* @method Region|\Illuminate\Database\Query\Builder query()
|
* @method Region|\Illuminate\Database\Query\Builder query()
|
||||||
*/
|
*/
|
||||||
class RegionService extends AdminService
|
class RegionService extends BaseService
|
||||||
{
|
{
|
||||||
protected string $modelName = Region::class;
|
protected string $modelName = Region::class;
|
||||||
|
|
||||||
|
protected string $modelFilterName = RegionFilter::class;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue