feat(old-items): complete reuse workflow and refine miniapp home

This commit is contained in:
2026-08-15 16:38:30 +08:00
parent 65d23eab4a
commit f3737c80be
94 changed files with 7880 additions and 215 deletions
@@ -0,0 +1,113 @@
CREATE TABLE `old_item_reward_configs` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`public_id` CHAR(36) NOT NULL,
`client_request_id` CHAR(36) NOT NULL,
`request_fingerprint` CHAR(64) NOT NULL,
`version` INTEGER UNSIGNED NOT NULL,
`active_key` VARCHAR(16) NULL,
`certificate_title` VARCHAR(120) NOT NULL,
`certificate_message` VARCHAR(1000) NOT NULL,
`issuer_name` VARCHAR(120) NOT NULL,
`legal_notice` VARCHAR(500) NOT NULL,
`clothing_points` INTEGER UNSIGNED NOT NULL,
`books_points` INTEGER UNSIGNED NOT NULL,
`household_points` INTEGER UNSIGNED NOT NULL,
`sports_points` INTEGER UNSIGNED NOT NULL,
`max_points_per_donation` INTEGER UNSIGNED NOT NULL,
`created_by` BIGINT UNSIGNED NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `old_item_reward_configs_public_id_key` (`public_id`),
UNIQUE INDEX `old_item_reward_configs_client_request_id_key` (`client_request_id`),
UNIQUE INDEX `old_item_reward_configs_version_key` (`version`),
UNIQUE INDEX `old_item_reward_configs_active_key_key` (`active_key`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE TABLE `old_item_certificates` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`public_id` CHAR(36) NOT NULL,
`certificate_no` VARCHAR(40) NOT NULL,
`donation_id` BIGINT UNSIGNED NOT NULL,
`config_id` BIGINT UNSIGNED NULL,
`issue_request_id` CHAR(36) NOT NULL,
`issue_fingerprint` CHAR(64) NOT NULL,
`active_key` VARCHAR(16) NULL,
`status` ENUM('ISSUED','REVOKED') NOT NULL DEFAULT 'ISSUED',
`recipient_name_encrypted` VARCHAR(512) NOT NULL,
`title_snapshot` VARCHAR(120) NOT NULL,
`message_snapshot` VARCHAR(1000) NOT NULL,
`issuer_snapshot` VARCHAR(120) NOT NULL,
`legal_notice_snapshot` VARCHAR(500) NOT NULL,
`issued_by` BIGINT UNSIGNED NOT NULL,
`issued_at` DATETIME(3) NOT NULL,
`revoked_by` BIGINT UNSIGNED NULL,
`revoked_request_id` CHAR(36) NULL,
`revoked_fingerprint` CHAR(64) NULL,
`revoke_reason_encrypted` TEXT NULL,
`revoked_at` DATETIME(3) NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `old_item_certificates_public_id_key` (`public_id`),
UNIQUE INDEX `old_item_certificates_certificate_no_key` (`certificate_no`),
UNIQUE INDEX `old_item_certificates_issue_request_id_key` (`issue_request_id`),
UNIQUE INDEX `old_item_certificates_revoked_request_id_key` (`revoked_request_id`),
UNIQUE INDEX `old_item_certificates_donation_active_key` (`donation_id`, `active_key`),
INDEX `old_item_certificates_donation_issued_idx` (`donation_id`, `issued_at`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE TABLE `old_item_point_accounts` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`public_id` CHAR(36) NOT NULL,
`user_id` BIGINT UNSIGNED NOT NULL,
`balance` INTEGER UNSIGNED NOT NULL DEFAULT 0,
`revision` INTEGER UNSIGNED NOT NULL DEFAULT 1,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updated_at` DATETIME(3) NOT NULL,
UNIQUE INDEX `old_item_point_accounts_public_id_key` (`public_id`),
UNIQUE INDEX `old_item_point_accounts_user_id_key` (`user_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE TABLE `old_item_point_entries` (
`id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
`public_id` CHAR(36) NOT NULL,
`account_id` BIGINT UNSIGNED NOT NULL,
`user_id` BIGINT UNSIGNED NOT NULL,
`donation_id` BIGINT UNSIGNED NULL,
`config_id` BIGINT UNSIGNED NULL,
`request_id` CHAR(36) NOT NULL,
`request_fingerprint` CHAR(64) NOT NULL,
`source_key` VARCHAR(100) NOT NULL,
`entry_type` ENUM('EARNED','ADJUSTMENT') NOT NULL,
`points_delta` INTEGER NOT NULL,
`balance_after` INTEGER UNSIGNED NOT NULL,
`note_encrypted` TEXT NULL,
`operator_user_id` BIGINT UNSIGNED NOT NULL,
`created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `old_item_point_entries_public_id_key` (`public_id`),
UNIQUE INDEX `old_item_point_entries_request_id_key` (`request_id`),
UNIQUE INDEX `old_item_point_entries_source_key_key` (`source_key`),
INDEX `old_item_point_entries_user_created_idx` (`user_id`, `created_at`),
INDEX `old_item_point_entries_donation_idx` (`donation_id`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE `old_item_reward_configs` ADD CONSTRAINT `old_item_reward_configs_created_by_fkey` FOREIGN KEY (`created_by`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_certificates` ADD CONSTRAINT `old_item_certificates_donation_fkey` FOREIGN KEY (`donation_id`) REFERENCES `old_item_donations`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_certificates` ADD CONSTRAINT `old_item_certificates_config_fkey` FOREIGN KEY (`config_id`) REFERENCES `old_item_reward_configs`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_certificates` ADD CONSTRAINT `old_item_certificates_issued_by_fkey` FOREIGN KEY (`issued_by`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_certificates` ADD CONSTRAINT `old_item_certificates_revoked_by_fkey` FOREIGN KEY (`revoked_by`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_accounts` ADD CONSTRAINT `old_item_point_accounts_user_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_entries` ADD CONSTRAINT `old_item_point_entries_account_fkey` FOREIGN KEY (`account_id`) REFERENCES `old_item_point_accounts`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_entries` ADD CONSTRAINT `old_item_point_entries_user_fkey` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_entries` ADD CONSTRAINT `old_item_point_entries_donation_fkey` FOREIGN KEY (`donation_id`) REFERENCES `old_item_donations`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_entries` ADD CONSTRAINT `old_item_point_entries_config_fkey` FOREIGN KEY (`config_id`) REFERENCES `old_item_reward_configs`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
ALTER TABLE `old_item_point_entries` ADD CONSTRAINT `old_item_point_entries_operator_fkey` FOREIGN KEY (`operator_user_id`) REFERENCES `users`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE;
INSERT INTO `permissions` (`code`, `name`, `description`) VALUES
('old_item_rewards:read', '查看旧物证书积分', '查看旧物善用证书、积分账户和规则'),
('old_item_rewards:manage', '管理旧物证书积分', '配置规则、补发撤销证书和调整公益积分');
INSERT INTO `role_permissions` (`role_id`, `permission_id`)
SELECT r.id, p.id FROM `roles` r CROSS JOIN `permissions` p
WHERE r.code IN ('ADMIN','SUPER_ADMIN') AND p.code IN ('old_item_rewards:read','old_item_rewards:manage');