This commit is contained in:
@@ -43,6 +43,9 @@ func (s *ExchangeOrderStore) List(ctx context.Context, filters map[string]any, p
|
||||
if status, ok := filters["status"].(int); ok && status > 0 {
|
||||
query = query.Where("status = ?", status)
|
||||
}
|
||||
if flowType, ok := filters["flow_type"].(string); ok && flowType != "" {
|
||||
query = query.Where("COALESCE(NULLIF(flow_type, ''), ?) = ?", constants.ExchangeFlowTypeShipping, flowType)
|
||||
}
|
||||
if identifier, ok := filters["identifier"].(string); ok && identifier != "" {
|
||||
like := "%" + identifier + "%"
|
||||
query = query.Where("old_asset_identifier LIKE ? OR new_asset_identifier LIKE ?", like, like)
|
||||
@@ -93,13 +96,14 @@ func (s *ExchangeOrderStore) UpdateStatus(ctx context.Context, id uint, fromStat
|
||||
return nil
|
||||
}
|
||||
|
||||
// FindByNewAssetID 通过新资产类型和ID查询换货来源记录
|
||||
// 用于换货链追溯:找到将当前资产作为换货结果的换货单,从而得到前代资产信息
|
||||
// FindByNewAssetID 通过新资产类型和ID查询已完成换货来源记录
|
||||
// 用于换货链追溯:找到将当前资产作为换货结果的已完成换货单,从而得到前代资产信息
|
||||
// 若未找到则返回 nil, nil 表示该资产无前代
|
||||
func (s *ExchangeOrderStore) FindByNewAssetID(ctx context.Context, assetType string, assetID uint) (*model.ExchangeOrder, error) {
|
||||
var order model.ExchangeOrder
|
||||
err := s.db.WithContext(ctx).
|
||||
Where("new_asset_id = ? AND new_asset_type = ?", assetID, assetType).
|
||||
Where("status = ?", constants.ExchangeStatusCompleted).
|
||||
Order("id DESC").
|
||||
First(&order).Error
|
||||
if err != nil {
|
||||
@@ -111,6 +115,21 @@ func (s *ExchangeOrderStore) FindByNewAssetID(ctx context.Context, assetType str
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
// FindShippingPendingByOldAsset 查询客户端可见的物流换货待处理单
|
||||
// 历史 flow_type 为空时按 shipping 兼容处理。
|
||||
func (s *ExchangeOrderStore) FindShippingPendingByOldAsset(ctx context.Context, assetType string, assetID uint) (*model.ExchangeOrder, error) {
|
||||
var order model.ExchangeOrder
|
||||
query := s.db.WithContext(ctx).
|
||||
Where("old_asset_type = ? AND old_asset_id = ?", assetType, assetID).
|
||||
Where("status IN ?", []int{constants.ExchangeStatusPendingInfo, constants.ExchangeStatusPendingShip, constants.ExchangeStatusShipped}).
|
||||
Where("COALESCE(NULLIF(flow_type, ''), ?) = ?", constants.ExchangeFlowTypeShipping, constants.ExchangeFlowTypeShipping)
|
||||
query = middleware.ApplyShopFilter(ctx, query)
|
||||
if err := query.Order("id DESC").First(&order).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &order, nil
|
||||
}
|
||||
|
||||
func (s *ExchangeOrderStore) FindActiveByOldAsset(ctx context.Context, assetType string, assetID uint) (*model.ExchangeOrder, error) {
|
||||
var order model.ExchangeOrder
|
||||
query := s.db.WithContext(ctx).
|
||||
|
||||
Reference in New Issue
Block a user