main
Jing Li 2024-04-20 14:52:00 +08:00
parent 69b644579f
commit 5efa1255a2
3 changed files with 24 additions and 15 deletions

View File

@ -181,10 +181,7 @@ class TaskService extends BaseService
]);
if (! $task->isSuccess() && $taskable->isSuccess()) {
$task->update([
'task_status' => TaskStatus::Success,
'completed_at' => now(),
]);
$task->markAsSuccess();
}
break;

View File

@ -144,10 +144,12 @@ class LedgerController extends Controller
->where('date', $ledger->date)
->first();
if ($taskLedger) {
$taskLedger->task()->update([
'task_status' => TaskStatus::Success,
'completed_at' => $ledger->created_at,
]);
/** @var \App\Models\Task */
$task = $taskLedger->task;
if (! $task->isSuccess()) {
$task->markAsSuccess();
}
}
// 业绩指标任务
@ -156,19 +158,21 @@ class LedgerController extends Controller
->where('month', $date->format('Y-m'))
->first();
if ($taskPerformance) {
$totalSales = Ledger::where('store_id', $ledger->store_id)
$actualPerformance = Ledger::where('store_id', $ledger->store_id)
->whereBetween('date', [$date->copy()->startOfMonth()->format('Y-m-d'), $date->copy()->endOfMonth()->format('Y-m-d')])
->sum('sales');
$taskPerformance->update([
'actual_performance' => $totalSales,
'actual_performance' => $actualPerformance,
]);
if ($taskPerformance->isCompleted() && ! $taskPerformance->task->isSuccess()) {
$taskPerformance->task->update([
'task_status' => TaskStatus::Success,
'completed_at' => now(),
]);
if ($taskPerformance->isSuccess()) {
/** @var \App\Models\Task */
$task = $taskPerformance->task;
if (! $task->isSuccess()) {
$task->markAsSuccess();
}
}
}

View File

@ -51,4 +51,12 @@ class Task extends Model
{
return $this->task_status === TaskStatus::Success;
}
public function markAsSuccess(): void
{
$this->forceFill([
'task_status' => TaskStatus::Success,
'completed_at' => now(),
])->save();
}
}