Exemplo n.º 1
0
def handing_fee():
    # 收取交易币种不是USD的手续费
    res = SqlData.search_settle_trans()
    for i in res:
        merchant_currency = i.get('merchant_currency')
        info_id = i.get('info_id')
        if merchant_currency == 'USD':
            SqlData.update_settle_handing(0, info_id)
        else:
            card_number = i.get('card_number')
            billing_amount = i.get('billing_amount')
            # 计算手续费
            hand_money = round(billing_amount * 0.02, 2)
            # 查询卡的归属客户
            user_id = SqlData.search_card_field('user_id', card_number)
            # 查询扣费前的账户余额
            before_balance = SqlData.search_user_field('balance', user_id)
            # 扣除手续费
            SqlData.update_balance(-hand_money, user_id)
            # 扣费后的余额
            balance = SqlData.search_user_field('balance', user_id)
            # 插入扣费记录
            n_time = xianzai_time()
            SqlData.insert_account_trans(n_time, '支出', '手续费', card_number,
                                         hand_money, before_balance, balance,
                                         user_id)

            # 更新扣费金额,表示该交易已扣费
            SqlData.update_settle_handing(hand_money, info_id)
Exemplo n.º 2
0
def card_delete():
    if request.method == "DELETE":

        # 判断是否是子账号用户
        vice_id = g.vice_id
        if vice_id:
            auth_dict = RedisTool.hash_get('svb_vice_auth', vice_id)
            if auth_dict is None:
                return jsonify({
                    'code': RET.SERVERERROR,
                    'msg': '抱歉您没有权限执行此操作!'
                })
            c_card = auth_dict.get('refund')
            if c_card == 'F':
                return jsonify({
                    'code': RET.SERVERERROR,
                    'msg': '抱歉您没有权限执行此操作!'
                })

        card_number = request.args.get('card_number')
        card_status = SqlData.search_one_card_status(card_number)
        if card_status:
            card_id = SqlData.search_card_field('card_id', card_number)
            card_detail = svb.card_detail(card_id)
            if not card_detail:
                return jsonify({'code': RET.SERVERERROR, 'msg': '网络繁忙,请稍后重试!'})
            available_balance = card_detail.get('data').get(
                'available_balance')
            res = svb.delete_card(card_id)
            if res:
                user_id = g.user_id
                before_balance = SqlData.search_user_field('balance', user_id)
                update_balance = float(available_balance / 100)
                SqlData.update_balance(update_balance, user_id)
                balance = SqlData.search_user_field("balance", user_id)
                SqlData.update_card_info_card_no('status', 'F', card_number)
                n_time = xianzai_time()
                SqlData.insert_account_trans(n_time, TRANS_TYPE.IN, "注销",
                                             card_number, update_balance,
                                             before_balance, balance, user_id)

                return jsonify({
                    "code": RET.OK,
                    "msg": '注销成功!退回金额:$' + str(update_balance)
                })

        else:
            return jsonify({'code': RET.SERVERERROR, 'msg': '该卡已注销!'})
Exemplo n.º 3
0
def add_account():
    if request.method == 'GET':
        return render_template('admin/add_account.html')
    if request.method == 'POST':
        results = {"code": RET.OK, "msg": MSG.OK}
        try:
            data = json.loads(request.form.get('data'))
            name = data.get('name').strip()
            account = data.get('account').strip()
            password = data.get('password').strip()
            phone_num = data.get('phone_num')
            create_price = float(data.get('create_price'))
            min_top = float(data.get('min_top'))
            max_top = float(30000)
            ed_name = SqlData.search_user_field_name('account', name)
            if ed_name:
                results['code'] = RET.SERVERERROR
                results['msg'] = '该用户名已存在!'
                return jsonify(results)
            if phone_num:
                ret = re.match(r"^1[35789]\d{9}$", phone_num)
                if not ret:
                    results['code'] = RET.SERVERERROR
                    results['msg'] = '请输入符合规范的电话号码!'
                    return jsonify(results)
            else:
                phone_num = ""
            SqlData.insert_account(account, password, phone_num, name,
                                   create_price, min_top, max_top)
            # 创建用户后插入充值数据
            pay_num = sum_code()
            t = xianzai_time()
            user_id = SqlData.search_user_field_name('id', name)
            SqlData.insert_top_up(pay_num, t, 0, 0, 0, user_id)
            SqlData.insert_account_trans(date=t,
                                         trans_type="充值",
                                         do_type="支出",
                                         card_no=0,
                                         do_money=0,
                                         before_balance=0,
                                         balance=0,
                                         user_id=user_id)
            return jsonify(results)
        except Exception as e:
            logging.error(e)
            results['code'] = RET.SERVERERROR
            results['msg'] = MSG.SERVERERROR
            return jsonify(results)
Exemplo n.º 4
0
def acc_pay():
    if request.method == 'POST':
        money = request.form.get('money')
        name = request.form.get('name')
        try:
            _money = float(money)
            f_money = round(_money, 2)
            if f_money < 0:
                return jsonify({'code': RET.SERVERERROR, 'msg': '请输入正数金额!'})
            balance = SqlData.search_user_field_name('balance', name)
            if f_money > balance:
                return jsonify({'code': RET.SERVERERROR, 'msg': '扣费余额不足!'})
            user_id = SqlData.search_user_field_name('id', name)
            SqlData.update_balance(-f_money, user_id)
            a_balance = SqlData.search_user_field("balance", user_id)
            # balance = before_balance - create_price
            n_time = xianzai_time()
            SqlData.insert_account_trans(n_time, '支出', '系统扣费', 0, f_money,
                                         balance, a_balance, user_id)
            return jsonify({'code': RET.OK, 'msg': MSG.OK})
        except Exception as e:
            logging.error(str(e))
            return jsonify({'code': RET.SERVERERROR, 'msg': '请输入正确的消费金额!'})
Exemplo n.º 5
0
def create_card():
    if request.method == 'GET':
        user_id = g.user_id
        min_top = SqlData.search_user_field('min_top', user_id)
        create_price = SqlData.search_user_field('create_price', user_id)
        context = dict()
        context['min_top'] = min_top
        context['create_price'] = create_price
        return render_template('user/create_card.html', **context)
    if request.method == 'POST':
        # 判断是否是子账号用户
        vice_id = g.vice_id
        if vice_id:
            auth_dict = RedisTool.hash_get('svb_vice_auth', vice_id)
            if auth_dict is None:
                return jsonify({
                    'code': RET.SERVERERROR,
                    'msg': '抱歉您没有权限执行此操作!'
                })
            c_card = auth_dict.get('c_card')
            if c_card == 'F':
                return jsonify({
                    'code': RET.SERVERERROR,
                    'msg': '抱歉您没有权限执行此操作!'
                })
        data = json.loads(request.form.get('data'))
        top_money = data.get('top_money')
        label = data.get('label')
        card_num = data.get('card_num')
        user_id = g.user_id
        user_data = SqlData.search_user_index(user_id)
        create_price = user_data.get('create_card')
        min_top = user_data.get('min_top')
        max_top = user_data.get('max_top')
        balance = user_data.get('balance')

        card_num = int(card_num)
        if card_num > 10:
            results = {"code": RET.SERVERERROR, "msg": "批量开卡数量不得超过10张!"}
            return jsonify(results)

        if not check_float(top_money):
            results = {"code": RET.SERVERERROR, "msg": "充值金额不能为小数!"}
            return jsonify(results)

        # 本次开卡需要的费用,计算余额是否充足
        money_all = (int(top_money) + create_price) * card_num
        if money_all > balance:
            results = {
                "code": RET.SERVERERROR,
                "msg": "本次消费金额:" + str(money_all) + ",账号余额不足!"
            }
            return jsonify(results)

        # 计算充值金额是否在允许范围
        # if not min_top <= int(top_money) <= max_top:
        if not min_top <= int(top_money):
            results = {"code": RET.SERVERERROR, "msg": "充值金额不在允许范围内!"}
            return jsonify(results)
        # 该处修改开卡
        try:
            data_list = []
            cents = int(top_money) * 100
            for i in range(card_num):
                data = svb.create_card(cents)
                if data:
                    # 开卡费用
                    n_time = xianzai_time()
                    card_number = data.get('card_number')
                    cvc = data.get('cvc')
                    expiry = data.get('expiry')
                    card_id = data.get('card_id')
                    last4 = data.get('last4')
                    valid_starting_on = data.get('valid_start_on')
                    valid_ending_on = data.get('valid_end_on')

                    # 插入卡信息
                    SqlData.insert_card(card_number, cvc, expiry, card_id,
                                        last4, valid_starting_on,
                                        valid_ending_on, label, 'T',
                                        int(top_money), user_id)

                    # 扣去开卡费用
                    before_balance = SqlData.search_user_field(
                        'balance', user_id)
                    create_price_do_money = float(
                        create_price) - float(create_price) * 2
                    SqlData.update_balance(create_price_do_money, user_id)
                    balance = SqlData.search_user_field("balance", user_id)
                    # balance = before_balance - create_price
                    SqlData.insert_account_trans(n_time, TRANS_TYPE.OUT,
                                                 DO_TYPE.CREATE_CARD,
                                                 card_number, create_price,
                                                 before_balance, balance,
                                                 user_id)

                    # 扣去充值费用
                    before_balance = SqlData.search_user_field(
                        'balance', user_id)
                    top_money = int(top_money)
                    top_money_do_money = top_money - top_money * 2
                    SqlData.update_balance(top_money_do_money, user_id)
                    balance = SqlData.search_user_field("balance", user_id)
                    n_time = xianzai_time()
                    SqlData.insert_account_trans(n_time, TRANS_TYPE.OUT,
                                                 DO_TYPE.TOP_UP, card_number,
                                                 top_money, before_balance,
                                                 balance, user_id)
                    data_list.append(card_num)
            return jsonify({
                "code":
                RET.OK,
                "msg":
                "成功开卡" + str(len(data_list)) + "张! 账户余额为: $" + str(balance)
            })

        except Exception as e:
            logging.error(str(e))
            return jsonify({
                "code": RET.SERVERERROR,
                "msg": "网络繁忙, 开卡失败, 请稍后再试"
            })
Exemplo n.º 6
0
def top_up():
    # 判断是否是子账号用户
    vice_id = g.vice_id
    if vice_id:
        auth_dict = RedisTool.hash_get('svb_vice_auth', vice_id)
        if auth_dict is None:
            return render_template('user/no_auth.html')
        c_card = auth_dict.get('top_up')
        if c_card == 'F':
            return render_template('user/no_auth.html')
    if request.method == 'GET':
        card_number = request.args.get('card_number')
        context = dict()
        context['card_number'] = card_number
        return render_template('user/card_top.html', **context)
    if request.method == 'POST':
        data = json.loads(request.form.get('data'))
        user_id = g.user_id
        card_number = request.args.get('card_number')
        top_money = data.get('top_money')
        user_data = SqlData.search_user_index(user_id)
        before_balance = user_data.get('balance')
        if not check_float(top_money):
            results = {"code": RET.SERVERERROR, "msg": "充值金额不能为小数!"}
            return jsonify(results)
        if int(top_money) > before_balance:
            results = {
                "code": RET.SERVERERROR,
                "msg": "本次消费金额:" + str(top_money) + ",账号余额不足!"
            }
            return jsonify(results)
        card_status = SqlData.search_one_card_status(card_number)
        if not card_status:
            return jsonify({'code': RET.SERVERERROR, 'msg': "该卡已注销,不支持此操作!"})
        card_id = SqlData.search_card_field('card_id', card_number)
        card_detail = svb.card_detail(card_id)
        if card_detail:
            available_balance = card_detail.get('data').get(
                'available_balance')
            now_balance = available_balance + int(top_money) * 100
            res = svb.update_card(card_id, now_balance)
            if res:
                top_money = int(top_money)
                top_money_do_money = top_money - top_money * 2
                SqlData.update_balance(top_money_do_money, user_id)
                n_time = xianzai_time()
                balance = SqlData.search_user_field('balance', user_id)
                SqlData.insert_account_trans(n_time, TRANS_TYPE.OUT,
                                             DO_TYPE.TOP_UP, card_number,
                                             top_money, before_balance,
                                             balance, user_id)
                return jsonify({
                    'code':
                    RET.OK,
                    'msg':
                    '充值成功!账户余额:$ ' + str(balance) + ",卡余额:$ " +
                    str(now_balance / 100)
                })
            return jsonify({'code': RET.SERVERERROR, 'msg': '网络繁忙,请稍后重试!'})
        else:
            return jsonify({'code': RET.SERVERERROR, 'msg': '网络繁忙,请稍后重试!'})
Exemplo n.º 7
0
def bento_refund():
    # 判断是否是子账号用户
    vice_id = g.vice_id
    if vice_id:
        auth_dict = RedisTool.hash_get('svb_vice_auth', vice_id)
        if auth_dict is None:
            return jsonify({'code': RET.SERVERERROR, 'msg': '抱歉您没有权限执行此操作!'})
        c_card = auth_dict.get('refund')
        if c_card == 'F':
            return jsonify({'code': RET.SERVERERROR, 'msg': '抱歉您没有权限执行此操作!'})

    # 参数获取
    data = request.form.get("data")
    card_number = request.form.get("card_number").strip()
    user_id = g.user_id

    # 金额的校验
    if "-" in str(data):
        return jsonify({"code": RET.SERVERERROR, 'msg': "请输入正确金额!"})
    if "." in str(data):
        if len(str(data).split(".")[1]) > 2:
            return jsonify({"code": RET.SERVERERROR, 'msg': "精度不大于两位小数!"})

    # 校验卡状态(注销无法更新)
    card_status = SqlData.search_one_card_status(card_number)
    if not card_status:
        return jsonify({'code': RET.SERVERERROR, 'msg': "该卡已注销,不支持此操作!"})

    # 查询卡余额,校验退款金额大小
    card_id = SqlData.search_card_field('card_id', card_number)
    card_detail = svb.card_detail(card_id)
    if not card_detail:
        return jsonify({"code": RET.SERVERERROR, 'msg': "网络繁忙,请稍后重试!"})
    available_balance = card_detail.get('data').get('available_balance')
    refund_money = float(data) * 100
    if refund_money >= available_balance:
        return jsonify({
            "code": RET.SERVERERROR,
            'msg': "卡余额不足!当前卡余额:$" + str(available_balance / 100)
        })

    # 更新卡余额
    update_money = int(available_balance - refund_money)
    res = svb.update_card(card_id, update_money)

    # 成功则更新账户余额
    if res:
        before_balance = SqlData.search_user_field('balance', user_id)
        SqlData.update_balance(float(data), user_id)
        balance = SqlData.search_user_field("balance", user_id)
        n_time = xianzai_time()
        SqlData.insert_account_trans(n_time, TRANS_TYPE.IN, "退款", card_number,
                                     float(data), before_balance, balance,
                                     user_id)

        return jsonify({
            "code": RET.OK,
            "msg": '退款成功!当前卡余额:$' + str(update_money / 100)
        })
    else:
        return jsonify({"code": RET.SERVERERROR, 'msg': "网络繁忙,请稍后重试!"})