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.
This commit is contained in:
@@ -32,3 +32,23 @@ CREATE TABLE IF NOT EXISTS `users` (
|
||||
KEY `idx_users_deleted_at` (`deleted_at`),
|
||||
CONSTRAINT `fk_users_mini_program` FOREIGN KEY (`mini_program_id`) REFERENCES `mini_programs`(`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- 会员订阅(通用能力:可给多个功能做“会员优先/免广告”策略)
|
||||
-- 说明:
|
||||
-- - 会员判断:存在 `status='active' AND ends_at > NOW()` 的记录即可视为会员
|
||||
-- - 如果你不想引入该表,也可以选择在 users 表新增 `vip_expires_at` 字段(但扩展性较弱)
|
||||
CREATE TABLE IF NOT EXISTS `user_memberships` (
|
||||
`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,
|
||||
`plan` varchar(30) NOT NULL COMMENT '例如:month/year/lifetime',
|
||||
`status` varchar(20) NOT NULL COMMENT 'active/canceled/expired',
|
||||
`starts_at` datetime NOT NULL,
|
||||
`ends_at` datetime NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_membership_user` (`mini_program_id`,`user_id`,`ends_at`),
|
||||
KEY `idx_membership_status` (`mini_program_id`,`user_id`,`status`,`ends_at`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
Reference in New Issue
Block a user