Exemplo n.º 1
0
def main():
    user = Account.get_by_alias(EMAIL)
    ZhiwangAccount.unbind(user.id_)

    try:
        register_zhiwang_account(user.id_)
        zhiwang_account = ZhiwangAccount.get_by_local(user.id_)
    except (MismatchUserError, RepeatlyRegisterError) as e:
        bcolors.fail(e.args[0], key='zhiwang_code')
        return

    bcolors.run('The new zhiwang code is %s' % zhiwang_account.zhiwang_id,
                key='zhiwang_code')

    with open(ADD_ZHIWANG_FILE, 'r') as f:
        source = RE_ZHIWANG_CODE.sub(
            "ZHIWANG_TOKEN = u'%s'" %
            zhiwang_account.zhiwang_id.encode('ascii'), f.read())
    with open(ADD_ZHIWANG_FILE, 'w') as f:
        f.write(source)

    bcolors.run('%s is changed. PLEASE COMMIT IT AND OPEN A MERGE REQUEST.' %
                ADD_ZHIWANG_FILE,
                key='zhiwang_code')

    if '--commit' in sys.argv:
        subprocess.check_call(
            ['git', 'commit', '-m', COMMIT_MSG, '--', ADD_ZHIWANG_FILE])
Exemplo n.º 2
0
def checkin():
    if not g.user:
        abort(401)
    if not ZhiwangAccount.get_by_local(g.user.id):
        abort(400)
    if zhiwang_offline_switch.is_enabled:
        abort(403, ZWLIB_OFFLINE_TEXT)
Exemplo n.º 3
0
def check_identity():
    if ZhiwangAccount.get_by_local(g.user.id_):
        if not has_real_identity(g.user):
            # 当用户有指旺账号却没有身份信息时跳转完善信息(基本不可能发生)
            return redirect(url_for('profile.auth.supply', next=request.path))
    else:
        # 没有指旺账号则跳转注册页
        return redirect(url_for('savings.auth.zhiwang', next=request.path))

    g.identity = Identity.get(g.user.id_)
Exemplo n.º 4
0
def channel_zhiwang():
    if ZhiwangAccount.get_by_local(g.user.id_):
        return jsonify(r=True)
    try:
        register_zhiwang_account(g.user.id_)
    except MismatchUserError as e:
        return jsonify(r=False, error=e.args[0])
    except RepeatlyRegisterError as e:
        return jsonify(r=False, error=e.args[0])
    else:
        return jsonify(r=True), 201
Exemplo n.º 5
0
def index():
    cur_path = 'savings'

    # 个人信息
    saving_manager = SavingsManager(g.user.id_)
    coupon_manager = CouponManager(g.user.id_)

    # 礼券
    coupons = coupon_manager.deduplicated_available_coupons

    # 指旺产品
    fdb_products, cls_products, ncm_products = [], [], []
    for p in ZhiwangProduct.get_all():
        if p.product_type is ZhiwangProduct.Type.fangdaibao:
            fdb_products.append(p)
        elif p.product_type is ZhiwangProduct.Type.classic:
            # 指旺暂不显示中长期产品
            if p.profit_period['min'] not in (
                    ProfitPeriod(90, 'day'),  # 临时决定不在Web上显示90天产品
                    ProfitPeriod(180, 'day'),
                    ProfitPeriod(270, 'day'),
                    ProfitPeriod(365, 'day')):
                cls_products.append(p)

    # 2016年五月一日下线指旺自选到期日产品
    if not zhiwang_fdb_product_on_switch.is_enabled:
        fdb_products = []

    xm_products = XMFixedDuedayProduct.get_all()

    has_identity = has_real_identity(g.user)
    # 合作方授权(检查是否需要验证(尝试自动注册)指旺账号
    zhiwang_account = ZhiwangAccount.get_by_local(g.user.id_)
    can_quick_reg_zhiwang = has_identity and not zhiwang_account

    # 合作方授权(检查是否需要验证(尝试自动注册)新米账号
    xm_account = XMAccount.get_by_local(g.user.id_)
    can_quick_reg_xm = has_identity and not xm_account

    context = {
        'cur_path': cur_path,
        'coupons': coupons,
        'ncm_products': ncm_products,
        'fdb_products': fdb_products,
        'cls_products': cls_products,
        'xm_products': xm_products,
        'saving_manager': saving_manager,
        'plan_amount': g.hoard_profile.plan_amount,
        'can_quick_reg_xm': can_quick_reg_xm,
        'can_quick_reg_zhiwang': can_quick_reg_zhiwang
    }
    return render_template('savings/mine.html', **context)
Exemplo n.º 6
0
def zhiwang_payment_tracking(order_id):
    """同步指旺用户订单支付状态"""
    from core.models.hoard.zhiwang import ZhiwangOrder, ZhiwangAccount

    expected_status_set = frozenset([
        ZhiwangOrder.Status.success,
        ZhiwangOrder.Status.failure,
    ])

    order = ZhiwangOrder.get(order_id)
    origin_status = order.status
    if origin_status in expected_status_set:
        return

    zw_ucode = ZhiwangAccount.get_by_local(order.user_id).zhiwang_id
    response = zhiwang.order_status(zw_ucode, order.order_code)
    assert response.order_code == order.order_code
    assert int(response.pay_amount) == int(order.amount)
    new_status = ZhiwangOrder.MUTUAL_STATUS_MAP.get(response.order_status)

    if new_status is not origin_status:
        # 当订单属于自然失败时不再更新状态
        if new_status is ZhiwangOrder.Status.failure and origin_status in (
                ZhiwangOrder.Status.unpaid, ZhiwangOrder.Status.committed):
            return

        # 只有当订单状态发生变化时才更新状态
        order.update_status(new_status)
        if new_status in expected_status_set:
            return

    if bearychat.configured:
        # 长时间未被结算中心处理的订单将发往BC提醒
        since_delta = datetime.datetime.now() - order.creation_time
        if since_delta > datetime.timedelta(hours=6):
            message = (u'已经**{}**了, 指旺订单 {}({}) 状态仍为 {}. '
                       u'[[查看详情]](http://earth.guihua.com/hoard/user/{})')
            bearychat.say(
                message.format(format_timedelta(since_delta, locale='zh_CN'),
                               order.id_, order.order_code, new_status.name,
                               order.user_id))

    error_msg = (u'tube:{0}, order_id:{1}, order code:{2}, '
                 u'new status:{3},user_id:{4}')
    raise WorkerTaskError(
        error_msg.format(zhiwang_payment_tracking.tube, order.id_,
                         order.order_code, new_status.name, order.user_id))
Exemplo n.º 7
0
def publicity():
    # 指旺活动产品
    products = [
        p for p in ZhiwangProduct.get_all()
        if p.product_type is ZhiwangProduct.Type.fangdaibao
    ]
    products = sorted(products, key=attrgetter('final_due_date'))
    product = first((p for p in products if p.in_stock), None)
    can_quick_reg_zhiwang = None
    if g.user:
        zhiwang_account = ZhiwangAccount.get_by_local(g.user.id_)
        can_quick_reg_zhiwang = not zhiwang_account and has_real_identity(
            g.user)
    return render_template('savings/publicity.html',
                           cur_path='savings',
                           product=product,
                           can_quick_reg_zhiwang=can_quick_reg_zhiwang)
Exemplo n.º 8
0
def zhiwang_asset_fetching(order_id):
    """为指旺资产找到匹配订单"""
    from core.models.hoard.zhiwang import ZhiwangOrder, ZhiwangAccount, ZhiwangAsset

    order = ZhiwangOrder.get(order_id)
    asset = ZhiwangAsset.get_by_order_code(order.order_code)
    if asset:
        return

    user_id = order.user_id
    zw_ucode = ZhiwangAccount.get_by_local(user_id).zhiwang_id
    all_assets = sorted(zhiwang.asset_list(zw_ucode),
                        key=operator.attrgetter('created_at'),
                        reverse=True)
    for asset_info in all_assets:
        detail = zhiwang.asset_details(zw_ucode, asset_info.asset_code)
        if detail.order_code == order.order_code:
            # find the matcher
            ZhiwangAsset.add(
                asset_info.asset_code,
                detail.order_code,
                order.bankcard_id,
                detail.user_bank_account,
                detail.product_id,
                user_id,
                ZhiwangAsset.MUTUAL_STATUS_MAP.get(detail.status),
                detail.annual_rate,
                detail.actual_annual_rate,
                detail.create_amount,
                detail.current_amount,
                detail.base_interest,
                detail.actual_interest,  # actual = expect
                detail.current_interest,
                detail.interest_start_date,
                detail.interest_end_date,
                detail.expected_payback_date,
                detail.created_at.naive)
            return

    raise WorkerTaskError(zhiwang_asset_fetching.tube)
Exemplo n.º 9
0
def initialize_zhiwang():
    if hasattr(request, 'oauth'):
        g.zhiwang_account = ZhiwangAccount.get_by_local(request.oauth.user.id_)
    else:
        g.zhiwang_account = None