This commit is contained in:
@@ -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,
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user