订单状态和状态日志
我正在用 PHP / MYSQL 开发电子商务(在线购物)的后端。
我想知道处理订单状态和状态跟踪/日期的最佳方式是什么。
当用户下订单时,tbl_order 表上的订单状态将为 1 (tbl_order.status = 1
)。这是最好的方法吗?
以下为订单状态编号:
- 1 - 新订单
- 2 - 待处理
- 3 - 已取消
- 4 - 已完成
当工作人员登录后台时,可以逐步更改订单状态。
我想追踪谁做的以及时间,怎么做?
I am developing a backend of e-commerce (online shopping) in PHP / MYSQL.
I want to know what the best way dealing with orders status and status tracking/date.
When a user placed an order, the order status will be 1 (tbl_order.status = 1
) on the tbl_order table. Is this the best way?
Here are the numbers of order status:
- 1 - New Order
- 2 - Pending
- 3 - Cancelled
- 4 - Completed
When staff login on the backend, they can change the order status step by step.
I want to track who done it and the time, how can that be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当前订单状态应按照您的建议存储在订单表中。
但为了跟踪更改,我建议使用一个单独的日志表,您可以在其中记录
timestamp
、order_id
、user_id
、old_status
代码>,<代码>new_status。这样您就可以随时追溯完整历史记录(与LastUpdate
概念相反)。这个概念可以推广到订单状态之外 - 任何字段值的变化都可以通过这种方式跟踪(尽管大量跟踪日志表的大小往往会快速增长)
Current order status should be stored on the order table as you suggest.
But for tracking changes, I would suggest a separate log table, where you would log
timestamp
,order_id
,user_id
,old_status
,new_status
. This way you can retrace full history at any time (as opposed toLastUpdate
concept).This concept can be generalized beyond the order status - any field value changes can be tracked this way (though with lots of tracking log tables tend to grow in size rapidly)
这种方法没有什么根本性的错误。您是否有一个 OrderStatus 表来存储数字及其含义?我会推荐这个,因为它将允许在将来添加不同的状态,而不会大惊小怪。
关于跟踪更改和时间 - 您通常会有一个“LastUpdated”和“UserId”列,每次修改订单时都会更新它们(可能使用存储过程来强制执行此操作)。我将它们放入 tbl_order 表中,以便记录对订单的任何更改。
总的来说,我认为你走的是正确的道路。
There is nothing fundmentally wrong with this method. Will you have an OrderStatus table that stores the numbers next to their meanings? I would recommend this as it will allow for different statuses to be added in the future with a minimum of fuss.
With regards to tracking changes and time - you would usually have a "LastUpdated" and "UserId" column which is updated each time the order is modified (perhaps using a stored procedure to enforce this). I'd put these in tbl_order table so that any changes to the order are logged.
Overall I think you're going down the right path.