Demo entry 6634319

test

   

Submitted by anonymous on Aug 09, 2017 at 17:01
Language: Python. Code size: 761 Bytes.

# In:
#   store_id - 商店 ID
#   user_id - 用户 ID (可以用 支付宝 或 微信 ID 来代表)
#   paid_amount - 本次消费金额 (单位: 元)
#
# Out:
#   threshold - 优惠券生效时所需达到的消费门槛
#   discount_amount - 优惠券折扣金额

def recommend_coupon(store_id, user_id, paid_amount):
    MAX_DISCOUNT_AMOUNT = 10    # 限定的折扣金额上限
    BASE_PERCENT_OF_PAID_AMOUNT = 0.1   # 基于本次消费金额的折扣基础比例

    threshold = 0   # 目前暂且只生成无门槛的立减券

    user_level_for_store = get_user_level_for_store(user_id, store_id)  # 获取用户在该商店的等级,取值范围为 0(最差) - 9(最好)。此等级由历史订单中用户的 RFM 值决定。

    discount_amount = (paid_amount * BASE_PERCENT_OF_PAID_AMOUNT) * (1 - user_level_for_store / 10) # 用户等级越低,越需要刺激,因此折扣金额越大
    discount_amount = min(MAX_DISCOUNT_AMOUNT, discount_amount) # 最大不超过给定的折扣金额上限

    return threshold, discount_amount

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).