join('promotion_activities as a', 'a.id', '=', 'p.activity_id')->where('a.type', 9)->where('a.status', 1) ->where('a.start_time', '<=', now()->timestamp)->where('a.end_time', '>=', now()->timestamp)->select('p.*')->orderBy('p.id') ->chunkById(100, function ($rows) use ($service, &$errors) { foreach ($rows as $row) try { $service->progress($row->activity_id, $row->user_id); } catch (\Throwable $e) { ++$errors; Log::error('promotion_sync_failed', ['account_id' => $row->id, 'exception' => $e]); } }, 'p.id', 'id'); foreach (DB::table('promotion_rewards')->where('status', 'locked')->distinct()->pluck('user_id') as $userId) { try { $service->unlock((int)$userId); } catch (\Throwable $e) { ++$errors; Log::error('promotion_unlock_failed', ['user_id' => $userId, 'exception' => $e]); } } $this->info('活动任务和奖金同步完成,失败数:' . $errors); return $errors ? self::FAILURE : self::SUCCESS; } }