This commit is contained in:
@@ -1087,6 +1087,9 @@ func (s *Service) List(ctx context.Context, req *dto.OrderListRequest, buyerType
|
||||
if req.PurchaseRole != "" {
|
||||
filters["purchase_role"] = req.PurchaseRole
|
||||
}
|
||||
if req.SellerShopID != nil {
|
||||
filters["seller_shop_id"] = *req.SellerShopID
|
||||
}
|
||||
if req.StartTime != nil {
|
||||
filters["start_time"] = req.StartTime
|
||||
}
|
||||
@@ -1094,7 +1097,18 @@ func (s *Service) List(ctx context.Context, req *dto.OrderListRequest, buyerType
|
||||
filters["end_time"] = req.EndTime
|
||||
}
|
||||
if req.Identifier != "" {
|
||||
resolvedIotCardID, resolvedDeviceID, err := s.resolveOrderListAssetIdentifier(ctx, req.Identifier)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 保留快照标识匹配,并叠加资产 ID 匹配(由 Store 层统一按 OR 组合)
|
||||
filters["identifier"] = req.Identifier
|
||||
if resolvedIotCardID != nil {
|
||||
filters["iot_card_id"] = *resolvedIotCardID
|
||||
}
|
||||
if resolvedDeviceID != nil {
|
||||
filters["device_id"] = *resolvedDeviceID
|
||||
}
|
||||
}
|
||||
if req.BuyerPhone != "" {
|
||||
filters["buyer_phone"] = req.BuyerPhone
|
||||
@@ -1134,6 +1148,75 @@ func (s *Service) List(ctx context.Context, req *dto.OrderListRequest, buyerType
|
||||
}, nil
|
||||
}
|
||||
|
||||
// resolveOrderListAssetIdentifier 将订单列表的统一资产标识解析为卡或设备 ID
|
||||
// 支持 ICCID、VirtualNo、IMEI、SN、MSISDN,与资产解析接口的识别口径保持一致。
|
||||
func (s *Service) resolveOrderListAssetIdentifier(ctx context.Context, identifier string) (*uint, *uint, error) {
|
||||
if identifier == "" {
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
if s.assetIdentifierStore != nil {
|
||||
regRecord, regErr := s.assetIdentifierStore.FindByIdentifier(ctx, identifier)
|
||||
if regErr != nil {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, regErr, "查询资产标识符失败")
|
||||
}
|
||||
if regRecord != nil {
|
||||
switch regRecord.AssetType {
|
||||
case model.AssetTypeIotCard:
|
||||
card, cardErr := s.iotCardStore.GetByID(ctx, regRecord.AssetID)
|
||||
if cardErr == nil && card != nil {
|
||||
cardID := card.ID
|
||||
return &cardID, nil, nil
|
||||
}
|
||||
if cardErr != nil && cardErr != gorm.ErrRecordNotFound {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, cardErr, "查询物联网卡失败")
|
||||
}
|
||||
case model.AssetTypeDevice:
|
||||
device, deviceErr := s.deviceStore.GetByID(ctx, regRecord.AssetID)
|
||||
if deviceErr == nil && device != nil {
|
||||
deviceID := device.ID
|
||||
return nil, &deviceID, nil
|
||||
}
|
||||
if deviceErr != nil && deviceErr != gorm.ErrRecordNotFound {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, deviceErr, "查询设备失败")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
device, deviceErr := s.deviceStore.GetByIdentifier(ctx, identifier)
|
||||
if deviceErr == nil && device != nil {
|
||||
deviceID := device.ID
|
||||
return nil, &deviceID, nil
|
||||
}
|
||||
if deviceErr != nil && deviceErr != gorm.ErrRecordNotFound {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, deviceErr, "查询设备失败")
|
||||
}
|
||||
|
||||
var card model.IotCard
|
||||
query := s.db.WithContext(ctx).Model(&model.IotCard{})
|
||||
query = middleware.ApplyShopFilter(ctx, query)
|
||||
|
||||
conditions := []string{"virtual_no = ?", "msisdn = ?", "iccid = ?"}
|
||||
args := []any{identifier, identifier, identifier}
|
||||
if len(identifier) == 19 {
|
||||
conditions = append(conditions, "iccid_19 = ?")
|
||||
args = append(args, identifier)
|
||||
} else if len(identifier) == 20 {
|
||||
conditions = append(conditions, "iccid_20 = ?")
|
||||
args = append(args, identifier)
|
||||
}
|
||||
|
||||
if err := query.Where(strings.Join(conditions, " OR "), args...).First(&card).Error; err == nil {
|
||||
cardID := card.ID
|
||||
return &cardID, nil, nil
|
||||
} else if err != gorm.ErrRecordNotFound {
|
||||
return nil, nil, errors.Wrap(errors.CodeDatabaseError, err, "查询物联网卡失败")
|
||||
}
|
||||
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
func (s *Service) Cancel(ctx context.Context, id uint, buyerType string, buyerID uint) error {
|
||||
order, err := s.orderStore.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user