main
Jing Li 2024-04-14 23:53:16 +08:00
parent 882f2bdb7c
commit 24e6ac6a7d
5 changed files with 35 additions and 5 deletions

View File

@ -108,7 +108,7 @@ class PlanController extends AdminController
->visibleOn('${planable_type == "plan_performances"}'), ->visibleOn('${planable_type == "plan_performances"}'),
amis()->TreeSelectControl() amis()->TreeSelectControl()
->name('plan_performance[store_category_id]') ->name('plan_performance[store_category_id]')
->label(__('plan.plan.store_category_id')) ->label(__('plan.plan.store_category'))
->source(admin_url('api/keywords/tree-list?parent_key=store_category')) ->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
->labelField('name') ->labelField('name')
->valueField('key') ->valueField('key')
@ -118,7 +118,7 @@ class PlanController extends AdminController
->visibleOn('${planable_type == "plan_performances"}'), ->visibleOn('${planable_type == "plan_performances"}'),
amis()->SelectControl() amis()->SelectControl()
->name('plan_performance[store_level_id]') ->name('plan_performance[store_level_id]')
->label(__('plan.plan.store_level_id')) ->label(__('plan.plan.store_level'))
->source(admin_url('api/keywords/tree-list?parent_key=store_level')) ->source(admin_url('api/keywords/tree-list?parent_key=store_level'))
->labelField('name') ->labelField('name')
->valueField('key') ->valueField('key')
@ -143,6 +143,18 @@ class PlanController extends AdminController
->required() ->required()
->valueFormat('YYYY-MM') ->valueFormat('YYYY-MM')
->visibleOn('${planable_type == "plan_hygienes"}'), ->visibleOn('${planable_type == "plan_hygienes"}'),
amis()->SelectControl()
->name('plan_hygiene[store_ids]')
->label(__('plan.plan.store'))
->value('${planable.store_ids}')
->multiple()
->joinValues(false)
->extractValue(true)
->source(admin_url('api/stores?_all=1'))
->labelField('title')
->valueField('id')
->searchable()
->visibleOn('${planable_type == "plan_hygienes"}'),
]); ]);
} }

View File

@ -62,7 +62,7 @@ class PlanService extends BaseService
$planable = PlanPerformance::create($data['plan_performance']); $planable = PlanPerformance::create($data['plan_performance']);
break; break;
case 'plan_performances': case 'plan_hygienes':
$planable = PlanHygiene::create($data['plan_hygiene']); $planable = PlanHygiene::create($data['plan_hygiene']);
break; break;
} }

View File

@ -2,6 +2,7 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
@ -12,10 +13,25 @@ class PlanHygiene extends Model
protected $fillable = [ protected $fillable = [
'month', 'month',
'store_ids',
]; ];
public function plan(): MorphOne public function plan(): MorphOne
{ {
return $this->morphOne(Plan::class, 'planable'); return $this->morphOne(Plan::class, 'planable');
} }
protected function storeIds(): Attribute
{
return Attribute::make(
get: function (mixed $value) {
if (! is_array($photos = json_decode($value ?? '', true))) {
$photos = [];
}
return $photos;
},
set: fn (mixed $value) => json_encode(is_array($value) ? $value : []),
);
}
} }

View File

@ -14,6 +14,7 @@ return new class extends Migration
Schema::create('plan_hygienes', function (Blueprint $table) { Schema::create('plan_hygienes', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('month')->comment('月份: 2024-04'); $table->string('month')->comment('月份: 2024-04');
$table->json('store_ids')->nullable()->comment('门店');
$table->timestamps(); $table->timestamps();
}); });
} }

View File

@ -9,8 +9,9 @@ return [
'created_at' => '创建时间', 'created_at' => '创建时间',
'updated_at' => '更新时间', 'updated_at' => '更新时间',
'month' => '月份', 'month' => '月份',
'store_category_id' => '门店分类', 'store' => '门店',
'store_level_id' => '门店等级', 'store_category' => '门店分类',
'store_level' => '门店等级',
'performance' => '业绩', 'performance' => '业绩',
], ],
]; ];