【问题标题】:Building A Generic Coupon Service System构建通用优惠券服务系统
【发布时间】:2015-11-26 11:12:21
【问题描述】:

我在一家食品电子商务公司工作,我正在重新设计优惠券服务。

优惠券可以有很多规则,例如:

a)for what users it is valid
b)For what restaurants it is valid
c)For what area it is valid
d)min amount
etc etc

当前系统处理所有这些规则,每个规则表示为一列是 MySQL:http://pastebin.com/6KDC0iC8

但是,由于优惠券规则会不断变化,我们不能每次都创建列。或者我们可以吗?有没有办法让它通用而不失去查询的能力:

a)what all coupons belong to this restaurant
b)what all coupons belong to this area

我正在考虑为此使用 mongo db。有什么建议吗?

【问题讨论】:

    标签: mysql mongodb database-schema coupon


    【解决方案1】:

    这是我对您的方案的建议。只是我的初步想法,所以如果您想让我详细说明,请告诉我。

    如果您必须为每个属性创建列,它可能确实不是非常可扩展的。我建议您将具有一对多或多对多关系的优惠券的属性存储在单独的表中。

    我可以想象这样的情况:

    Coupon
      id
      ...
    
    Restaurant
      id
      ...
    
    Area
      id
      ...
    
    CouponsInArea
      coupon_id
      area_id
    
    CouponRestaurantValidity
      coupon_id
      restaurant_id
    

    这些可能不会有太大变化。

    某些属性也可能对优惠券有效或无效。你可以用更通用的方式解决这个问题:

    CouponProperty
      coupon_id
      property (a string)
    

    然后您可以通过与此类似的方式检索来查询:

    select coupon properties where coupon_id is coupon.id
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多