简体   繁体   English

在 mysql 和 php 中实施定价计划的最简单方法是什么?

[英]What is the simplest way of implementing pricing plans in mysql and php?

I am working on a project, and I am trying to find a way to associate my pricing plans table with a customer.我正在处理一个项目,我正在尝试找到一种方法将我的定价计划表与客户相关联。

id  name    description      price  days
1   Free    the free plan    0.00   0
2   Silver  the silver plan  49.99  365
3   Gold    the gold plan    99.99  365

My first thought was to add the plan id as foreign key to the customers table.我的第一个想法是将计划 ID 作为外键添加到客户表中。 But i also need to know when is the expire date (based on the purchase date and the days of the plan selected).但我还需要知道到期日期是什么时候(基于购买日期和所选计划的天数)。

When attempting to do something like this, it is best to keep tables abstracted from each other.当尝试做这样的事情时,最好使表彼此抽象。

user_pricing_plans  - the table name
pricing_plans_id - the id for the record you want to associate with a user
user_id   - the id of the user
date_expiration - the date the plan will expire
date_purchased - the date the plan was purchased

following an approach like this will allow you alter this table if needed to add extra information.如果需要添加额外信息,遵循这样的方法将允许您更改此表。 you could also follow a similar approach in the future with another table.您将来也可以使用另一张桌子采用类似的方法。

the key to all of this is separating your concerns ( the data ) into separate containers.所有这一切的关键是将您的关注点(数据)分离到单独的容器中。

Edit: to kind of hint at what I'm getting at about why separating the tables is a good idea, I added the date_purchased as a field in the user_pricing_plans table.编辑:为了暗示我为什么将表分开是一个好主意,我在 user_pricing_plans 表中添加了 date_purchased 作为字段。

a dba I know once said that "mysql is not a place for developers - they try to create tables to work with their code. tables are meant to represent data. your code should be written to work with the data and the schemas that represent them - not the other way around"我认识的一个 dba 曾经说过“mysql 不是开发人员的地方——他们试图创建表来处理他们的代码。表是用来表示数据的。你的代码应该被编写为处理数据和代表它们的模式- 不是相反”

I do not know why I can not add a comment to the best answer in the post.我不知道为什么我不能在帖子中的最佳答案中添加评论。

As @Jonathon Hibbard points few years ago, there is another reason to separate the data between pricing plan and user model.正如@Jonathon Hibbard 几年前指出的那样,将定价计划和用户模型之间的数据分开还有另一个原因。

You used to have users who have one plan and choose another later, that is called, "history".曾经有用户拥有一个计划,然后选择另一个计划,这称为“历史”。 To manage that, this third table is very important.为了做到这一点,第三张表非常重要。

And in my opinion, more important, one thing is your pricing table, an another one is the final price you have with every client.在我看来,更重要的是,一件事是你的定价表,另一件事是你对每个客户的最终价格。 Yo have knownledge people, close clients that you want "special" prices, this third table gives you the oportunity to set diferent prices for one plan with fixed price and a lot of other use cases.你知道人们,你想要“特殊”价格的亲密客户,这第三张表让你有机会为一个固定价格的计划和许多其他用例设置不同的价格。

Think about your main plan table like a product, the user is the client, and the third party as the ticket, with "temp pricing" aplied, ocassional discounts or whatever.把你的主计划表想象成一个产品,用户是客户,第三方是票,有“临时定价”,偶尔折扣或其他什么。

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

相关问题 在php中订购mysql输出的最简单/最快的方法 - Simplest/fastest way of ordering mysql output in php 在PHP中实现Parallel cURL的最简单方法是什么? - What is the simplest way to implement Parallel cURL in PHP? 在PHP中引用多字节字符串的最简单方法是什么? - What is the simplest way to reference a Multibyte string in PHP? 将php代码定义为变量-最简单的方法是什么? - Defining php code as a variable - what is the simplest way? 在mysql / php中使用id / parent_id模型获取记录的所有父级的最简单方法是什么? - What is the simplest way to get all the parents of a record using the id / parent_id model in mysql/php? PHP / MySQL定价路线 - PHP/MySQL Pricing routes PHP + mysql:从包含存款,收益和取款的交易列表中计算个人利润的最简单方法是什么 - PHP+mysql : What would be the simplest way to calculate individual profits from a transaction list containing deposits, gains and withdrawals 在自定义的magento 2模块中使用外部php库的最简单方法是什么? - What is the simplest way to use an external php library in a custom magento 2 module? 在PHP中从SQL格式化时间戳的最简单方法是什么? - What is the simplest way to format a timestamp from SQL in PHP? 将远程 HTTP 资源获取到字符串中的最简单方法(在 PHP 中)是什么? - What’s the simplest way (in PHP) to grab a remote HTTP resource into a string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM