generated from liutk/owl-admin-base
141 lines
7.2 KiB
PHP
141 lines
7.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers\Store;
|
|
|
|
use App\Admin\Controllers\AdminController;
|
|
use App\Admin\Services\StoreService;
|
|
use App\Enums\BusinessStatus;
|
|
use App\Enums\EmployeeStatus;
|
|
use App\Models\Store;
|
|
use Slowlyo\OwlAdmin\Admin;
|
|
use Slowlyo\OwlAdmin\Renderers\Form;
|
|
use Slowlyo\OwlAdmin\Renderers\Page;
|
|
|
|
/**
|
|
* 门店管理
|
|
*/
|
|
class StoreController extends AdminController
|
|
{
|
|
protected string $serviceName = StoreService::class;
|
|
|
|
public function list(): Page
|
|
{
|
|
$user = Admin::user();
|
|
$crud = $this->baseCRUD()
|
|
->tableLayout('fixed')
|
|
->headerToolbar([
|
|
$this->createTypeButton('drawer', 'lg')->visible($user->can('admin.store.stores.create')),
|
|
...$this->baseHeaderToolBar(),
|
|
])
|
|
->bulkActions([])
|
|
->filter($this->baseFilter()->body([
|
|
amis()->GroupControl()->mode('horizontal')->body([
|
|
amis()->TextControl()->name('title')->label(__('store.title'))->columnRatio(3)->clearable(),
|
|
amis()->TreeSelectControl()->name('category_id')->label(__('store.category_id'))->columnRatio(3)
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->onlyLeaf(true)
|
|
->clearable(),
|
|
amis()->SelectControl()->name('business_id')->label(__('store.business_id'))->columnRatio(3)
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_business'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->clearable(),
|
|
]),
|
|
amis()->GroupControl()->mode('horizontal')->body([
|
|
amis()->SelectControl()->name('level_id')->label(__('store.level_id'))->columnRatio(3)
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_level'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->clearable(),
|
|
// amis()->InputCityControl()->name('region')->label(__('store.region'))->columnRatio(3)
|
|
// ->allowDistrict(false)
|
|
// ->extractValue(false)
|
|
// ->clearable(),
|
|
amis()->SelectControl()->name('business_status')->label(__('store.business_status'))->options(BusinessStatus::options())->columnRatio(3)->clearable(),
|
|
]),
|
|
]))
|
|
->filterDefaultVisible()
|
|
->columns([
|
|
amis()->TableColumn()->name('id')->label(__('store.id')),
|
|
amis()->TableColumn()->name('title')->label(__('store.title')),
|
|
amis()->TableColumn()->name('master.name')->label(__('store.master_id')),
|
|
amis()->TableColumn()->name('category.name')->label(__('store.category_id')),
|
|
amis()->TableColumn()->name('business.name')->label(__('store.business_id')),
|
|
amis()->TableColumn()->name('level.name')->label(__('store.level_id')),
|
|
amis()->TableColumn()->name('profit_ratio')->label(__('store.profit_ratio'))->type('tpl')->set('tpl', '${profit_ratio}%'),
|
|
amis()->TableColumn()->name('region')->label(__('store.region'))->set('type', 'tpl')->set('tpl', '${region.province}-${region.city}'),
|
|
amis()->TableColumn()->name('business_status')->label(__('store.business_status'))->type('switch')->trueValue(BusinessStatus::Open)->falseValue(BusinessStatus::Close),
|
|
amis()->TableColumn()->name('created_at')->label(__('store.created_at')),
|
|
$this->rowActions([
|
|
$this->rowShowButton()->visible($user->can('admin.store.stores.view')),
|
|
$this->rowEditTypeButton('drawer', 'lg')->visible($user->can('admin.store.stores.update')),
|
|
$this->rowDeleteButton()->visible($user->can('admin.store.stores.delete')),
|
|
]),
|
|
]);
|
|
|
|
return $this->baseList($crud);
|
|
}
|
|
|
|
public function form($edit): Form
|
|
{
|
|
return $this->baseForm()->title('')->body([
|
|
amis()->TextControl()->name('title')->label(__('store.title'))->required(),
|
|
amis()->SelectControl()->name('master_id')->label(__('store.master_id'))
|
|
->source($edit ? admin_url('api/employees?_all=1&employee_status='.EmployeeStatus::Online->value) : admin_url('api/employees?_all=1&store_id=0&employee_status='.EmployeeStatus::Online->value))
|
|
->labelField('name')
|
|
->valueField('id')
|
|
->searchable()
|
|
->required(),
|
|
amis()->TreeSelectControl()->name('category_id')->label(__('store.category_id'))
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->onlyLeaf(true)
|
|
->required(),
|
|
amis()->SelectControl()->name('business_id')->label(__('store.business_id'))
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_business'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->required(),
|
|
amis()->SelectControl()->name('level_id')->label(__('store.level_id'))
|
|
->source(admin_url('api/keywords/tree-list?parent_key=store_level'))
|
|
->labelField('name')
|
|
->valueField('key')
|
|
->required(),
|
|
amis()->NumberControl()
|
|
->name('profit_ratio')
|
|
->label(__('store.profit_ratio'))
|
|
->placeholder(__('store.profit_ratio'))
|
|
->precision(2)
|
|
->showSteps(false)
|
|
->required(),
|
|
amis()->InputCityControl()->name('region')->label(__('store.region'))->allowDistrict(false)->extractValue(false)->required(),
|
|
amis()->LocationControl()->name('region')->label(__('store.location'))->ak(config('baidu.js_secret'))->autoSelectCurrentLoc()->required(),
|
|
]);
|
|
}
|
|
|
|
public function detail(): Form
|
|
{
|
|
$detail = amis()->Property()->items([
|
|
['label' => __('store.title'), 'content' => '${title}'],
|
|
['label' => __('store.master_id'), 'content' => '${master.name}'],
|
|
['label' => __('store.business_status'), 'content' => amis()->Tag()->label('${business_status_text}')->color('${business_status_color}')],
|
|
['label' => __('store.category_id'), 'content' => '${category.name}'],
|
|
['label' => __('store.business_id'), 'content' => '${business.name}'],
|
|
['label' => __('store.level_id'), 'content' => '${level.name}'],
|
|
['label' => __('store.region'), 'content' => '${region.province}-${region.city}'],
|
|
['label' => __('store.address'), 'content' => '${address}', 'span' => 2],
|
|
['label' => __('store.profit_ratio'), 'content' => '${profit_ratio}%', 'span' => 3],
|
|
]);
|
|
|
|
return $this->baseDetail()->title('')->body([$detail]);
|
|
}
|
|
|
|
public function shareList()
|
|
{
|
|
return $this->service->listQuery()->where('business_status', BusinessStatus::Open)->get(['id', 'title']);
|
|
}
|
|
}
|