补充通知信息
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 8m11s

This commit is contained in:
2026-07-28 16:14:20 +08:00
parent 4b98612816
commit 1e4f998fe7
8 changed files with 87 additions and 21 deletions

View File

@@ -61,9 +61,9 @@ func NewRegistry() *Registry {
constants.NotificationTypePackageExpiring: {
Type: constants.NotificationTypePackageExpiring, Category: constants.NotificationCategoryExpiry,
Severity: constants.NotificationSeverityWarning,
TitleTemplate: "套餐即将到期",
BodyTemplate: "您的套餐即将到期,请及时查看并处理。",
TemplateFields: map[string]struct{}{},
TitleTemplate: "套餐{{.expiry_status}}",
BodyTemplate: "资产 {{.asset_identifier}} 的套餐{{.expiry_status}},到期日期:{{.expiry_date}}。",
TemplateFields: map[string]struct{}{"asset_identifier": {}, "expiry_status": {}, "expiry_date": {}},
RecipientKinds: map[string]struct{}{
constants.NotificationRecipientKindAccount: {},
constants.NotificationRecipientKindPersonalCustomer: {},
@@ -78,8 +78,8 @@ func NewRegistry() *Registry {
Type: constants.NotificationTypeAgentRechargeCompleted, Category: constants.NotificationCategorySystem,
Severity: constants.NotificationSeverityInfo,
TitleTemplate: "店铺充值已入账",
BodyTemplate: "店铺充值已成功入账,请进入充值详情查看。",
TemplateFields: map[string]struct{}{},
BodyTemplate: "店铺「{{.shop_name}}」充值 {{.amount}} 已成功入账。",
TemplateFields: map[string]struct{}{"shop_name": {}, "amount": {}},
RecipientKinds: map[string]struct{}{constants.NotificationRecipientKindAccount: {}},
AllowedRefTypes: map[string]struct{}{
constants.NotificationRefTypeAgentRecharge: {},

View File

@@ -82,7 +82,7 @@ func (p *ReminderPublisher) appendShopNotification(ctx context.Context, tx *gorm
ResourceType: candidate.AssetType, ResourceID: assetID, BusinessKey: eventID,
Payload: notificationapp.AdminDynamicPayload{
TargetKind: constants.NotificationTargetKindShop, TargetID: shopID,
NotificationType: constants.NotificationTypePackageExpiring, TemplateData: map[string]string{},
NotificationType: constants.NotificationTypePackageExpiring, TemplateData: expiryTemplateData(candidate),
RefType: constants.NotificationRefTypeExpiringAsset, RefID: shopIDText,
ExpiresAt: candidate.EstimatedFinalExpiresAt,
},
@@ -160,7 +160,7 @@ func (p *ReminderPublisher) appendNotification(ctx context.Context, tx *gorm.DB,
ResourceType: candidate.AssetType, ResourceID: assetID, BusinessKey: eventID,
Payload: notificationapp.PersonalCustomerDirectPayload{
RecipientID: customerID, NotificationType: constants.NotificationTypePackageExpiring,
TemplateData: map[string]string{}, RefType: constants.NotificationRefTypeAsset,
TemplateData: expiryTemplateData(candidate), RefType: constants.NotificationRefTypeAsset,
RefID: assetID, RefKey: candidate.Identifier, ExpiresAt: candidate.EstimatedFinalExpiresAt,
},
})
@@ -170,6 +170,28 @@ func (p *ReminderPublisher) appendNotification(ctx context.Context, tx *gorm.DB,
return nil
}
// expiryTemplateData 为后台和个人客户生成同口径的资产到期文案数据。
func expiryTemplateData(candidate dto.ExpiringAssetItem) map[string]string {
status := "即将到期"
if candidate.DaysUntilFinalExpiry != nil {
switch {
case *candidate.DaysUntilFinalExpiry < 0:
status = "已到期"
case *candidate.DaysUntilFinalExpiry == 0:
status = "今天到期"
}
}
expiryDate := ""
if candidate.EstimatedFinalExpiresAt != nil {
expiryDate = candidate.EstimatedFinalExpiresAt.In(shanghaiLocation).Format("2006-01-02")
}
return map[string]string{
"asset_identifier": candidate.Identifier,
"expiry_status": status,
"expiry_date": expiryDate,
}
}
func recipientKey(assetType string, assetID uint) string {
return fmt.Sprintf("%s:%d", assetType, assetID)
}

View File

@@ -2,11 +2,13 @@ package wallet
import (
"context"
"fmt"
"strconv"
notificationapp "github.com/break/junhong_cmp_fiber/internal/application/notification"
walletapp "github.com/break/junhong_cmp_fiber/internal/application/wallet"
"github.com/break/junhong_cmp_fiber/internal/infrastructure/messaging/outbox"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
"gorm.io/gorm"
@@ -38,6 +40,10 @@ func (w *CreditEventWriter) Append(ctx context.Context, tx *gorm.DB, event walle
return err
}
rechargeID := strconv.FormatUint(uint64(event.ReferenceID), 10)
var shop model.Shop
if err := tx.WithContext(ctx).Select("shop_name").Where("id = ?", event.ShopID).Take(&shop).Error; err != nil {
return errors.Wrap(errors.CodeDatabaseError, err, "查询充值通知店铺失败")
}
notificationEventID := "agent-recharge:" + rechargeID + ":completed"
_, err = w.outbox.AppendIdempotent(ctx, tx, outbox.Envelope{
EventID: notificationEventID, EventType: constants.OutboxEventTypeAdminDynamicNotification,
@@ -47,7 +53,11 @@ func (w *CreditEventWriter) Append(ctx context.Context, tx *gorm.DB, event walle
BusinessKey: notificationEventID, RequestID: event.RequestID, CorrelationID: event.CorrelationID,
Payload: notificationapp.AdminDynamicPayload{
TargetKind: constants.NotificationTargetKindShop, TargetID: event.ShopID,
NotificationType: constants.NotificationTypeAgentRechargeCompleted, TemplateData: map[string]string{},
NotificationType: constants.NotificationTypeAgentRechargeCompleted,
TemplateData: map[string]string{
"shop_name": shop.ShopName,
"amount": fmt.Sprintf("%d.%02d 元", event.Amount/100, event.Amount%100),
},
RefType: constants.NotificationRefTypeAgentRecharge, RefID: rechargeID,
},
})