简体   繁体   English

如何使用php将订单历史记录存储在数据库中?

[英]How do I store order history in a database using php?

I have a site where users can place an order. 我有一个用户可以下订单的网站。 The order goes through various stages before it is ready for delivery. 在准备交付之前,订单经历了各个阶段。 I want to be able to log anytime anything happens relating to an order. 我希望能够随时记录与订单有关的任何事件。

Here's an example of what I would like for it to look: 这是我希望它看起来的示例:

(2/13/12 4:41pm): Order initiated by Customer (2/13/12 4:41 pm):客户发起的订单
(2/13/12 4:41pm): Order sent to Manager for approval (2/13/12 4:41 pm):订单已发送给经理以供批准
(2/13/12 4:43pm): Order approved by Manager (2/13/12 4:43 pm):经理批准的订单
(2/14/12 6:03pm): The order was edited by the user: (2/14/12 6:03 pm):订单由用户编辑:
City: 'Los Angeles' to 'San Diego' 城市:从“洛杉矶”到“圣地亚哥”
(2/14/12 6:09pm): The order was edited by the admin: (2/14/12 6:09 pm):订单由管理员编辑:
Email: 'gearge@gmail.com' to 'george@gmail.com' 电子邮件:“ gearge@gmail.com”到“ george@gmail.com”
(2/15/12 8:41pm): Order ready for Delivery (2/15/12 8:41 pm):订单已准备好交付

What is the best approach for me to store this type of order history? 对我而言,存储此类订单历史记录的最佳方法是什么? I have created a table in the DB called history where I would like to store the history as it pertains to each order. 我在数据库中创建了一个名为history的表,我想在其中存储与每个订单有关的历史记录。 My columns are history_id(primary), order_id(foreign), date added(timestamp), and history_message(varchar). 我的列是history_id(主要),order_id(外国),添加日期(时间戳)和history_message(varchar)。

Ideally I would like to create numbered codes for each step in the ordering process, such as an order approval, order edit, or order delivery and then just assign the number for that row instead of the actual history message, which is more characters. 理想情况下,我想为订购过程中的每个步骤创建编号的代码,例如订单批准,订单编辑或订单交付,然后只为该行分配编号,而不是实际的历史消息(更多字符)。 I feel that this way I won't overstuff my DB. 我觉得这样我不会过度使用数据库。 The problem with this approach is that I would like to keep a log of the actual data that was changed(as you can see in the edits by the user and admin in the example) and I'm not sure how I can accomplish that without saving the complete history message for each row. 这种方法的问题在于,我想保留更改后的实际数据的日志(如您在示例中的用户和admin的编辑中所见),并且我不确定如何在不进行更改的情况下完成此操作保存每行的完整历史记录消息。

What is the best way to store order history in a database for my situation? 针对我的情况,将订单历史记录存储在数据库中的最佳方法是什么?

You can use trigger to update a child table keeping track of each order status. 您可以使用触发器更新跟踪每个订单状态的子表。

Basically using insert trigger or do manual insert after update in order status by insert query you can copy required data from orders table to a new table we can call trackorders. 基本上使用插入触发器或通过插入查询在订单状态更新后进行手动插入,您可以将所需数据从订单表复制到新表中,我们可以将其称为跟踪订单。 tracking table will keep track of all changes and record with current status will be in main table. 跟踪表将跟踪所有更改,并在主表中记录当前状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM