简体   繁体   English

PHP / Doctrine 1.2 / MySQL-根据另一个值识别一个值

[英]PHP / Doctrine 1.2 / MySQL - Identifying one value depending on another value

I'm working on an online warehouse/shopping system (php + doctrine + mysql), where each product can have more than one price depending on the quantity. 我正在开发一个在线仓库/购物系统(php +教义+ mysql),根据数量,每种产品的价格都可能超过一个。 I have two tables (1) Product and (2) Price: 我有两个表(1)产品和(2)价格:

Product 产品

id    name
1     product1  
2     product2
3     product3

Price 价钱

id  product_id     from    to      price
1   1              1       10      90
2   1              11      20      80
3   1              21      30      70

As you can see, product1 has 3 different prices. 如您所见, product1具有3个不同的价格。 For instance, if the customer buy between 1 and 10 product1, he should get the first price - 90, between 11 and 20 the next price - 80 and so on. 例如,如果客户购买1到10之间的product1,他应该得到第一个价格-90,在11和20之间得到下一个价格-80,依此类推。

Since the calculation is progressive the total result will be: 由于计算是渐进的,因此总结果将为:

Invoice 发票

id  product_id   quantity    price_id
1   1            10          1
2   1            10          2
3   1            10          3

The question is what is the best way to identify the price level depending on the product quantity using Doctrine. 问题是使用Doctrine根据产品数量确定价格水平的最佳方法是什么。

Thanks in advance! 提前致谢!

Create a getPrice() method in your Product model and have it do the calculations. 在产品模型中创建一个getPrice()方法,并进行计算。 Then you can invoke it with: $product->price or $product->getPrice() . 然后,您可以使用$product->price$product->getPrice()调用它。 I would avoid trying to make the calculations with your DQL/SQL queries 我会避免尝试使用您的DQL / SQL查询进行计算

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

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