Files
wx_service/docs/sql/membership.sql
T
nepiedg 16844d4a42 Enhance AI and Redis integration for smoke logging features
- Added AI configuration options to .env.example and config.go for OpenAI integration.
- Implemented Redis caching for session management in main.go and auth middleware.
- Updated smoke logging service to support real smoking time (`smoke_at`) and AI advice retrieval.
- Enhanced API routes to include endpoints for AI advice and unlock functionality for non-members.
- Improved database schema with new tables for AI advice and unlock records.
- Expanded documentation to cover new AI features and Redis caching implementation.
2026-01-03 02:14:21 +00:00

46 lines
1.8 KiB
SQL

-- 会员兑换码(用于无支付系统时的会员开通)
CREATE TABLE IF NOT EXISTS `membership_redeem_codes` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`code_hash` varchar(64) NOT NULL COMMENT 'sha256(code) hex;不存明文',
`code_suffix` varchar(16) DEFAULT NULL COMMENT '展示/审计用后缀',
`plan` varchar(30) NOT NULL DEFAULT 'default',
`duration_days` int NOT NULL,
`expires_at` datetime DEFAULT NULL,
`max_uses` int NOT NULL DEFAULT 1,
`used_uses` int NOT NULL DEFAULT 0,
`status` varchar(20) NOT NULL DEFAULT 'active' COMMENT 'active/disabled',
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_redeem_code_hash` (`code_hash`),
KEY `idx_redeem_code_suffix` (`code_suffix`),
KEY `idx_redeem_code_deleted` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `membership_redemptions` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`deleted_at` datetime DEFAULT NULL,
`mini_program_id` bigint unsigned NOT NULL,
`user_id` bigint unsigned NOT NULL,
`redeem_code_id` bigint unsigned NOT NULL,
`code_suffix` varchar(16) DEFAULT NULL,
`membership_id` bigint unsigned NOT NULL,
`client_ip` varchar(64) DEFAULT NULL,
`user_agent` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_redemption_user_date` (`mini_program_id`,`user_id`,`created_at`),
KEY `idx_redemption_code` (`redeem_code_id`),
KEY `idx_redemption_deleted` (`deleted_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;