generated from liutk/owl-admin-base
Update
parent
9dbb4b0af7
commit
28382facf7
|
|
@ -6,6 +6,9 @@ use App\Admin\Controllers\AdminController;
|
|||
use App\Admin\Services\Plan\PlanService;
|
||||
use App\Enums\PlanStatus;
|
||||
use App\Enums\TaskStatus;
|
||||
use App\Models\PlanHygiene;
|
||||
use App\Models\PlanLedger;
|
||||
use App\Models\PlanPerformance;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
|
|
@ -21,18 +24,6 @@ class PlanController extends AdminController
|
|||
{
|
||||
protected string $serviceName = PlanService::class;
|
||||
|
||||
protected array $planableTypes = [
|
||||
'plan_ledgers' => '总账录入',
|
||||
'plan_performances' => '业绩指标',
|
||||
'plan_hygienes' => '清洁卫生',
|
||||
];
|
||||
|
||||
protected array $planableTypeLabelMap = [
|
||||
'plan_ledgers' => '<span class="label label-primary">总账录入</span>',
|
||||
'plan_performances' => '<span class="label label-danger">业绩指标</span>',
|
||||
'plan_hygienes' => '<span class="label label-success">清洁卫生</span>',
|
||||
];
|
||||
|
||||
public function list(): Page
|
||||
{
|
||||
$crud = $this->baseCRUD()
|
||||
|
|
@ -54,7 +45,7 @@ class PlanController extends AdminController
|
|||
->name('planable_type')
|
||||
->label(__('plan.plan.type'))
|
||||
->multiple()
|
||||
->options($this->planableTypes)
|
||||
->options($this->planableTypeOptions())
|
||||
->clearable(),
|
||||
|
||||
amis()->SelectControl()
|
||||
|
|
@ -68,7 +59,7 @@ class PlanController extends AdminController
|
|||
->columns([
|
||||
amis()->TableColumn('id', __('plan.plan.id')),
|
||||
amis()->TableColumn('name', __('plan.plan.name')),
|
||||
amis()->TableColumn('planable_type', __('plan.plan.type'))->type('mapping')->map($this->planableTypeLabelMap),
|
||||
amis()->TableColumn('planable_type', __('plan.plan.type'))->type('mapping')->map($this->planableTypeLabelMap()),
|
||||
amis()->TableColumn('plan_status', __('plan.plan.status'))->type('mapping')->map(PlanStatus::labelMap()),
|
||||
amis()->TableColumn('created_at', __('plan.plan.created_at')),
|
||||
$this->rowActions([
|
||||
|
|
@ -91,11 +82,14 @@ class PlanController extends AdminController
|
|||
|
||||
public function form(): Form
|
||||
{
|
||||
$planableTypePerformance = (new PlanPerformance())->getMorphClass();
|
||||
$planableTypeHygiene = (new PlanHygiene())->getMorphClass();
|
||||
|
||||
return $this->baseForm()->title('')->body([
|
||||
amis()->SelectControl()
|
||||
->name('planable_type')
|
||||
->label(__('plan.plan.type'))
|
||||
->options(Arr::except($this->planableTypes, ['plan_ledgers']))
|
||||
->options(Arr::except($this->planableTypeOptions(), [(new PlanLedger())->getMorphClass()]))
|
||||
->required()
|
||||
->disabledOn('${planable_id > 0}'),
|
||||
|
||||
|
|
@ -112,7 +106,7 @@ class PlanController extends AdminController
|
|||
->value('${planable.month}')
|
||||
->required()
|
||||
->valueFormat('YYYY-MM')
|
||||
->visibleOn('${planable_type == "plan_performances"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),
|
||||
amis()->TreeSelectControl()
|
||||
->name('plan_performance[store_category_id]')
|
||||
->label(__('plan.plan_performance.store_category'))
|
||||
|
|
@ -122,7 +116,7 @@ class PlanController extends AdminController
|
|||
->onlyLeaf(true)
|
||||
->value('${planable.store_category_id}')
|
||||
->required()
|
||||
->visibleOn('${planable_type == "plan_performances"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),
|
||||
amis()->SelectControl()
|
||||
->name('plan_performance[store_level_id]')
|
||||
->label(__('plan.plan_performance.store_level'))
|
||||
|
|
@ -131,7 +125,7 @@ class PlanController extends AdminController
|
|||
->valueField('key')
|
||||
->value('${planable.store_level_id}')
|
||||
->clearable()
|
||||
->visibleOn('${planable_type == "plan_performances"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),
|
||||
amis()->NumberControl()
|
||||
->name('plan_performance[performance]')
|
||||
->label(__('plan.plan_performance.performance'))
|
||||
|
|
@ -140,7 +134,7 @@ class PlanController extends AdminController
|
|||
->precision(2)
|
||||
->showSteps(false)
|
||||
->required()
|
||||
->visibleOn('${planable_type == "plan_performances"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),
|
||||
|
||||
// 清洁卫生
|
||||
amis()->MonthControl()
|
||||
|
|
@ -149,7 +143,7 @@ class PlanController extends AdminController
|
|||
->value('${planable.month}')
|
||||
->required()
|
||||
->valueFormat('YYYY-MM')
|
||||
->visibleOn('${planable_type == "plan_hygienes"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypeHygiene.'"}'),
|
||||
amis()->SelectControl()
|
||||
->name('plan_hygiene[store_ids]')
|
||||
->label(__('plan.plan_hygiene.store'))
|
||||
|
|
@ -161,26 +155,30 @@ class PlanController extends AdminController
|
|||
->labelField('title')
|
||||
->valueField('id')
|
||||
->searchable()
|
||||
->visibleOn('${planable_type == "plan_hygienes"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypeHygiene.'"}'),
|
||||
]);
|
||||
}
|
||||
|
||||
public function detail(): Form
|
||||
{
|
||||
$planableTypeLedger = (new PlanLedger())->getMorphClass();
|
||||
$planableTypePerformance = (new PlanPerformance())->getMorphClass();
|
||||
$planableTypeHygiene = (new PlanHygiene())->getMorphClass();
|
||||
|
||||
return $this->baseDetail()->title('')->body([
|
||||
amis()->Property()->items([
|
||||
['label' => __('plan.plan.name'), 'content' => '${name}'],
|
||||
['label' => __('plan.plan.type'), 'content' => amis()->Mapping()->name('planable_type')->map($this->planableTypeLabelMap)],
|
||||
['label' => __('plan.plan.type'), 'content' => amis()->Mapping()->name('planable_type')->map($this->planableTypeLabelMap())],
|
||||
['label' => __('plan.plan.status'), 'content' => amis()->Mapping()->name('plan_status')->map(PlanStatus::labelMap())],
|
||||
// 总账录入
|
||||
['label' => __('plan.plan_ledger.date'), 'content' => '${planable.date}', 'visibleOn' => '${planable_type == "plan_ledgers"}'],
|
||||
['label' => __('plan.plan_ledger.date'), 'content' => '${planable.date}', 'visibleOn' => '${planable_type == "'.$planableTypeLedger.'"}'],
|
||||
// 业绩指标
|
||||
['label' => __('plan.plan_performance.month'), 'content' => '${planable.month}', 'visibleOn' => '${planable_type == "plan_performances"}'],
|
||||
['label' => __('plan.plan_performance.store_category'), 'content' => '${planable.store_category.name}', 'visibleOn' => '${planable_type == "plan_performances"}'],
|
||||
['label' => __('plan.plan_performance.store_level'), 'content' => '${planable.store_level.name}', 'visibleOn' => '${planable_type == "plan_performances"}'],
|
||||
['label' => __('plan.plan_performance.performance'), 'content' => '${planable.performance}', 'visibleOn' => '${planable_type == "plan_performances"}'],
|
||||
['label' => __('plan.plan_performance.month'), 'content' => '${planable.month}', 'visibleOn' => '${planable_type == "'.$planableTypePerformance.'"}'],
|
||||
['label' => __('plan.plan_performance.store_category'), 'content' => '${planable.store_category.name}', 'visibleOn' => '${planable_type == "'.$planableTypePerformance.'"}'],
|
||||
['label' => __('plan.plan_performance.store_level'), 'content' => '${planable.store_level.name}', 'visibleOn' => '${planable_type == "'.$planableTypePerformance.'"}'],
|
||||
['label' => __('plan.plan_performance.performance'), 'content' => '${planable.performance}', 'visibleOn' => '${planable_type == "'.$planableTypePerformance.'"}'],
|
||||
// 清洁卫生
|
||||
['label' => __('plan.plan_hygiene.month'), 'content' => '${planable.month}', 'visibleOn' => '${planable_type == "plan_hygienes"}'],
|
||||
['label' => __('plan.plan_hygiene.month'), 'content' => '${planable.month}', 'visibleOn' => '${planable_type == "'.$planableTypeHygiene.'"}'],
|
||||
[
|
||||
'label' => __('plan.plan_hygiene.store'),
|
||||
'content' => amis()->Each()
|
||||
|
|
@ -188,7 +186,7 @@ class PlanController extends AdminController
|
|||
->items(
|
||||
amis()->Tpl()->tpl('<span class="label label-primary m-l-sm">${title}</span>')
|
||||
),
|
||||
'visibleOn' => '${planable_type == "plan_hygienes"}',
|
||||
'visibleOn' => '${planable_type == "'.$planableTypeHygiene.'"}',
|
||||
],
|
||||
]),
|
||||
|
||||
|
|
@ -207,7 +205,7 @@ class PlanController extends AdminController
|
|||
amis()->TableColumn('completed_at', __('plan.task.completed_at')),
|
||||
amis()->TableColumn('created_at', __('plan.task.created_at')),
|
||||
])
|
||||
->visibleOn('${planable_type == "plan_ledgers"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypeLedger.'"}'),
|
||||
|
||||
// 业绩指标
|
||||
amis()->CRUDTable()
|
||||
|
|
@ -227,7 +225,7 @@ class PlanController extends AdminController
|
|||
amis()->TableColumn('completed_at', __('plan.task.completed_at')),
|
||||
amis()->TableColumn('created_at', __('plan.task.created_at')),
|
||||
])
|
||||
->visibleOn('${planable_type == "plan_performances"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),
|
||||
|
||||
// 清洁卫生
|
||||
amis()->CRUDTable()
|
||||
|
|
@ -245,7 +243,7 @@ class PlanController extends AdminController
|
|||
amis()->TableColumn('completed_at', __('plan.task.completed_at')),
|
||||
amis()->TableColumn('created_at', __('plan.task.created_at')),
|
||||
])
|
||||
->visibleOn('${planable_type == "plan_hygienes"}'),
|
||||
->visibleOn('${planable_type == "'.$planableTypeHygiene.'"}'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
@ -275,4 +273,26 @@ class PlanController extends AdminController
|
|||
->confirmText('是否发布选中的任务计划?')
|
||||
->api('post:' . admin_url('/plan/plans/${id}/publish'));
|
||||
}
|
||||
|
||||
protected function planableTypeOptions(): array
|
||||
{
|
||||
return [
|
||||
(new PlanLedger())->getMorphClass() => '总账录入',
|
||||
(new PlanPerformance())->getMorphClass() => '业绩指标',
|
||||
(new PlanHygiene())->getMorphClass() => '清洁卫生',
|
||||
];
|
||||
}
|
||||
|
||||
protected function planableTypeLabelMap(): array
|
||||
{
|
||||
$planableTypeLedger = (new PlanLedger())->getMorphClass();
|
||||
$planableTypePerformance = (new PlanPerformance())->getMorphClass();
|
||||
$planableTypeHygiene = (new PlanHygiene())->getMorphClass();
|
||||
|
||||
return [
|
||||
$planableTypeLedger => '<span class="label label-primary">'.$this->planableTypeOptions()[$planableTypeLedger ].'</span>',
|
||||
$planableTypePerformance => '<span class="label label-danger">'.$this->planableTypeOptions()[$planableTypePerformance ].'</span>',
|
||||
$planableTypeHygiene => '<span class="label label-success">'.$this->planableTypeOptions()[$planableTypeHygiene ].'</span>',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,19 +32,22 @@ class PlanService extends BaseService
|
|||
|
||||
public function store($data): bool
|
||||
{
|
||||
$planableTypePerformance = (new PlanPerformance())->getMorphClass();
|
||||
$planableTypeHygiene = (new PlanHygiene())->getMorphClass();
|
||||
|
||||
$rules = array_merge(
|
||||
[
|
||||
'name' => ['bail', 'required', 'max:255'],
|
||||
'planable_type' => ['bail', 'required', Rule::in(['plan_performances', 'plan_hygienes'])],
|
||||
'planable_type' => ['bail', 'required', Rule::in([$planableTypePerformance, $planableTypeHygiene])],
|
||||
],
|
||||
match ($data['planable_type'] ?? '') {
|
||||
'plan_performances' => [
|
||||
$planableTypePerformance => [
|
||||
'plan_performance.month' => ['bail', 'required', 'date_format:Y-m'],
|
||||
'plan_performance.store_category_id' => ['bail', 'required', Rule::exists(Keyword::class, 'key')],
|
||||
'plan_performance.store_level_id' => ['bail', 'nullable', Rule::exists(Keyword::class, 'key')],
|
||||
'plan_performance.performance' => ['bail', 'required', 'numeric', 'min:0'],
|
||||
],
|
||||
'plan_hygienes' => [
|
||||
$planableTypeHygiene => [
|
||||
'plan_hygiene.month' => ['bail', 'required', 'date_format:Y-m'],
|
||||
],
|
||||
},
|
||||
|
|
@ -65,11 +68,11 @@ class PlanService extends BaseService
|
|||
);
|
||||
|
||||
switch ($data['planable_type']) {
|
||||
case 'plan_performances':
|
||||
case $planableTypePerformance:
|
||||
$planable = PlanPerformance::create($data['plan_performance']);
|
||||
break;
|
||||
|
||||
case 'plan_hygienes':
|
||||
case $planableTypeHygiene:
|
||||
$planable = PlanHygiene::create($data['plan_hygiene']);
|
||||
break;
|
||||
}
|
||||
|
|
@ -95,14 +98,14 @@ class PlanService extends BaseService
|
|||
[
|
||||
'name' => ['filled', 'max:255'],
|
||||
],
|
||||
match ($plan->planable_type) {
|
||||
'plan_performances' => [
|
||||
match (get_class($plan->planable)) {
|
||||
PlanPerformance::class => [
|
||||
'plan_performance.month' => ['bail', 'required', 'date_format:Y-m'],
|
||||
'plan_performance.store_category_id' => ['bail', 'required', Rule::exists(Keyword::class, 'key')],
|
||||
'plan_performance.store_level_id' => ['bail', 'nullable', Rule::exists(Keyword::class, 'key')],
|
||||
'plan_performance.performance' => ['bail', 'required', 'numeric', 'min:0'],
|
||||
],
|
||||
'plan_hygienes' => [
|
||||
PlanHygiene::class => [
|
||||
'plan_hygiene.month' => ['bail', 'required', 'date_format:Y-m'],
|
||||
],
|
||||
},
|
||||
|
|
@ -126,12 +129,12 @@ class PlanService extends BaseService
|
|||
}
|
||||
$plan->save();
|
||||
|
||||
switch ($plan->planable_type) {
|
||||
case 'plan_performances':
|
||||
switch (get_class($plan->planable)) {
|
||||
case PlanPerformance::class:
|
||||
$plan->planable->update($data['plan_performance']);
|
||||
break;
|
||||
|
||||
case 'plan_hygienes':
|
||||
case PlanHygiene::class:
|
||||
$plan->planable->update($data['plan_hygiene']);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue