feat: 为订单表添加 IAP 相关字段并调整 IAP 对账逻辑参数。
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 7m34s

This commit is contained in:
shanshanzhong 2026-03-10 21:12:39 -07:00
parent 7c2eddf9c3
commit 4095552252
3 changed files with 14 additions and 6 deletions

View File

@ -1,5 +1,13 @@
-- Add subscription_user_id column to order table
ALTER TABLE `order` ADD COLUMN `subscription_user_id` bigint NOT NULL DEFAULT 0 COMMENT 'Target user ID for subscription (0=same as UserId)' AFTER `user_id`;
-- Add subscription_user_id column to order table (idempotent)
SET @col_exists = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'order' AND COLUMN_NAME = 'subscription_user_id');
SET @sql = IF(@col_exists = 0, 'ALTER TABLE `order` ADD COLUMN `subscription_user_id` bigint NOT NULL DEFAULT 0 COMMENT ''Target user ID for subscription (0=same as UserId)'' AFTER `user_id`', 'SELECT 1');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- Add app_account_token column to order table for Apple IAP
ALTER TABLE `order` ADD COLUMN `app_account_token` varchar(36) DEFAULT NULL COMMENT 'Apple IAP App Account Token (UUID)' AFTER `subscribe_token`;
-- Add app_account_token column to order table for Apple IAP (idempotent)
SET @col_exists2 = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'order' AND COLUMN_NAME = 'app_account_token');
SET @sql2 = IF(@col_exists2 = 0, 'ALTER TABLE `order` ADD COLUMN `app_account_token` varchar(36) DEFAULT NULL COMMENT ''Apple IAP App Account Token (UUID)'' AFTER `subscribe_token`', 'SELECT 1');
PREPARE stmt2 FROM @sql2;
EXECUTE stmt2;
DEALLOCATE PREPARE stmt2;

View File

@ -23,5 +23,5 @@ func (l *DailyReconcileLogic) ProcessTask(ctx context.Context, _ *asynq.Task) er
logger.Infof("[IAPDailyReconcile] start at %s", time.Now().Format("2006-01-02 15:04:05"))
// 第三层:扫描 1min ~ 48htrade_no 非空trade_no 为空说明客户端从未上传过 token服务端无法主动补单
// 实际上与第二层的区别是时间窗口:覆盖全天的遗漏
return l.inner.reconcile(ctx, 1*time.Minute, 48*time.Hour, true)
return l.inner.reconcile(ctx, 1*time.Minute, 48*time.Hour, false)
}

View File

@ -27,7 +27,7 @@ func NewReconcileLogic(svc *svc.ServiceContext) *ReconcileLogic {
func (l *ReconcileLogic) ProcessTask(ctx context.Context, _ *asynq.Task) error {
logger.Infof("[IAPReconcile] start at %s", time.Now().Format("2006-01-02 15:04:05"))
return l.reconcile(ctx, 5*time.Minute, 48*time.Hour, true)
return l.reconcile(ctx, 5*time.Minute, 48*time.Hour, false)
}
// reconcile 核心对账逻辑,被第二层和第三层共享