fix: 第1批 M9 套餐临期提醒按资产、扫码进入时触发
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 10m17s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 10m17s
- 每日扫描不再给个人客户写临期通知,店铺通知不变 - H5 资产信息在当前资产剩余 0~15 天且当天首次进入时返回 expiry_reminder,并为该客户、该资产写一条临期通知(Redis 去重,失败不占键) - 个人通知列表、未读数、全部已读中临期提醒只处理当前资产(按 ref_key) - OpenSpec Change scope-expiry-reminder-to-current-asset:6/9,临期 fixture 端到端验证与每日扫描验证待测试部署后完成
This commit is contained in:
@@ -84,13 +84,15 @@ func (q *Query) List(ctx context.Context, recipientID uint, request dto.Notifica
|
||||
}, nil
|
||||
}
|
||||
|
||||
// PersonalUnreadCount 查询当前个人客户可见业务通知的准确未读数。
|
||||
func (q *Query) PersonalUnreadCount(ctx context.Context, customerID uint) (*dto.NotificationUnreadCountResponse, error) {
|
||||
// PersonalUnreadCount 查询当前个人客户可见业务通知的准确未读数;套餐临期提醒只计当前资产的。
|
||||
func (q *Query) PersonalUnreadCount(ctx context.Context, customerID uint, currentAssetKey string) (*dto.NotificationUnreadCountResponse, error) {
|
||||
if customerID == 0 {
|
||||
return nil, errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
var count int64
|
||||
err := personalNotificationScope(q.db.WithContext(ctx).Model(&model.Notification{}), customerID, q.now().UTC()).
|
||||
Where(constants.NotificationPersonalExpiringAssetCondition,
|
||||
constants.NotificationTypePackageExpiring, constants.NotificationRefTypeAsset, currentAssetKey).
|
||||
Where("is_read = ?", false).
|
||||
Count(&count).Error
|
||||
if err != nil {
|
||||
@@ -99,8 +101,8 @@ func (q *Query) PersonalUnreadCount(ctx context.Context, customerID uint) (*dto.
|
||||
return newUnreadCountResponse(count), nil
|
||||
}
|
||||
|
||||
// PersonalList 查询当前个人客户可见的未过期业务通知简化列表。
|
||||
func (q *Query) PersonalList(ctx context.Context, customerID uint, request dto.PersonalNotificationListRequest) (*dto.PersonalNotificationListResponse, error) {
|
||||
// PersonalList 查询当前个人客户可见的未过期业务通知简化列表;套餐临期提醒只含当前资产的。
|
||||
func (q *Query) PersonalList(ctx context.Context, customerID uint, currentAssetKey string, request dto.PersonalNotificationListRequest) (*dto.PersonalNotificationListResponse, error) {
|
||||
if customerID == 0 {
|
||||
return nil, errors.New(errors.CodeInvalidParam)
|
||||
}
|
||||
@@ -108,7 +110,9 @@ func (q *Query) PersonalList(ctx context.Context, customerID uint, request dto.P
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base := personalNotificationScope(q.db.WithContext(ctx).Model(&model.Notification{}), customerID, q.now().UTC())
|
||||
base := personalNotificationScope(q.db.WithContext(ctx).Model(&model.Notification{}), customerID, q.now().UTC()).
|
||||
Where(constants.NotificationPersonalExpiringAssetCondition,
|
||||
constants.NotificationTypePackageExpiring, constants.NotificationRefTypeAsset, currentAssetKey)
|
||||
if request.IsRead != nil {
|
||||
base = base.Where("is_read = ?", *request.IsRead)
|
||||
}
|
||||
@@ -238,3 +242,35 @@ func popupSnapshotItem(record model.Notification) *dto.NotificationPopupSnapshot
|
||||
ActionType: record.PopupSnapshot.ActionType,
|
||||
}
|
||||
}
|
||||
|
||||
// CurrentAssetRefKey 返回个人客户令牌当前资产的通知引用标识:卡为 ICCID;设备优先虚拟号,为空则 IMEI。
|
||||
// 资产不存在或类型未知时返回空串,此时个人通知中心不展示任何套餐临期提醒。
|
||||
func (q *Query) CurrentAssetRefKey(ctx context.Context, assetType string, assetID uint) (string, error) {
|
||||
if assetID == 0 {
|
||||
return "", nil
|
||||
}
|
||||
var row struct {
|
||||
ICCID string `gorm:"column:iccid"`
|
||||
VirtualNo string `gorm:"column:virtual_no"`
|
||||
IMEI string `gorm:"column:imei"`
|
||||
}
|
||||
var result *gorm.DB
|
||||
switch assetType {
|
||||
case constants.AssetTypeIotCard, "card":
|
||||
result = q.db.WithContext(ctx).Model(&model.IotCard{}).Select("iccid").Where("id = ?", assetID).Limit(1).Scan(&row)
|
||||
case constants.AssetTypeDevice:
|
||||
result = q.db.WithContext(ctx).Model(&model.Device{}).Select("virtual_no", "imei").Where("id = ?", assetID).Limit(1).Scan(&row)
|
||||
default:
|
||||
return "", nil
|
||||
}
|
||||
if result.Error != nil {
|
||||
return "", errors.Wrap(errors.CodeDatabaseError, result.Error, "查询当前资产标识失败")
|
||||
}
|
||||
if row.ICCID != "" {
|
||||
return row.ICCID, nil
|
||||
}
|
||||
if row.VirtualNo != "" {
|
||||
return row.VirtualNo, nil
|
||||
}
|
||||
return row.IMEI, nil
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ func (q *Query) resolveCandidates(ctx context.Context, candidates []assetCandida
|
||||
if filter.PackageID != nil && usage.PackageID != *filter.PackageID {
|
||||
continue
|
||||
}
|
||||
level, levelName := expiryLevel(days)
|
||||
level, levelName := ExpiryLevel(days)
|
||||
items = append(items, dto.ExpiringAssetItem{
|
||||
AssetType: candidate.AssetType, AssetID: candidate.AssetID, Identifier: candidate.Identifier, ShopID: candidate.ShopID,
|
||||
PackageUsageID: usage.ID, PackageID: usage.PackageID, PackageName: usage.PackageName,
|
||||
@@ -363,7 +363,8 @@ func validateListFilter(filter ListFilter) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func expiryLevel(days int) (string, string) {
|
||||
// ExpiryLevel 返回临期高亮等级与中文名称:≤3 红、≤7 紫、其余粉红。
|
||||
func ExpiryLevel(days int) (string, string) {
|
||||
if days <= 3 {
|
||||
return "red", "红色"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user