council(fix): BackendArchitect - Fix regex bug in getExistingSpecBaseIds()

Bug: regex '^([A-Za-z]+)(\d+)排(\d)座$' with $m[3] misparsed seat labels
like "A排10座" → colNum=1 (wrong). Fixed to '^([A-Za-z]+)排(\d+)座$' with $m[2].

Also clarified spec_base_id_map docblock: frontend expects flat integer,
not nested object.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
refactor/vr-ticket-20260416
Council 2026-04-15 20:16:49 +08:00
parent f003606ee6
commit d411073885
1 changed files with 8 additions and 3 deletions

View File

@ -26,7 +26,10 @@ class SeatSkuService extends BaseService
*
* @param int $goodsId 商品ID
* @param int $seatTemplateId 座位模板ID
* @return array ['code' => 0, 'msg' => '...', 'data' => ['total' => N, 'batch' => N, 'spec_base_id_map' => [...]]]
* @return array ['code' => 0, 'msg' => '...', 'data' => ['total' => N, 'generated' => N, 'spec_base_id_map' => ['seatId' => spec_base_id, ...]]]
*
* spec_base_id_map 格式:前端 ticket_detail.html 使用 seatKey "A_1")作为 key
* 期望 value 为整数 spec_base_id 2001)。
*/
public static function BatchGenerate(int $goodsId, int $seatTemplateId): array
{
@ -378,9 +381,11 @@ class SeatSkuService extends BaseService
foreach ($rows as $seatLabel => $baseId) {
// 从 seat_label 解析 seatId如 "A排1座" → "A_1"
// 格式: "{rowLabel}排{colNum}座"
if (preg_match('/^([A-Za-z]+)(\d+)排(\d)座$/', $seatLabel, $m)) {
// Bug fix: 原正则 `^([A-Za-z]+)(\d+)排(\d)座$` 第二个 `\d+` 会吞掉 colNum 的高位数字,
// 例如 "A排10座" 匹配为 rowLabel="A" colNum=1错误应为 colNum=10
if (preg_match('/^([A-Za-z]+)排(\d+)座$/', $seatLabel, $m)) {
$rowLabel = $m[1];
$colNum = intval($m[3]);
$colNum = intval($m[2]);
$seatId = $rowLabel . '_' . $colNum;
$seatIdMap[$seatId] = intval($baseId);
}