diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index f7a7f3b3..9b01334a 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -12,8 +12,7 @@ type StepPriceJsonStruct struct { EndQuantity int64 `json:"end_quantity"` StartQuantity int64 `json:"start_quantity"` } `json:"price_range"` - MinBuyUnitsNum int64 `json:"min_buy_units_num"` - StepBuyUnitsNum int64 `json:"step_buy_units_num"` + MinBuyUnitsNum int64 `json:"min_buy_units_num"` } func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) { diff --git a/server/product/internal/logic/getpricebypidlogic.go b/server/product/internal/logic/getpricebypidlogic.go index 546533c5..01c7449d 100644 --- a/server/product/internal/logic/getpricebypidlogic.go +++ b/server/product/internal/logic/getpricebypidlogic.go @@ -34,6 +34,84 @@ func NewGetPriceByPidLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get svcCtx: svcCtx, } } + +// 新的阶梯价格(到时候替换) +/*func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) { + req.Pid = strings.Trim(req.Pid, " ") + if req.Pid == "" { + return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:pid is empty") + } + //获取产品信息(只是获取id) + productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "the product is not exists") + } + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") + } + //查询产品价格 + modelPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByProductIdTag(l.ctx, productInfo.Id, constants.TAG_MODEL, "id,part_id,step_price,packed_unit") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get model price list") + } + fittingIds := make([]int64, 0, len(modelPriceList)) + for _, v := range modelPriceList { + if *v.PartId > 0 { + fittingIds = append(fittingIds, *v.PartId) + } + } + //查询配件价格列表 + fittingPriceList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIdsTag(l.ctx, fittingIds, constants.TAG_PARTS, "id,price,packed_unit") + if err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get fitting price list") + } + mapFitting := make(map[int64]gmodel.FsProductModel3d) + for _, v := range fittingPriceList { + mapFitting[v.Id] = v + } + //遍历处理模型价格 + mapRsp := make(map[string]interface{}) + for _, modelPriceInfo := range modelPriceList { + var stepPrice gmodel.StepPriceJsonStruct + if err = json.Unmarshal(*modelPriceInfo.StepPrice, &stepPrice); err != nil { + logx.Error(err) + return resp.SetStatusWithMessage(basic.CodeJsonErr, "failed to parse step price json") + } + if len(stepPrice.PriceRange) == 0 { + return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("step price is not set:%d", modelPriceInfo.Id)) + } + //最小单价 + minPrice := stepPrice.PriceRange[len(stepPrice.PriceRange)-1].Price + //最大单价 + maxPrice := stepPrice.PriceRange[0].Price + //购买数步进基数 + stepPurchaseQuantity := *modelPriceInfo.PackedUnit + if *modelPriceInfo.PartId > 0 { + fittingPriceInfo, ok := mapFitting[*modelPriceInfo.PartId] + if !ok { + return resp.SetStatusWithMessage(basic.CodeServiceErr, fmt.Sprintf("fitting price is not exists:%d", *modelPriceInfo.PartId)) + } + //最小价格要加配件 + minPrice += *fittingPriceInfo.Price + //如果配件装箱基数比主体大,则基数以配件为主 + if *fittingPriceInfo.PackedUnit > stepPurchaseQuantity { + stepPurchaseQuantity = *fittingPriceInfo.PackedUnit + } + } + mapRsp[fmt.Sprintf("_%d", *modelPriceInfo.SizeId)] = map[string]interface{}{ + "step_purchase_quantity": stepPurchaseQuantity, + "min_price": minPrice, + "max_price": maxPrice, + "step_range": stepPrice.PriceRange, + "min_buy_units_num": stepPrice.MinBuyUnitsNum, + } + } + return resp.SetStatusWithMessage(basic.CodeOK, "success", mapRsp) +} +*/ func (l *GetPriceByPidLogic) GetPriceByPid(req *types.GetPriceByPidReq, userinfo *auth.UserInfo) (resp *basic.Response) { req.Pid = strings.Trim(req.Pid, " ") if req.Pid == "" {