fix: 第1批 F1、M12 一资产一号与换货按手机号关联校验

- F1 一个资产同时只能有一个有效手机号关联,他号绑定返回 1192(不含号码),同号幂等
- 登录 need_bind_phone 改看资产是否已有有效关联,新增 asset_phone_bound、asset_phone_is_own;H5 绑定按客户/资产两侧状态分别写入
- 客户换号不再迁移资产关联
- M12 换货新资产有有效手机号关联即拒绝,号码只在 data.phone;换货完成清空旧资产客户绑定并失效旧资产关联(exchange_completed),均不迁移
- OpenSpec Change enforce-single-phone-per-asset:11/16,H5 短信与换货端到端验证待测试部署后完成
This commit is contained in:
邹进
2026-10-12 00:10:41 +09:00
parent 6298a9061f
commit 9ced14fa1b
19 changed files with 568 additions and 451 deletions

View File

@@ -7,7 +7,6 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
accessauditapp "github.com/break/junhong_cmp_fiber/internal/application/accessaudit"
"github.com/break/junhong_cmp_fiber/internal/model"
"github.com/break/junhong_cmp_fiber/pkg/config"
"github.com/break/junhong_cmp_fiber/pkg/errors"
@@ -88,15 +87,14 @@ func (s *Service) establishAssociation(
return s.associationWriter.Establish(ctx, tx, customer, phone, assetType, assetID)
}
// migrateAssociations 委托关联写入规则完成换绑原子迁移与上限/冲突判定。
// 开关关闭时完全短路,不迁移任何关联。
func (s *Service) migrateAssociations(
ctx context.Context,
tx *gorm.DB,
oldPhone, newPhone string,
) ([]accessauditapp.PhoneAssetAssociationChange, error) {
if !requirePhoneBinding() {
return nil, nil
// assetHasValidAssociation 判断当前访问资产是否已有任一有效手机号关联;开关关闭或无资产身份时返回 false。
func (s *Service) assetHasValidAssociation(ctx context.Context, tx *gorm.DB, assetType string, assetID uint) (bool, error) {
if !requirePhoneBinding() || assetType == "" || assetID == 0 {
return false, nil
}
return s.associationWriter.Migrate(ctx, tx, oldPhone, newPhone)
phones, err := s.associationStore.WithTx(tx).ListValidByAsset(ctx, assetType, assetID)
if err != nil {
return false, errors.Wrap(errors.CodeInternalError, err, "查询资产手机号关联失败")
}
return len(phones) > 0, nil
}