main
panliang 2024-04-29 13:47:42 +08:00
commit c03698fc0b
2 changed files with 13 additions and 6 deletions

View File

@ -120,7 +120,6 @@ class PlanController extends AdminController
->source(admin_url('api/keywords/tree-list?parent_key=store_category'))
->labelField('name')
->valueField('key')
->onlyLeaf(true)
->value('${planable.store_category_id}')
->required()
->visibleOn('${planable_type == "'.$planableTypePerformance.'"}'),

View File

@ -213,11 +213,17 @@ class PlanService extends BaseService
// 任务结束时间
$endAt = $startAt->copy()->endOfMonth();
$input = [
'category_id' => $plan->planable->store_category_id,
'level_id' => $plan->planable->store_level_id,
];
// 门店分类IDs
$categoryIds = value(function ($id) {
$ids = collect();
if ($parent = Keyword::where('key', $id)->first()) {
/** @var \Illuminate\Support\Collection */
$ids = Keyword::where('path', 'like', "%-{$parent->id}-%")->pluck('key');
}
return $ids->push($id);
}, $plan->planable->store_category_id);
// 门店业绩统计
$aggregates = Ledger::select(['store_id', DB::raw('SUM(`sales`) as sales')])
->whereBetween('date', [$startAt->format('Y-m-d'), $endAt->format('Y-m-d')])
->groupBy('store_id')
@ -225,7 +231,9 @@ class PlanService extends BaseService
->toArray();
/** @var \Illuminate\Database\Eloquent\Collection */
$stores = Store::filter($input, StoreFilter::class)->get(['id', 'master_id']);
$stores = Store::filter(['level_id' => $plan->planable->store_level_id], StoreFilter::class)
->whereIn('category_id', $categoryIds)
->get(['id', 'master_id']);
foreach ($stores as $store) {
$taskable = TaskPerformance::create([