psqr.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * 流程单二维码落地页:微信扫描打开,展示工单信息。
  4. * 访问:/psqr.php?d=...
  5. */
  6. header('Content-Type: text/html; charset=utf-8');
  7. $data = [];
  8. $k = isset($_GET['k']) ? preg_replace('/[^a-fA-F0-9]/', '', (string)$_GET['k']) : '';
  9. if ($k !== '') {
  10. $files = [
  11. dirname(__DIR__) . '/runtime/psqr/' . $k . '.json',
  12. __DIR__ . '/uploads/psqr/' . $k . '.json',
  13. ];
  14. foreach ($files as $file) {
  15. if (is_file($file)) {
  16. $tmp = json_decode((string)file_get_contents($file), true);
  17. if (is_array($tmp)) {
  18. $data = $tmp;
  19. break;
  20. }
  21. }
  22. }
  23. }
  24. $raw = isset($_GET['d']) ? (string)$_GET['d'] : '';
  25. if (!$data && $raw !== '') {
  26. $pad = strtr($raw, '-_', '+/');
  27. $mod = strlen($pad) % 4;
  28. if ($mod) {
  29. $pad .= str_repeat('=', 4 - $mod);
  30. }
  31. $json = base64_decode($pad, true);
  32. $tmp = $json !== false ? json_decode($json, true) : null;
  33. if (is_array($tmp)) {
  34. $data = $tmp;
  35. }
  36. }
  37. $h = function ($key) use ($data) {
  38. $v = isset($data[$key]) ? (string)$data[$key] : '';
  39. if (function_exists('mb_substr')) {
  40. $v = mb_substr($v, 0, 80, 'UTF-8');
  41. }
  42. return htmlspecialchars($v, ENT_QUOTES, 'UTF-8');
  43. };
  44. $no = $h('no');
  45. $name = $h('name');
  46. $qty = $h('qty');
  47. $plate = $h('plate');
  48. $total = $h('total');
  49. $cur = $h('cur');
  50. $title = $no !== '' ? $no : '流程单';
  51. ?>
  52. <!DOCTYPE html>
  53. <html lang="zh-CN">
  54. <head>
  55. <meta charset="utf-8">
  56. <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
  57. <meta name="format-detection" content="telephone=no">
  58. <title><?php echo $title; ?> · 流程单</title>
  59. <style>
  60. * { box-sizing: border-box; }
  61. body {
  62. margin: 0;
  63. background: #e8eee4;
  64. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  65. color: #1a2a1a;
  66. }
  67. .card {
  68. max-width: 420px;
  69. margin: 24px auto;
  70. background: #fff;
  71. border: 4px solid #2f7a3a;
  72. border-radius: 8px;
  73. overflow: hidden;
  74. box-shadow: 0 8px 24px rgba(20, 60, 30, 0.12);
  75. }
  76. .hd {
  77. background: #2f7a3a;
  78. color: #fff;
  79. padding: 16px 18px 14px;
  80. }
  81. .hd h1 { margin: 0; font-size: 18px; font-weight: 700; }
  82. .hd p { margin: 6px 0 0; font-size: 13px; opacity: .9; }
  83. dl { margin: 0; padding: 8px 0 16px; }
  84. dt {
  85. padding: 10px 18px 0;
  86. font-size: 12px;
  87. color: #6a7a6a;
  88. }
  89. dd {
  90. margin: 0;
  91. padding: 4px 18px 10px;
  92. font-size: 17px;
  93. font-weight: 600;
  94. line-height: 1.45;
  95. border-bottom: 1px solid #eef3ee;
  96. word-break: break-all;
  97. }
  98. dd:last-child { border-bottom: 0; }
  99. .empty { padding: 40px 20px; text-align: center; color: #888; }
  100. </style>
  101. </head>
  102. <body>
  103. <div class="card">
  104. <div class="hd">
  105. <h1>产品工序流程卡</h1>
  106. <p>扫码查看本张流程单信息</p>
  107. </div>
  108. <?php if ($no === '' && $name === '') { ?>
  109. <div class="empty">二维码内容无效</div>
  110. <?php } else { ?>
  111. <dl>
  112. <dt>工单编号</dt><dd><?php echo $no !== '' ? $no : '—'; ?></dd>
  113. <dt>名称</dt><dd><?php echo $name !== '' ? $name : '—'; ?></dd>
  114. <dt>总数量</dt><dd><?php echo $qty !== '' ? $qty : '—'; ?></dd>
  115. <dt>每版</dt><dd><?php echo $plate !== '' ? $plate : '—'; ?></dd>
  116. <dt>总流程</dt><dd><?php echo $total !== '' ? $total : '—'; ?></dd>
  117. <dt>当前流程号</dt><dd><?php echo $cur !== '' ? $cur : '—'; ?></dd>
  118. </dl>
  119. <?php } ?>
  120. </div>
  121. </body>
  122. </html>