feat(tickets): ticket settings, ticket types and order tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-04 15:23:16 +08:00
1 parent 896ee3bcc5
commit b8a1873266
23 files changed
+1171 -6

No files matched your search

@@ -100,7 +100,8 @@ Staff "mark paid" on an Expired order, and a type's quantity edit, take the same
All take JSON. `companyId` is always concrete and is set by mobile-api.
- **Settings:**
- `POST /counter/event/save` accepts `ticketsEnabled`, `paymentInstructions` and `holdDays`. It returns 400 on the field when switching on with blank instructions or when hold days are outside 1 to 14. mobile-api passes these only for callers with `BO_EVENT_TICKETS`.
- `POST /counter/ticketType/settings {companyId, eventUuid, ticketsEnabled, paymentInstructions, holdDays, doneBy}`. It returns 400 `PAYMENT_INSTRUCTIONS_REQUIRED`, `PAYMENT_INSTRUCTIONS_TOO_LONG` or `HOLD_DAYS_INVALID`.
- `event/save` keeps the stored ticket settings on every edit, and starts a new event with tickets off. This is so a mobile-api event edit, which round-trips the whole event, can never reset them.
- **Ticket types:**
- `POST /counter/ticketType/list {companyId, eventUuid}` returns `[{id, name, priceSen, quantity, salesEndDate, sort, enabled, held, left}]`.
- `POST /counter/ticketType/save {companyId, eventUuid, id?, name, priceSen, quantity, salesEndDate, sort, enabled, doneBy}` returns 409 `QUANTITY_BELOW_HELD` or `NAME_TAKEN`.
@@ -191,7 +192,12 @@ All take JSON. `companyId` is always concrete and is set by mobile-api.
## Risks / Trade-offs
- **Event row lock under a rush.** Requests for one event are serialised. That is fine at the expected volume (tens per minute). If a big launch needs more, move to per-type locks.
- **Event row lock under a rush.** Requests for one event are serialised. That is fine at the expected volume (hundreds per minute). The upgrade path was agreed with the owner on 2026-12-04:
1. A conditional single-statement seat update (`... WHERE held + n <= quantity`), with no event lock.
2. Then a Redis seat counter backed by the database, a CDN-cached event page, a CAPTCHA and a load test.
3. At concert scale: a virtual waiting room, queued order allocation, member-only sales, and ticketing as its own service.
Seats are counted from `ticket` rows on one table, so step 1 is a local change.
- **Seat hoarding.** One email can hold up to 30 seats (3 orders × 10) for the hold days, and many emails can hold more. This is mitigated by the IP limit, the honeypot and staff cancel. A CAPTCHA is deferred.
- **Emails in English and BM only,** matching invites. The zh-CN email text is deferred with the rest of the email localisation.
- **Expired orders may still be paid.** Staff can rescue them only while their seats are free. This is refused clearly otherwise.
@@ -0,0 +1,99 @@
-- Co-Lite change add-event-ticket-orders: ticket settings, ticket types, orders and tickets (design decision 1).
-- Target: `service-counter`. Additive only. Run before the new images go live. Needs a user that may alter tables.
-- Money is integer sen. `shop_order` / `shop_order_line` stay apart from the legacy Tastefully `orders` tables.
USE `service-counter`;
ALTER TABLE `event`
ADD COLUMN `tickets_enabled` tinyint(1) NOT NULL DEFAULT 0,
ADD COLUMN `payment_instructions` varchar(1000) NULL,
ADD COLUMN `hold_days` int NOT NULL DEFAULT 3;
CREATE TABLE IF NOT EXISTS `ticket_type` (
`id` bigint NOT NULL AUTO_INCREMENT,
`company_id` bigint NOT NULL,
`event_uuid` bigint NOT NULL,
`name` varchar(80) NOT NULL,
`price_sen` int NOT NULL,
`quantity` int NOT NULL,
`sales_end_date` date NULL,
`sort` int NOT NULL DEFAULT 0,
`enabled` tinyint(1) NOT NULL DEFAULT 1,
`created_by` varchar(255) NULL,
`created_at` datetime NULL DEFAULT CURRENT_TIMESTAMP,
`updated_by` varchar(255) NULL,
`updated_at` datetime NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_ticket_type_name` (`event_uuid`, `name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `shop_order` (
`id` bigint NOT NULL AUTO_INCREMENT,
`company_id` bigint NOT NULL,
`event_uuid` bigint NULL COMMENT 'Null is reserved for a later standalone shop',
`reference` varchar(12) NOT NULL,
`token` varchar(32) NOT NULL,
`buyer_name` varchar(100) NOT NULL,
`buyer_email` varchar(254) NOT NULL,
`buyer_mobile_e164` varchar(20) NULL,
`buyer_company` varchar(150) NULL,
`lead_uuid` bigint NULL,
`event_lead_uuid` bigint NULL,
`status` varchar(20) NOT NULL COMMENT 'AWAITING, PAID, CANCELLED, EXPIRED',
`total_sen` int NOT NULL,
`hold_until` datetime NULL,
`paid_at` datetime NULL,
`paid_by` varchar(255) NULL,
`payment_ref` varchar(100) NULL,
`cancelled_at` datetime NULL,
`cancelled_by` varchar(255) NULL,
`expired_at` datetime NULL,
`consent_at` datetime NULL,
`consent_notice_id` bigint NULL,
`page_path` varchar(200) NULL,
`utm_source` varchar(100) NULL,
`utm_medium` varchar(100) NULL,
`utm_campaign` varchar(100) NULL,
`last_email` varchar(20) NULL COMMENT 'RECEIVED, PAID, EXPIRED, CANCELLED',
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_shop_order_reference` (`company_id`, `reference`),
UNIQUE KEY `uk_shop_order_token` (`token`),
KEY `idx_shop_order_event_status` (`event_uuid`, `status`),
KEY `idx_shop_order_hold` (`status`, `hold_until`),
KEY `idx_shop_order_buyer` (`event_uuid`, `buyer_email`, `status`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `shop_order_line` (
`id` bigint NOT NULL AUTO_INCREMENT,
`order_id` bigint NOT NULL,
`kind` varchar(10) NOT NULL COMMENT 'TICKET; PICKUP and SHIP reserved for merch',
`item_id` bigint NOT NULL COMMENT 'ticket_type.id for TICKET',
`name` varchar(80) NOT NULL,
`unit_price_sen` int NOT NULL,
`quantity` int NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_shop_order_line_order` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `ticket` (
`id` bigint NOT NULL AUTO_INCREMENT,
`company_id` bigint NOT NULL,
`event_uuid` bigint NOT NULL,
`order_id` bigint NOT NULL,
`order_line_id` bigint NOT NULL,
`ticket_type_id` bigint NOT NULL,
`code` varchar(32) NULL COMMENT 'QR code, issued by add-event-tickets',
`attendee_name` varchar(100) NULL,
`attendee_mobile_e164` varchar(20) NULL,
`attendee_email` varchar(254) NULL,
`event_lead_uuid` bigint NULL,
`status` varchar(10) NOT NULL DEFAULT 'ACTIVE' COMMENT 'ACTIVE, CANCELLED',
`cancelled_at` datetime NULL,
`cancelled_by` varchar(255) NULL,
`checked_in_at` datetime NULL,
`checked_in_by` varchar(255) NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_ticket_code` (`code`),
KEY `idx_ticket_type_status` (`ticket_type_id`, `status`),
KEY `idx_ticket_order` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@@ -0,0 +1,6 @@
-- Co-Lite change add-event-ticket-orders: permission-only module for ticket settings, ticket types and orders.
-- Target: `service-system`. No role gets it by default; a super admin grants it under Roles.
USE `service-system`;
INSERT INTO `module` (`id`, `name`, `desc`, `area`, `type`, `parent`, `url`, `icon_name`) VALUES
(41160000, 'BO_EVENT_TICKETS', 'Event tickets', 'BO', 'M', 40000000, NULL, NULL);
@@ -0,0 +1,11 @@
-- Co-Lite change add-event-ticket-orders: rollback. Drops every ticket order and ticket. Run only to remove the data too.
USE `service-counter`;
DROP TABLE IF EXISTS `ticket`;
DROP TABLE IF EXISTS `shop_order_line`;
DROP TABLE IF EXISTS `shop_order`;
DROP TABLE IF EXISTS `ticket_type`;
ALTER TABLE `event` DROP COLUMN `tickets_enabled`, DROP COLUMN `payment_instructions`, DROP COLUMN `hold_days`;
USE `service-system`;
DELETE FROM `modules_roles` WHERE `module_id` = 41160000;
DELETE FROM `module` WHERE `id` = 41160000;
@@ -6,7 +6,7 @@ Design: `design.md` (technical contracts) and `docs/superpowers/specs/2026-12-04
## 1. Data
- [ ] 1.1 Write the SQL:
- [x] 1.1 Write the SQL:
- `sql/01-event-ticket-orders.sql`: the event columns, `ticket_type`, `shop_order`, `shop_order_line` and `ticket`;
- `sql/02-event-tickets-module.sql`: `BO_EVENT_TICKETS`;
- `sql/99-rollback.sql`.
@@ -18,11 +18,11 @@ Design: `design.md` (technical contracts) and `docs/superpowers/specs/2026-12-04
## 2. services-counter
- [ ] 2.1 Ticket entities, settings and ticket types.
- [x] 2.1 Ticket entities, settings and ticket types.
- Depends on: 1.1
- Tests first:
- **Entities:** they map to the DDL.
- **Event save:**
- **Ticket settings** (own endpoint `ticketType/settings`; an event edit keeps the stored settings):
- switching on with blank instructions is refused on the field;
- hold days 0 or 15 are refused;
- a valid save persists.
@@ -48,7 +48,7 @@ Design: `design.md` (technical contracts) and `docs/superpowers/specs/2026-12-04
- **Capacity:**
- before the event days, guests plus walk-ins plus held tickets over capacity gives `EVENT_FULL` with `left`;
- on the event days it does not.
- **Concurrency:** two threads request the last seat; exactly one order is created (integration test on the real lock).
- **Concurrency:** the unit test proves the event lock is taken before seats are counted. The module has no test database, and adding H2 or Testcontainers would be a new dependency for one test. So the real lock and the JPQL are checked against the local MySQL stack in 5.1: the counter boots, which validates the queries, and two parallel requests race for the last seat.
- **Buyer lead:**
- a new buyer gets an event lead with source `TICKET` and the UTM values;
- a buyer already captured keeps the old source and gets a note naming the reference.