setName('xdata:UserUpgrade'); $this->setDescription('批量重新计算用户等级'); } /** * @param Input $input * @param Output $output * @return void * @throws Exception */ protected function execute(Input $input, Output $output) { try { [$total, $count] = [DataUser::mk()->count(), 0]; foreach (DataUser::mk()->field('id')->cursor() as $user) { $this->queue->message($total, ++$count, "正在计算用户 [{$user['id']}] 的等级"); UserUpgradeService::upgrade($user['id']); $this->queue->message($total, $count, "完成计算用户 [{$user['id']}] 的等级", 1); } $this->setQueueSuccess("此次共重新计算 {$total} 个用户等级。"); } catch (Exception $exception) { throw $exception; } catch (\Exception $exception) { $this->setQueueError($exception->getMessage()); } } }