自动对商品应用最合适的折扣套餐
我创建了一些折扣套餐:
Package1(Item1,Item2,Item5) Discount-5%. Package2(Item2,Item5,Item8) Discount-8% Package3(Item1,Item2) Discount3%.
当一个人在线购买商品时(例如,他购买商品1、商品2、商品5、商品10),当我向他显示总价时,我需要自动对商品应用最合适的折扣。
在上述情况下,两个折扣将适用于所述选择,但是套餐1折扣是最好的,因为它给一个人最大的好处...所以我需要自动应用它。
有没有人遇到过这种情况或者可以帮助我?
DiscountID DiscountName ItemIds Disc% 1 Package1 1,2,5 5 2 Package2 2,3,5 8 3 Package3 1,2 3
我随身携带了一个人选择的所有 ItemId。现在需要申请最合适的折扣..
感谢您的帮助/指导。
I have created some discount packages:
Package1(Item1,Item2,Item5) Discount-5%. Package2(Item2,Item5,Item8) Discount-8% Package3(Item1,Item2) Discount3%.
When a Person buy Items Online(for Ex. he buys Item1,Item2,Item5, Item10), while I show him the total price, I need to apply the best fitted discount on the items automatically.
In the above case, two discounts would be applicable on said selection, however Package1 Discount is best as it give a person max benefit... so this I need apply this automatically.
Is there anyone who came across this type of scenario or anyone who could help me?
DiscountID DiscountName ItemIds Disc% 1 Package1 1,2,5 5 2 Package2 2,3,5 8 3 Package3 1,2 3
I have all the ItemId with me, which a Person selected. Now need to apply best fit discount..
Appreciating your help/ guidance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
Try this
您需要将每组购买的商品应用于每个套餐,如果不符合条件,则返回折扣百分比或零,然后查询这些结果以获取您的套餐组中的最大折扣。
You need to apply each set of purchased items to each package, either returning the discount %, or zero, if they don't qualify, then query those results for the max discount from your set of packages.
乍一看,这似乎是背包问题的一个实例,它是NP-hard。
本文似乎解决了与您类似的问题。
暴力解决方案
一种暴力解决方案是将折扣套餐的每个有效组合应用于订单。
想象一棵树,其中对于给定节点,每个祖先代表已应用于订单的折扣包,其每个子代代表可应用于订单中其余商品的有效折扣包。
当没有更多的包裹可以应用于订单时,节点是叶子。
如果您有大量商品并且提供超过 1 个折扣套餐,我不会推荐您这样做。
At first glance, it seems like this is an instance of the Knapsack Problem, which is NP-hard.
This paper seems to address a similar problem to yours.
Brute Force Solution
One brute force solution would be to apply every valid combination of discount packages to the order.
Picture a tree where, for a given node, each ancestor represents a discount package that has already been applied to the order, and each of its children represent a valid discount package that can be applied to the remaining items in the order.
A node is a leaf when no more packages can be applied to the order.
I wouldn't recommend this if you have a large number of items and more than 1 discount package being offered.