put($file, ''); // 按月获取数据 $firstDay = UserOperationLog::where('op_type', 'dict_lookup') ->orderBy('created_at') ->select('created_at') ->first(); $firstDay = strtotime($firstDay->created_at); $firstMonth = Carbon::create(date('Y-m', $firstDay)); $now = Carbon::now(); $current = $firstMonth; $sumCount = 0; while ($current <= $now) { // code... $start = Carbon::create($current)->startOfMonth(); $end = Carbon::create($current)->endOfMonth(); $date = $current->format('Y-m'); $count = UserOperationLog::where('op_type', 'dict_lookup') ->whereDate('created_at', '>=', $start) ->whereDate('created_at', '<=', $end) ->count(); $sumCount += $count; $editor = UserOperationLog::where('op_type', 'dict_lookup') ->whereDate('created_at', '>=', $start) ->whereDate('created_at', '<=', $end) ->groupBy('user_id') ->select('user_id')->get(); $info = $date.','.$count.','.$sumCount.','.count($editor); $this->info($info); Storage::disk('local')->append($file, $info); $current->addMonth(1); } return 0; } }