setName('xdata:UserAmount'); $this->setDescription('批量重新计算余额返利'); } /** * @param Input $input * @param Output $output * @return void * @throws Exception */ protected function execute(Input $input, Output $output) { [$total, $count, $error] = [DataUser::mk()->count(), 0, 0]; foreach (DataUser::mk()->field('id')->cursor() as $user) try { $this->queue->message($total, ++$count, "刷新用户 [{$user['id']}] 余额及返利开始"); UserRebateService::amount($user['id']) && UserBalanceService::amount($user['id']); $this->queue->message($total, $count, "刷新用户 [{$user['id']}] 余额及返利完成", 1); } catch (\Exception $exception) { $error++; $this->queue->message($total, $count, "刷新用户 [{$user['id']}] 余额及返利失败, {$exception->getMessage()}", 1); } $this->setQueueSuccess("此次共处理 {$total} 个刷新操作, 其中有 {$error} 个刷新失败。"); } }