예제 #1
0
def auth():
    """
    用户登录认证信息
    """
    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    form = UserAuthForm(request.form)
    condition = {
        'user_id': current_user.id,
        'type_auth': TYPE_AUTH_ACCOUNT,
    }
    user_auth_info = get_user_auth_row(**condition)

    if user_auth_info:
        form.id.data = user_auth_info.id
        form.type_auth.data = user_auth_info.type_auth
        form.auth_key.data = user_auth_info.auth_key
        form.status_verified.data = user_auth_info.status_verified
        form.create_time.data = user_auth_info.create_time
        form.update_time.data = user_auth_info.update_time
        if request.method == 'GET':
            form.auth_secret.data = ''
    if request.method == 'POST':
        if form.validate_on_submit():
            # 权限校验
            condition = {
                'id': form.id.data,
                'user_id': current_user.id,
                'type_auth': TYPE_AUTH_ACCOUNT,
            }
            op_right = get_user_auth_row(**condition)
            if not op_right:
                flash(u'修改失败', 'warning')
                return redirect(url_for('index'))

            current_time = datetime.utcnow()
            user_auth_data = {
                # 'type_auth': AUTH_TYPE_ACCOUNT,
                # 'auth_key': form.auth_key.data,
                # 'status_verified': form.status_verified.data,
                'update_time': current_time,
            }
            if form.auth_secret.data:
                user_auth_data['auth_secret'] = md5(form.auth_secret.data)
                result = edit_user_auth(form.id.data, user_auth_data)
                if result:
                    flash(u'修改成功', 'success')
                    return redirect(url_for('.auth'))
                else:
                    flash(u'信息不变', 'info')
            else:
                flash(u'信息不变', 'info')
        else:
            flash(u'修改失败', 'warning')
        # flash(form.errors, 'warning')  # 调试打开

    # flash(u'Hello, %s' % current_user.id, 'info')  # 测试打开
    return render_template('user/auth.html', title='auth', form=form, team_tree=team_tree)
예제 #2
0
def lists(page=1):
    """
    钱包列表
    """
    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)
    pagination = get_wallet_item_rows(page, PER_PAGE_FRONTEND,
                                      **{'user_id': current_user.id})
    return render_template('wallet/list.html',
                           title='wallet_list',
                           pagination=pagination,
                           team_tree=team_tree)
예제 #3
0
def profile():
    """
    用户基本信息
    """
    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    form = UserProfileForm(request.form)
    user_info = get_user_profile_row_by_id(current_user.id)

    if user_info:
        form.user_pid.data = user_info.user_pid
        form.nickname.data = user_info.nickname
        form.avatar_url.data = user_info.avatar_url
        form.create_time.data = user_info.create_time
        form.update_time.data = user_info.update_time
        if request.method == 'GET':
            form.area_id.data = user_info.area_id
            form.area_code.data = user_info.area_code
            form.phone.data = user_info.phone
            form.email.data = user_info.email
            form.birthday.data = user_info.birthday
            form.real_name.data = user_info.real_name
            form.id_card.data = user_info.id_card
    if request.method == 'POST':
        if form.validate_on_submit():
            current_time = datetime.utcnow()
            # 手机号码国际化
            area_id = form.area_id.data
            area_code = area_code_map.get(area_id, '86')
            user_data = {
                'email': form.email.data,
                'area_id': area_id,
                'area_code': area_code,
                'phone': form.phone.data,
                'birthday': form.birthday.data,
                'id_card': form.id_card.data,
                'update_time': current_time,
            }
            result = edit_user_profile(current_user.id, user_data)

            if result:
                flash(u'修改成功', 'success')
                return redirect(url_for('.profile'))
            else:
                flash(u'信息不变', 'info')
        else:
            flash(u'修改失败', 'warning')
        # flash(form.errors, 'warning')  # 调试打开

    # flash(u'Hello, %s' % current_user.id, 'info')  # 测试打开
    return render_template('user/profile.html', title='profile', form=form, team_tree=team_tree)
예제 #4
0
def add_get():
    """
    创建提现申请
    :return:
    """
    user_id = current_user.id

    # 判断基本信息和银行信息是否完整
    if not user_profile_is_complete(user_id):
        flash(u'请先完善基本信息', 'warning')
        return redirect(url_for('user.profile'))
    if not user_profile_is_complete(user_id):
        flash(u'请先完善银行信息', 'warning')
        return redirect(url_for('user.bank'))
        # 判断是否激活
    if current_user.status_active == int(STATUS_ACTIVE_NO):
        flash(u'请先激活当前账号', 'warning')
        return redirect(url_for('user.profile'))

    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    # 单次提现金额范围
    APPLY_GET_MIN_EACH = Decimal(get_conf('APPLY_GET_MIN_EACH'))  # 最小值
    APPLY_GET_MAX_EACH = Decimal(get_conf('APPLY_GET_MAX_EACH'))  # 最大值
    APPLY_GET_STEP = Decimal(get_conf('APPLY_GET_STEP'))  # 投资金额步长(基数)

    form = ApplyGetAddForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            type_pay = form.type_pay.data
            type_withdraw = form.type_withdraw.data
            money_apply = form.money_apply.data
            try:
                result = user_apply_get(user_id, type_pay, type_withdraw,
                                        money_apply)
                if result:
                    flash(u'申请成功', 'success')
                    return redirect(url_for('apply.lists_get'))
            except Exception as e:
                flash(u'申请失败, 原因:%s' % e.message, 'warning')
    return render_template('apply/get_add.html',
                           title='apply_get_add',
                           form=form,
                           APPLY_GET_MIN_EACH=str(APPLY_GET_MIN_EACH),
                           APPLY_GET_MAX_EACH=str(APPLY_GET_MAX_EACH),
                           APPLY_GET_STEP=str(APPLY_GET_STEP),
                           team_tree=team_tree)
예제 #5
0
def bank():
    """
    银行信息
    :return:
    """
    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    form = UserBankForm(request.form)
    bank_info = get_user_bank_row_by_id(current_user.id)

    if bank_info:
        form.status_verified.data = bank_info.status_verified
        form.create_time.data = bank_info.create_time
        form.update_time.data = bank_info.update_time
        if request.method == 'GET':
            form.account_name.data = bank_info.account_name
            form.bank_name.data = bank_info.bank_name
            form.bank_address.data = bank_info.bank_address
            form.bank_account.data = bank_info.bank_account
    if request.method == 'POST':
        if form.validate_on_submit():
            current_time = datetime.utcnow()
            bank_data = {
                'user_id': current_user.id,
                'account_name': form.account_name.data,
                'bank_name': form.bank_name.data,
                'bank_address': form.bank_address.data,
                'bank_account': form.bank_account.data,
                # 'status_verified': form.status_verified.data,
                'update_time': current_time,
            }
            if bank_info:
                result = edit_user_bank(current_user.id, bank_data)
            else:
                bank_data['create_time'] = current_time
                result = add_user_bank(bank_data)

            if result:
                flash(u'修改成功', 'success')
            else:
                flash(u'信息不变', 'info')
        else:
            flash(u'修改失败', 'warning')
        # flash(form.errors, 'warning')  # 调试打开

    # flash(u'Hello, %s' % current_user.id, 'info')  # 测试打开
    return render_template('user/bank.html', title='bank', form=form, team_tree=team_tree)
예제 #6
0
def add():
    """
    添加激活记录
    :return:
    """
    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    user_name = request.args.get('user_name', '')

    form = ActiveAddForm(request.form)

    # 初始化表单的值
    if user_name:
        form.user_name.data = user_name
    if not form.amount.data:
        form.amount.data = 1

    if request.method == 'POST':
        if form.validate_on_submit():
            # 赠送激活数量
            try:
                user_id = get_user_id_by_name(form.user_name.data)
                result = give_active(current_user.id, user_id,
                                     form.amount.data)
                if result:
                    flash(u'赠送激活数量操作成功', 'success')
                return redirect(url_for('.lists'))
            except Exception as e:
                flash(e.message or u'赠送激活数量操作失败', 'warning')
        # 闪现消息 success info warning danger
        # flash(form.errors, 'warning')  # 调试打开
    return render_template('active/add.html',
                           title='active_add',
                           form=form,
                           team_tree=team_tree)
예제 #7
0
def add_put():
    """
    创建投资申请
    :return:
    """
    user_id = current_user.id

    # 判断基本信息和银行信息是否完整
    if not user_profile_is_complete(user_id):
        flash(u'请先完善基本信息', 'warning')
        return redirect(url_for('user.profile'))
    if not user_profile_is_complete(user_id):
        flash(u'请先完善银行信息', 'warning')
        return redirect(url_for('user.bank'))
        # 判断是否激活
    if current_user.status_active == int(STATUS_ACTIVE_NO):
        flash(u'请先激活当前账号', 'warning')
        return redirect(url_for('user.profile'))

    # 获取团队成员三级树形结构
    team_tree = get_team_tree(current_user.id)

    # 单次投资金额范围
    APPLY_PUT_MIN_EACH = Decimal(get_conf('APPLY_PUT_MIN_EACH'))  # 最小值
    APPLY_PUT_MAX_EACH = Decimal(get_conf('APPLY_PUT_MAX_EACH'))  # 最大值
    APPLY_PUT_STEP = Decimal(get_conf('APPLY_PUT_STEP'))  # 投资金额步长(基数)

    form = ApplyPutAddForm(request.form)
    if request.method == 'POST':
        if form.validate_on_submit():
            current_time = datetime.utcnow()

            # 新增投资申请明细
            apply_put_info = {
                'user_id': user_id,
                'type_apply': TYPE_APPLY_USER,
                'type_pay': form.type_pay.data,
                'money_apply': form.money_apply.data,
                'status_apply': STATUS_APPLY_SUCCESS,
                'status_order': STATUS_ORDER_HANDING,
                'status_delete': STATUS_DEL_NO,
                'create_time': current_time,
                'update_time': current_time,
            }
            apply_put_id = add_apply_put(apply_put_info)

            # 消耗排单币
            scheduling_cost = form.money_apply.data / 100

            # 扣除排单币总表数量
            scheduling_info = get_scheduling_row_by_id(user_id)

            amount = scheduling_info.amount if scheduling_info else 0

            scheduling_data = {
                'amount': amount - scheduling_cost,
                'create_time': current_time,
                'update_time': current_time
            }
            edit_scheduling(user_id, scheduling_data)

            # 新增排单币明细
            scheduling_item_data = {
                'user_id': user_id,
                'type': user_id,
                'amount': scheduling_cost,
                'sc_id': user_id,
                'note': u'投资申请编号:%s' % apply_put_id,
                'status_audit': STATUS_AUDIT_SUCCESS,
                'audit_time': current_time,
                'create_time': current_time,
                'update_time': current_time
            }
            add_scheduling_item(scheduling_item_data)

            if apply_put_id:
                # 加入投资申请本息回收队列
                q = RabbitDelayQueue(
                    exchange=EXCHANGE_NAME,
                    queue_name='apply_put_interest_on_principal',
                    ttl=APPLY_PUT_INTEREST_ON_PRINCIPAL_TTL)
                msg = {
                    'user_id': user_id,
                    'apply_put_id': apply_put_id,
                    'apply_time': current_time.strftime('%Y-%m-%d %H:%M:%S')
                }
                q.put(msg)
                q.close_conn()
                flash(u'申请成功', 'success')
            else:
                flash(u'申请失败', 'warning')
            return redirect(url_for('apply.lists_put'))
    return render_template('apply/put_add.html',
                           title='apply_put_add',
                           form=form,
                           APPLY_PUT_MIN_EACH=str(APPLY_PUT_MIN_EACH),
                           APPLY_PUT_MAX_EACH=str(APPLY_PUT_MAX_EACH),
                           APPLY_PUT_STEP=str(APPLY_PUT_STEP),
                           team_tree=team_tree)