예제 #1
0
파일: division.py 프로젝트: c1xfr2e/soledad
def all_division(year=None):
    for code in data.get(year, []):
        if unicode(code) in excluded_division_codes:
            continue  # restricted to China Mainland
        yield Division.get(code, year)
예제 #2
0
파일: division.py 프로젝트: c1xfr2e/soledad
def get_division(code, year=None):
    try:
        return Division.get(code, year)
    except ValueError:
        return
예제 #3
0
def subscribe_product(user,
                      product,
                      bankcard,
                      order_amount,
                      pay_amount,
                      due_date,
                      wrapped_product=None,
                      coupon=None,
                      pocket_deduction_amount=0):
    """申购产品"""
    # 检查礼券是否可用、返现账户抵扣是否可用、订单是否可建
    if coupon:
        coupon.check_before_use(wrapped_product or product, order_amount)
    if pocket_deduction_amount > 0:
        FirewoodWorkflow(user.id_).check_deduction_enjoyable(
            wrapped_product or product, order_amount, pocket_deduction_amount)
    wrapped_product_id = wrapped_product.id_ if wrapped_product else None
    ZhiwangOrder.check_before_adding(user.id_, bankcard.id_,
                                     product.product_id, order_amount,
                                     wrapped_product_id)

    # 获取订单优惠信息并检查合法性
    hike_list = collect_profit_hikes(user, coupon, pocket_deduction_amount,
                                     wrapped_product)
    rate_bonus = max([h.annual_rate
                      for h in hike_list]) if hike_list else Decimal('0')
    deduction_bonus = sum([h.deduction_amount for h in hike_list])
    assert rate_bonus < Decimal('5.0')  # 指旺最高加息限制
    assert order_amount - deduction_bonus == pay_amount

    try:
        # 向指旺发起申购请求
        response = zhiwang.order_apply_with_coupon(
            ZhiwangAccount.get_by_local(user.id_).zhiwang_id,  # 用户的指旺ID
            product.product_id,  # 用户认购的产品
            rate_bonus,  # 加息值
            order_amount,  # 订单金额
            pay_amount,  # 实际支付金额
            bankcard.card_number,  # 银行卡号
            int(bankcard.bank.zwlib_id),  # 银行ID
            bankcard.mobile_phone,  # 银行预留手机号
            due_date.strftime('%Y-%m-%d')
            if due_date else None,  # TODO: 认购产品到期日
            Division.get(bankcard.province_id, year=2006).name,  # 银行卡开卡省份
            Division.get(bankcard.city_id, year=2006).name)  # 银行卡开卡市
    except RemoteError as e:
        err_msg = e.args[1]
        err_msg = ZWLIB_ERROR_MAPPING.get(err_msg, err_msg)
        raise SubscribeProductError(u'申购产品失败: %s' % err_msg)

    assert pay_amount == response.pay_amount

    # 创建订单
    order = ZhiwangOrder.add(user.id_, product.product_id, bankcard.id_,
                             order_amount, response.pay_amount,
                             response.expect_interest,
                             response.interest_start_date,
                             response.interest_end_date, response.order_code,
                             response.pay_code, wrapped_product_id)
    # 创建优惠记录
    for hike in hike_list:
        # FIXME: the operation of hikes should be managed in one session
        Hike.add(user.id_, order.id_, hike.kind, hike.annual_rate,
                 hike.deduction_amount)
    # 订单预绑定礼券
    if coupon:
        CouponUsageRecord.add(coupon, user, provider_zhiwang, order)
    # 创建抵扣使用记录
    if pocket_deduction_amount > 0:
        FirewoodBurning.add(user, pocket_deduction_amount,
                            FirewoodBurning.Kind.deduction, provider_zhiwang,
                            order.id_)
    return order