您的电子商务系统的交易管理策略应该是什么?
在基于网络的电子商务系统中管理交易的一般模式或方法是什么?例如,您如何处理多个用户尝试购买最后一件商品的情况?
What is the general pattern or approach to managing transactions in a web-based e-commerce system? How do you handle the situation where more than one user tries to buy the last item, for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了防止两个用户购买只有 1 件库存的同一库存商品,您需要在创建订单并减少该商品的库存之前检查用户购物车中的每个商品是否都有可用库存。
此操作必须是原子的,并且在任何给定时间只能处理一个订单(请阅读:数据库事务),如果您使用中央数据库进行库存管理,这应该不是问题。
如果客户结帐时库存已用完,您应该从客户的购物车中删除该商品并将其重定向到购物车,并通知他们这一情况。
当然,只有当两个用户都将相同的库存商品添加到购物车,而其中只有一件商品有库存并且其中一个用户结账时,才会出现这种情况。先到先得。如果当时没有库存,您通常不应允许客户将产品添加到购物车,除非您可以在合理的时间内订购新库存,但在这种情况下,整个要点就没有意义了。
您可以采取先发制人的方法,在客户发起结帐时检查库存是否可用,并采取与上述相同的路线。但是,这取决于您产品的性质以及交易量与取消订单的数量。如果同一商品的另一个订单可能同时被取消,并且在客户结帐时有库存,那么您不希望因为告诉客户没有库存而失去销售机会。最好让订单在没有货的情况下失败,并告知客户这种情况,毕竟这种情况很少见。
To prevent two users from purchasing the same stock item of which there is only 1 unit in stock, you need to check that each item in a user's cart has stock available right before you create an order and decrement stock for that item.
This operation will have to be atomic and only one order can be processed at any given time (read: database transaction), which should not be a problem if you are using a central database for stock management.
If stock has run out by the time a client checks out, you should remove the item from the client's cart and redirect them to their shopping cart, informing them of the situation.
Of course, this situation only occurs when two users both add the same stock item to their cart of which only one unit is in stock and one of them checks out. First come, first served. You should generally not allow clients to add products to their cart if no stock is available at that moment, unless you can order new stock within a reasonable amount of time, but in that case, the whole point is moot.
You can take a preemptive approach by checking that stock is available the moment a client initiates checkout and take the same route as above. However, that would depend on the nature of your product and the volume of transactions vs cancelled orders. If it is likely that another order for the same item was cancelled in the meantime and stock becomes available by the time a client checks out, then you don't want to lose a sale by telling the client that no stock is available. Better to let the order fail at the moment stock is not available and inform the client of the situation, which is rare after all.
为什么不先接受订单,然后再为客户获取该商品(或许稍晚一些)?您可以赢得回头客:)
Why not take the order and then get that item for the customer, perhaps a bit later? You can win a repeat customer :)