当客户在线下单时,如何处理DB中的价格变化?

发布于 2024-11-30 06:13:02 字数 443 浏览 2 评论 0原文

我有一个 Product 数据库表,其中包含 product_idpriceinventory_count 等列。

用户点击以特定价格购买特定产品。我的程序生成一个确认页面,列出产品和价格。一切正常,用户单击“确认”。我的程序更新该产品的 inventory_count 并向用户的信用卡收取产品 price 中列出的金额。

但在确认页面生成之后、用户点击“确认”之前的这段时间里,该产品的价格已经发生了变化。因此,用户可能在确认页面中看到价格为 10 美元,但在他单击“确认”后,产品表中的 价格 已更改为 11 美元,这就是他将被收取的费用。

处理这种情况的最佳方法是什么?如果相关的话,我正在使用 MySQL 和 Python。

I have a Product database table with columns such as product_id, price, and inventory_count.

A user clicks to buy a certain product at a certain price. My program generates a confirmation page listing the product and the price. Everything is fine and the user clicks "Confirm". My program updates the inventory_count of that product and charges the user's credit card the amount listed in the product's price.

But during the time after the confirmation page is generated but before the user clicks "Confirm", the price of that product has been changed. So the user might have seen a price of $10 in the confirmation page but after he clicks "Confirm" the price in the Product table has already been changed to $11 and that's what he will be charged.

What's the best way to handle a situation like this? I'm using MySQL and Python if that's relevant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可遇━不可求 2024-12-07 06:13:02

使用您打算实际收取的价格创建一个用于待处理购买的新表,并在生成确认页面时向其中添加项目。

当您将商品添加到 Pending 表时,从 Product 表的 inventory_count 中扣除,然后您可以重新增加 inventory_count code> 如果购买未成功。

Create a new table for pending purchases with the price you intend to actually charge, and add items to it when you generate the confirmation page.

Deduct from the Product table's inventory_count when you add an item to the Pending table, then you can re-increment the inventory_count if the purchase doesn't go through.

荭秂 2024-12-07 06:13:02

您绝对应该从客户最后一次有机会改变主意时开始计算价格。我确信这也是一个法律问题,你在这个问题上看起来不会那么好。

不管怎样,在客户确认后实施最后一次检查不会太难,对吧?也许您可以显示价格已更改的通知。

You definitely should carry over the price from the time the customer last had the chance to change his mind. I'm sure that's also a legal issue in which you'd not look so good.

Anyway, can't be to hard to implement one last check after the customer has confirmed, right? Maybe you then could show a notice that the price has changed.

柠栀 2024-12-07 06:13:02

我认为你应该避免这样的情况(如果我是你的客户我会感到失望)。
但如果不能,当客户按下确认键时,请对价格进行最后一次检查,并在价格发生变化时向用户显示消息。

I my opinion you should avoid situations like this (if I were your customer I would be disappointed).
But if you can't, when customer press confirm, do the last check of price and show message to user if it changed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文