fix
This commit is contained in:
		
							parent
							
								
									6eccd11386
								
							
						
					
					
						commit
						ab916ac13d
					
				| @ -152,3 +152,17 @@ func (d *FsProductModel3dModel) FindOneByProductIdSizeIdTag(ctx context.Context, | |||||||
| 	err = db.Take(&resp).Error | 	err = db.Take(&resp).Error | ||||||
| 	return resp, err | 	return resp, err | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func (d *FsProductModel3dModel) GetAllByProductIdsTags(ctx context.Context, productIds []int64, tags []int, fields ...string) (resp []FsProductModel3d, err error) { | ||||||
|  | 	if len(productIds) == 0 || len(tags) == 0 { | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
|  | 	db := d.db.WithContext(ctx).Model(&FsProductModel3d{}). | ||||||
|  | 		Where("`product_id` in (?)  and `tag` in (?) and `status` = ?", productIds, tags, 1). | ||||||
|  | 		Order("sort DESC") | ||||||
|  | 	if len(fields) != 0 { | ||||||
|  | 		db = db.Select(fields[0]) | ||||||
|  | 	} | ||||||
|  | 	err = db.Find(&resp).Error | ||||||
|  | 	return resp, err | ||||||
|  | } | ||||||
|  | |||||||
| @ -3,10 +3,11 @@ package logic | |||||||
| import ( | import ( | ||||||
| 	"encoding/json" | 	"encoding/json" | ||||||
| 	"errors" | 	"errors" | ||||||
|  | 	"fmt" | ||||||
|  | 	"fusenapi/constants" | ||||||
| 	"fusenapi/model/gmodel" | 	"fusenapi/model/gmodel" | ||||||
| 	"fusenapi/utils/auth" | 	"fusenapi/utils/auth" | ||||||
| 	"fusenapi/utils/basic" | 	"fusenapi/utils/basic" | ||||||
| 	"fusenapi/utils/format" |  | ||||||
| 	"fusenapi/utils/image" | 	"fusenapi/utils/image" | ||||||
| 	"fusenapi/utils/s3url_to_s3id" | 	"fusenapi/utils/s3url_to_s3id" | ||||||
| 	"gorm.io/gorm" | 	"gorm.io/gorm" | ||||||
| @ -228,32 +229,50 @@ func (l *GetTagProductListLogic) getProductRelationInfo(req getProductRelationIn | |||||||
| 			CoverMetadata: req.MapResourceMetadata[*v.Cover], | 			CoverMetadata: req.MapResourceMetadata[*v.Cover], | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| 	//获取产品价格列表 | 	//获取产品模型价格列表 | ||||||
| 	productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds) | 	modelList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdsTags(l.ctx, productIds, []int{constants.TAG_MODEL, constants.TAG_PARTS}, "id,product_id,price,tag,step_price") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logx.Error(err) | 		logx.Error(err) | ||||||
| 		return nil, errors.New("failed to get product min price list") | 		return nil, errors.New("failed to get model list") | ||||||
| 	} | 	} | ||||||
| 	//存储产品最小价格 | 	mapModelMinPrice := make(map[int64]int64) | ||||||
| 	for _, v := range productPriceList { | 	//每个模型/配件存储最小价格 | ||||||
| 		priceStrSlic := strings.Split(v.Price, ",") | 	for _, modelInfo := range modelList { | ||||||
| 		priceSlice, err := format.StrSlicToIntSlice(priceStrSlic) | 		switch *modelInfo.Tag { | ||||||
| 		if err != nil { | 		case constants.TAG_MODEL: //模型 | ||||||
| 			logx.Error(err) | 			if modelInfo.StepPrice == nil || len(*modelInfo.StepPrice) == 0 { | ||||||
| 			return nil, errors.New("parse price err") | 				return nil, errors.New(fmt.Sprintf("model step price is not set:%d", modelInfo.Id)) | ||||||
|  | 			} | ||||||
|  | 			var stepPrice gmodel.StepPriceJsonStruct | ||||||
|  | 			if err = json.Unmarshal(*modelInfo.StepPrice, &stepPrice); err != nil { | ||||||
|  | 				logx.Error(err) | ||||||
|  | 				return nil, errors.New(fmt.Sprintf("failed to parse model step price:%d", modelInfo.Id)) | ||||||
|  | 			} | ||||||
|  | 			lenRange := len(stepPrice.PriceRange) | ||||||
|  | 			if lenRange == 0 { | ||||||
|  | 				return nil, errors.New(fmt.Sprintf("the count of step price is 0:%d", modelInfo.Id)) | ||||||
|  | 			} | ||||||
|  | 			mapModelMinPrice[modelInfo.Id] = stepPrice.PriceRange[lenRange-1].Price | ||||||
|  | 		case constants.TAG_PARTS: //配件 | ||||||
|  | 			mapModelMinPrice[modelInfo.Id] = *modelInfo.Price | ||||||
| 		} | 		} | ||||||
| 		if len(priceSlice) == 0 { | 	} | ||||||
|  | 	//给产品存储最小价格 | ||||||
|  | 	for _, v := range modelList { | ||||||
|  | 		if *v.Tag != constants.TAG_MODEL { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| 		//正序排序价格(注意排序后的阶梯价格不能用作阶梯数量价格计算) | 		itemPrice := mapModelMinPrice[v.Id] | ||||||
| 		sort.Ints(priceSlice) | 		if *v.PartId > 0 { | ||||||
| 		if min, ok := req.MapProductMinPrice[v.ProductId]; ok { | 			itemPrice += mapModelMinPrice[*v.PartId] | ||||||
| 			if min > int64(priceSlice[0]) { |  | ||||||
| 				req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0]) |  | ||||||
| 			} |  | ||||||
| 		} else { |  | ||||||
| 			req.MapProductMinPrice[v.ProductId] = int64(priceSlice[0]) |  | ||||||
| 		} | 		} | ||||||
|  | 		if minPrice, ok := req.MapProductMinPrice[*v.ProductId]; ok { | ||||||
|  | 			if itemPrice < minPrice { | ||||||
|  | 				req.MapProductMinPrice[*v.ProductId] = itemPrice | ||||||
|  | 			} | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 		req.MapProductMinPrice[*v.ProductId] = itemPrice | ||||||
| 	} | 	} | ||||||
| 	//获取模板 | 	//获取模板 | ||||||
| 	productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") | 	productTemplatesV2List, err = l.svcCtx.AllModels.FsProductTemplateV2.FindAllByProductIds(l.ctx, productIds, "sort ASC", "product_id,id,model_id,template_tag") | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user