validate( rules: [ 'month' => ['filled', 'date_format:Y-m'], ], attributes: [ 'month' => '月份', ], ); /** @var \Carbon\Carbon */ $month = Carbon::createFromFormat('Y-m', $request->input('month') ?: date('Y-m')); /** @var \App\Models\Employee */ $user = $request->user(); /** * 当月的业绩指标任务 * * @var \App\Models\TaskPerformance */ $taskPerformance = TaskPerformance::where('store_id', $user->store_id) ->where('month', $month->format('Y-m')) ->first(); $actualPerformance = Ledger::where('store_id', $user->store_id) ->whereBetween('date', [$month->copy()->startOfMonth()->format('Y-m-d'), $month->copy()->endOfMonth()->format('Y-m-d')]) ->sum('sales'); return [ 'actual_performance' => trim_zeros($actualPerformance), 'expected_performance' => trim_zeros($taskPerformance->expected_performance ?? 0), ]; } }