setName('fc:settle') ->setDescription('分销佣金到期结算 / 关闭超时订单 / 同步转账状态'); } protected function execute(Input $input, Output $output) { $now = time(); /* 1. 佣金到期结算 */ $settled = Db::name('fc_commission') ->where('status', 0) ->where('settle_due', '<=', $now) ->update([ 'status' => 1, 'settletime' => $now, ]); $output->writeln('==> 佣金结算:' . $settled . ' 笔'); /* 2. 关闭超时未支付订单(统一走 OrderClose 规范化清理) */ $timeout = OrderClose::getTimeoutSeconds(); $expired = Db::name('fc_order') ->where('status', 'pending') ->where('createtime', '<', $now - $timeout) ->select(); $closed = 0; foreach ($expired as $order) { if (OrderClose::close($order, 'timeout_auto')) { $closed++; } } $output->writeln('==> 关闭超时订单:' . $closed . ' 笔(超时阈值:' . round($timeout / 60) . ' 分钟)'); /* 3. 同步转账中的提现单(最多 20 笔) */ $synced = 0; if (class_exists('\app\common\library\WxTransfer') && \app\common\library\WxTransfer::isReady()) { $rows = Db::name('fc_withdraw')->where('status', 'paying')->limit(20)->select(); foreach ($rows as $row) { try { \app\common\library\WxTransfer::sync((int)$row['id']); $synced++; } catch (\Throwable $e) { // 单笔失败不影响其它 } } } $output->writeln('==> 同步转账状态:' . $synced . ' 笔'); $output->writeln('==> 完成'); } }