setName('xadmin:fanspay'); $this->setDescription('Wechat Users Payment auto clear for ThinkAdmin'); } /** * 执行支付单清理任务 * @throws Exception * @throws DbException */ protected function execute(Input $input, Output $output) { $query = WechatPaymentRecord::mq(); $query->where(['payment_status' => 0]); $query->whereTime('create_time', '<', strtotime('-24 hours')); [$total, $count] = [(clone $query)->count(), 0]; if (empty($total)) { $this->setQueueSuccess('无需清理24小时未支付!'); } /** @var Model $item */ foreach ($query->cursor() as $item) { $this->setQueueMessage($total, ++$count, sprintf('开始清理 %s 支付单...', $item->getAttr('code'))); $item->delete(); $this->setQueueMessage($total, $count, sprintf('完成清理 %s 支付单!', $item->getAttr('code')), 1); } } }