generated from liutk/owl-admin-base
Update
parent
adb33d3744
commit
ca02342ca4
|
|
@ -8,16 +8,19 @@ use App\Admin\Services\BaseService;
|
||||||
use App\Enums\PlanStatus;
|
use App\Enums\PlanStatus;
|
||||||
use App\Enums\TaskStatus;
|
use App\Enums\TaskStatus;
|
||||||
use App\Models\Keyword;
|
use App\Models\Keyword;
|
||||||
|
use App\Models\Ledger;
|
||||||
use App\Models\Plan;
|
use App\Models\Plan;
|
||||||
use App\Models\PlanHygiene;
|
use App\Models\PlanHygiene;
|
||||||
use App\Models\PlanPerformance;
|
use App\Models\PlanPerformance;
|
||||||
use App\Models\Store;
|
use App\Models\Store;
|
||||||
|
use App\Models\Task;
|
||||||
use App\Models\TaskHygiene;
|
use App\Models\TaskHygiene;
|
||||||
use App\Models\TaskPerformance;
|
use App\Models\TaskPerformance;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
|
|
@ -215,6 +218,12 @@ class PlanService extends BaseService
|
||||||
'level_id' => $plan->planable->store_level_id,
|
'level_id' => $plan->planable->store_level_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')
|
||||||
|
->pluck('sales', 'store_id')
|
||||||
|
->toArray();
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Collection */
|
/** @var \Illuminate\Database\Eloquent\Collection */
|
||||||
$stores = Store::filter($input, StoreFilter::class)->get(['id', 'master_id']);
|
$stores = Store::filter($input, StoreFilter::class)->get(['id', 'master_id']);
|
||||||
|
|
||||||
|
|
@ -224,15 +233,23 @@ class PlanService extends BaseService
|
||||||
'store_id' => $store->id,
|
'store_id' => $store->id,
|
||||||
'store_master_id' => $store->master_id,
|
'store_master_id' => $store->master_id,
|
||||||
'expected_performance' => $plan->planable->performance,
|
'expected_performance' => $plan->planable->performance,
|
||||||
'actual_performance' => 0,
|
'actual_performance' => $aggregates[$store->id] ?? 0,
|
||||||
]);
|
]);
|
||||||
$taskable->task()->create([
|
|
||||||
|
$task = new Task([
|
||||||
'plan_id' => $plan->id,
|
'plan_id' => $plan->id,
|
||||||
'name' => '业绩指标',
|
'name' => '业绩指标',
|
||||||
'start_at' => $startAt,
|
'start_at' => $startAt,
|
||||||
'end_at' => $endAt,
|
'end_at' => $endAt,
|
||||||
'task_status' => TaskStatus::Pending,
|
'task_status' => TaskStatus::Pending,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($taskable->isSuccess()) {
|
||||||
|
$task->task_status = TaskStatus::Success;
|
||||||
|
$task->completed_at = now();
|
||||||
|
}
|
||||||
|
|
||||||
|
$taskable->task()->save($task);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue