| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- namespace app\admin\command;
- use app\admin\controller\Procuremen;
- use app\common\library\ProcuremenStatus;
- use think\console\Command;
- use think\console\Input;
- use think\console\input\Option;
- use think\console\Output;
- use think\Db;
- /**
- * 按订单号重生成已完结存证 PDF
- * 用法:php think procuremen:regen-pdf --ccydh=202605584L,202605694S
- */
- class ProcuremenRegenPdf extends Command
- {
- protected function configure()
- {
- $this->setName('procuremen:regen-pdf')
- ->addOption('ccydh', null, Option::VALUE_REQUIRED, '订单号,多个用英文逗号分隔')
- ->setDescription('Regenerate archive PDF for completed procuremen orders');
- }
- protected function execute(Input $input, Output $output)
- {
- $raw = trim((string)$input->getOption('ccydh'));
- if ($raw === '') {
- $output->writeln('<error>请传 --ccydh=订单号</error>');
- return;
- }
- $list = [];
- foreach (preg_split('/[,,\s]+/u', $raw) as $one) {
- $one = trim((string)$one);
- if ($one !== '') {
- $list[$one] = true;
- }
- }
- if ($list === []) {
- $output->writeln('<error>订单号无效</error>');
- return;
- }
- foreach (array_keys($list) as $ccydh) {
- try {
- $rows = Db::table('purchase_order')
- ->where('CCYDH', $ccydh)
- ->field('id,scydgy_id,CCYDH,status,pdf_url')
- ->select();
- } catch (\Throwable $e) {
- $output->writeln('<error>' . $ccydh . ' 查询失败:' . $e->getMessage() . '</error>');
- continue;
- }
- if (!is_array($rows) || $rows === []) {
- $output->writeln('<comment>' . $ccydh . ' 未找到 purchase_order</comment>');
- continue;
- }
- foreach ($rows as $po) {
- if (!is_array($po)) {
- continue;
- }
- $sid = (int)($po['scydgy_id'] ?? 0);
- $status = (string)($po['status'] ?? '');
- $completed = ProcuremenStatus::isPoCompleted($status);
- $output->writeln(sprintf(
- '处理 %s scydgy_id=%d status=%s completed=%s',
- $ccydh,
- $sid,
- $status !== '' ? $status : '(空)',
- $completed ? 'yes' : 'no'
- ));
- // 强制按当前详情重存(含操作记录),不强制要求已完结标记
- $path = Procuremen::regenerateArchivePdfWithoutAuth($sid, false);
- if ($path === '') {
- $output->writeln('<error> PDF 生成失败 scydgy_id=' . $sid . '</error>');
- } else {
- $output->writeln('<info> PDF 已更新:' . $path . '</info>');
- }
- }
- }
- $output->writeln('<info>完成</info>');
- }
- }
|