copy()->subQuarters($this->option('quarter')); $start = $time->copy()->startOfQuarter(); $end = $time->copy()->endOfQuarter(); $sn = $time->year . '-' . $time->quarter; $list = []; CateRankModel::where('sn', $sn)->delete(); $cateList = PartyCate::withCount(['users'])->get(); foreach ($cateList as $item) { $list[] = [ 'sn' => $sn, 'cate_id' => $item->id, 'score' => $item->current_score, 'count' => $item->users_count, 'avg_score' => floor($item->score/$item->users_count), 'created_at' => $now, 'updated_at' => $now, ]; } CateRankModel::insert($list); // 清空党支部当前得分 PartyCate::where('current_score', '>', 0)->update([ 'current_score' => 0 ]); } }