ProcuremenRegenPdf.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\admin\command;
  3. use app\admin\controller\Procuremen;
  4. use app\common\library\ProcuremenStatus;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\Db;
  10. /**
  11. * 按订单号重生成已完结存证 PDF
  12. * 用法:php think procuremen:regen-pdf --ccydh=202605584L,202605694S
  13. */
  14. class ProcuremenRegenPdf extends Command
  15. {
  16. protected function configure()
  17. {
  18. $this->setName('procuremen:regen-pdf')
  19. ->addOption('ccydh', null, Option::VALUE_REQUIRED, '订单号,多个用英文逗号分隔')
  20. ->setDescription('Regenerate archive PDF for completed procuremen orders');
  21. }
  22. protected function execute(Input $input, Output $output)
  23. {
  24. $raw = trim((string)$input->getOption('ccydh'));
  25. if ($raw === '') {
  26. $output->writeln('<error>请传 --ccydh=订单号</error>');
  27. return;
  28. }
  29. $list = [];
  30. foreach (preg_split('/[,,\s]+/u', $raw) as $one) {
  31. $one = trim((string)$one);
  32. if ($one !== '') {
  33. $list[$one] = true;
  34. }
  35. }
  36. if ($list === []) {
  37. $output->writeln('<error>订单号无效</error>');
  38. return;
  39. }
  40. foreach (array_keys($list) as $ccydh) {
  41. try {
  42. $rows = Db::table('purchase_order')
  43. ->where('CCYDH', $ccydh)
  44. ->field('id,scydgy_id,CCYDH,status,pdf_url')
  45. ->select();
  46. } catch (\Throwable $e) {
  47. $output->writeln('<error>' . $ccydh . ' 查询失败:' . $e->getMessage() . '</error>');
  48. continue;
  49. }
  50. if (!is_array($rows) || $rows === []) {
  51. $output->writeln('<comment>' . $ccydh . ' 未找到 purchase_order</comment>');
  52. continue;
  53. }
  54. foreach ($rows as $po) {
  55. if (!is_array($po)) {
  56. continue;
  57. }
  58. $sid = (int)($po['scydgy_id'] ?? 0);
  59. $status = (string)($po['status'] ?? '');
  60. $completed = ProcuremenStatus::isPoCompleted($status);
  61. $output->writeln(sprintf(
  62. '处理 %s scydgy_id=%d status=%s completed=%s',
  63. $ccydh,
  64. $sid,
  65. $status !== '' ? $status : '(空)',
  66. $completed ? 'yes' : 'no'
  67. ));
  68. // 强制按当前详情重存(含操作记录),不强制要求已完结标记
  69. $path = Procuremen::regenerateArchivePdfWithoutAuth($sid, false);
  70. if ($path === '') {
  71. $output->writeln('<error> PDF 生成失败 scydgy_id=' . $sid . '</error>');
  72. } else {
  73. $output->writeln('<info> PDF 已更新:' . $path . '</info>');
  74. }
  75. }
  76. }
  77. $output->writeln('<info>完成</info>');
  78. }
  79. }